如何在TYPE中使用(select * from table_name)而不是(列表)?

时间:2017-11-02 14:36:11

标签: sql oracle plsql

create type number_table is table of number;

FOR r IN (SELECT COLUMN_VALUE AS site
               FROM TABLE (number_table (55578622,
                                         70422825,
                                         71659843,
                                         77226904,
                                         78231463,
                                         80292748,
                                         81090361,
                                         81519938,
                                         81914339,
                                         82318250,
                                         85413629,
                                         85869431,
                                         86549326,
                                         86563882)

我如何使用(select * from table_name)而不是(列表)??

2 个答案:

答案 0 :(得分:1)

使用list时会出现什么问题。

替代方案可能是:

  

我如何使用(select * from table_name)而不是(列表)??

SELECT CURSOR (SELECT COLUMN_VALUE AS site
                 FROM TABLE (number_table (55578622,
                                      70422825,
                                      71659843,
                                      77226904,
                                      78231463,
                                      80292748,
                                      81090361,
                                      81519938,
                                      81914339,
                                      82318250,
                                      85413629,
                                      85869431,
                                      86549326,
                                      86563882))) col
  FROM DUAL  ;                                

答案 1 :(得分:0)

使用Implicit游标(see more)这是非常自动的:这样怎么样?

--- say table_name as 3 cols: c1, c2, c3
FOR r IN (SELECT * FROM table_name) 
LOOP
  -- do something with r
  dbms_output.put_line('c1 is:'||r.c1);
  dbms_output.put_line('c2 is:'||r.c2)
  dbms_output.put_line('c3 is:'||r.c3)

END LOOP;

希望有所帮助