7

可以使用以下命令创建具有一列一行的表:

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;

但它不起作用。

4

2 回答 2

13

您可以使用集合类型和 TABLE 运算符,例如(适用于 Oracle 10g):

SQL> SELECT column_value FROM TABLE(SYS.ODCIVARCHAR2LIST('abc', 'def', 'ghi'));

COLUMN_VALUE
--------------------------------------------------------------------------------
abc
def
ghi
于 2012-07-13T12:37:31.380 回答
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
于 2012-07-13T11:40:08.437 回答