for example:SQL> declare
2 v_out varchar2(100);
3 begin
4 if 1=1 then
5 declare
6 cursor c_1 is select 'a' col from dual;
7 begin
8 open c_1;
9 fetch c_1 into v_out;
10 dbms_output.put_line(v_out);
11 end;
12 end if;
13 end;
14 /
aPL/SQL 过程已成功完成。SQL>
2 v_out varchar2(100);
3 begin
4 if 1=1 then
5 declare
6 cursor c_1 is select 'a' col from dual;
7 begin
8 open c_1;
9 fetch c_1 into v_out;
10 dbms_output.put_line(v_out);
11 end;
12 end if;
13 end;
14 /
aPL/SQL 过程已成功完成。SQL>
2 v_out varchar2(100);
3 begin
4 if 1>2 then
5 declare
6 cursor c_1 is select 'a' col from dual;
7 begin
8 open c_1;
9 fetch c_1 into v_out;
10 dbms_output.put_line(v_out);
11 end;
12 else
13 declare
14 cursor c_2 is select 'b' col from dual;
15 begin
16 open c_2;
17 fetch c_2 into v_out;
18 dbms_output.put_line(v_out);
19 end;
20 end if;
21 end;
22 /
bPL/SQL 过程已成功完成。SQL>
使用动态游标ref cursorfor example:SQL> declare
2 type c is ref cursor;
3 v_out varchar2(100);
4 c_1 c;
5 begin
6 if 1>2 then
7 open c_1 for 'select ''a'' col from dual';
8 else
9 open c_1 for 'select ''b'' col from dual';
10 end if;
11 fetch c_1 into v_out;
12 dbms_output.put_line(v_out);
13 end;
14 /
bPL/SQL 过程已成功完成。SQL>