SQL: Select a list of numbers from “nothing”

后端 未结 4 1279
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-02 01:24

What is a fast/readable way to SELECT a relation from \"nothing\" that contains a list of numbers. I want to define which numbers by setting a start and end value. I am usi

4条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-02 01:54

    A simple way to do this in PostgreSQL and SQLite is as follows:

    sqlite> select 1 union select 2 union select 3;
    1
    2
    3
    

    It should work in most RDBMS systems, but IIRC in Oracle you would have to use:

    select 1 from dual union select 2 from dual union select 3 from dual;
    

    But I don't have an Oracle DB to test it on.

提交回复
热议问题