可以使用以下内容创建包含一列和一行的表:
select 'create' as col from dual;
这可用于构建表连接:
with
a as (select 'create' as ac from dual),
b as (select 'delete' as bc from dual)
select * from a left outer join b on (ac = bc);
现在我想要两行。我是这样做的:
select 'create' as col from dual
union
select 'delete' as col from dual;
但这有更紧凑的符号吗?我试过了
select ('create', 'delete') as col from dual;
但它不起作用。
答案 0 :(得分:11)
例如,您可以使用集合类型和TABLE运算符(适用于Oracle 10g):
SQL> SELECT column_value FROM TABLE(SYS.ODCIVARCHAR2LIST('abc', 'def', 'ghi'));
COLUMN_VALUE
--------------------------------------------------------------------------------
abc
def
ghi
答案 1 :(得分:2)
生成行的几种方法。您可以对具有更多行的表使用rownum:
SELECT roWnum AS a
FROM user_objects
WHERE rownum <= 3
您可以使用分层查询:
SELECT level AS a
FROM dual
CONNECT BY LEVEL <= 3
编辑:将int序列更改为alpha序列:
SELECT CHR( ASCII('a') + level - 1 )
FROM dual
CONNECT BY LEVEL <= 3