SQL Query to return N rows from dual

前端 未结 10 1841
盖世英雄少女心
盖世英雄少女心 2021-02-13 10:31

I want to write a SQL query which accepts a bind variable (say :NUM) and its output consists of one column & :NUM number of rows, each row having its row number. i.e. if we

10条回答
  •  再見小時候
    2021-02-13 11:17

    I'm marking this community wiki since it doesn't actually answer your requirement for no tables, but one of the first things we do when installing a database is to create a set of tables for this sort of purpose.

    • A table containing a large number of integers (e.g., -99999 through 99999).
    • A table containing every date from 10 years in the past to 10 years in the future (which is continuously added to each month and trimmed occasionally).
    • A table containing each hour of the day.

    By doing this, we greatly reduce the complexity, and increase the speed, of a large number of our queries at the cost of (minimal and cheap) disk space.

    You should give some serious thought to that. Aside from maintaining the date table, there's not a lot of upkeep needed.

提交回复
热议问题