Is there a generic workaround to express a derived column list in Oracle (and MySQL)?

后端 未结 3 1414
时光说笑
时光说笑 2021-02-19 00:20

Many SQL databases support what the SQL standard calls a . Such databases include at least CUBRID, Derby, Firebird, HSQLDB, Postgres, SQL

3条回答
  •  谎友^
    谎友^ (楼主)
    2021-02-19 00:42

    As suggested by user tbone here, common table expressions are a good solution to my problem, at least for Oracle. For completeness, here is my example query written using CTEs in Oracle

    -- Rename a  to u(b) with Oracle
    with u(b) as (select 1 from dual) 
    select u.b from u
    
    -- Rename a  to u(b) with H2, which only knows recursive CTEs
    -- Thanks to a comment by user a_horse_with_no_name
    with recursive u(b) as (
      select 1
      union all
      select null where false
    )
    select u.b from u
    

提交回复
热议问题