SELECT from nothing?

前端 未结 14 2270
难免孤独
难免孤独 2020-12-24 04:03

Is it possible to have a statement like

SELECT \"Hello world\"
WHERE 1 = 1

in SQL?

The main thing I want to know, is can I SELECT f

14条回答
  •  醉酒成梦
    2020-12-24 04:50

    Here is the most complete list of database support of dual from https://blog.jooq.org/tag/dual-table/:

    In many other RDBMS, there is no need for dummy tables, as you can issue statements like these:

    SELECT 1;
    SELECT 1 + 1;
    SELECT SQRT(2);
    

    These are the RDBMS, where the above is generally possible:

    • H2
    • MySQL
    • Ingres
    • Postgres
    • SQLite
    • SQL Server
    • Sybase ASE

    In other RDBMS, dummy tables are required, like in Oracle. Hence, you’ll need to write things like these:

    SELECT 1       FROM DUAL;
    SELECT 1 + 1   FROM DUAL;
    SELECT SQRT(2) FROM DUAL;
    

    These are the RDBMS and their respective dummy tables:

    • DB2: SYSIBM.DUAL
    • Derby: SYSIBM.SYSDUMMY1
    • H2: Optionally supports DUAL
    • HSQLDB: INFORMATION_SCHEMA.SYSTEM_USERS
    • MySQL: Optionally supports DUAL
    • Oracle: DUAL
    • Sybase SQL Anywhere: SYS.DUMMY

    Ingres has no DUAL, but would actually need it as in Ingres you cannot have a WHERE, GROUP BY or HAVING clause without a FROM clause.

提交回复
热议问题