如何在oracle函数中列出表

如何在oracle函数中列出表,oracle,oracle11g,Oracle,Oracle11g,在postresql函数中,我们可以在(SELECT…)中按i列出表 在Oracle中,不必显式声明游标循环变量。它隐式地将是表名%rowtype数据类型 以下是一个例子: For i in (select col_1, .., col_n from your_table) loop -- do something end loop; 演示: create table test_1(col1 varchar2(11)); Table created SQL>

在postresql函数中,我们可以在(SELECT…)中按i列出表


在Oracle中,不必显式声明游标循环变量。它隐式地将是
表名%rowtype
数据类型

以下是一个例子:

For i in (select col_1, .., col_n
            from your_table)
loop
  -- do something
end loop;
演示:

create table test_1(col1 varchar2(11));

Table created

SQL> insert into test_1(col1) values('data_1');

1 row inserted

SQL> insert into test_1(col1) values('data_2');

1 row inserted

SQL> insert into test_1(col1) values('data_3');

1 row inserted

SQL> commit;

Commit complete

SQL> set serveroutput on;

SQL>begin
  2    for i in (select col1 from test_1)
  3    loop
  4      dbms_output.put_line(i.col1);
  5    end loop;
  6  end;
  7  /

data_1
data_2
data_3

PL/SQL procedure successfully completed

我已经补充了一些细节
For i in (select col_1, .., col_n
            from your_table)
loop
  -- do something
end loop;
create table test_1(col1 varchar2(11));

Table created

SQL> insert into test_1(col1) values('data_1');

1 row inserted

SQL> insert into test_1(col1) values('data_2');

1 row inserted

SQL> insert into test_1(col1) values('data_3');

1 row inserted

SQL> commit;

Commit complete

SQL> set serveroutput on;

SQL>begin
  2    for i in (select col1 from test_1)
  3    loop
  4      dbms_output.put_line(i.col1);
  5    end loop;
  6  end;
  7  /

data_1
data_2
data_3

PL/SQL procedure successfully completed