当然可以实现, 而且方法有多种!
具体如下:
SQL> declare
2 rec emp%rowtype;
3 begin
4 execute immediate 'select * from emp where deptno = 20 and rownum = 1' into rec;
5 dbms_output.put_line(rec.ename);
6
7 exception
8 when no_data_found then
9 dbms_output.put_line('No data found!');
10 end;
11 /
SMITH
PL/SQL procedure successfully completed
SQL>
如果你非要用动态游标就用如下的方法!
SQL> declare
2 cur sys_refcursor;
3 rec emp%rowtype;
4 begin
5 open cur for 'select * from emp where deptno = 20';
6 fetch cur into rec;
7 if cur%found then
8 dbms_output.put_line(rec.ename);
9 else
10 dbms_output.put_line('No data found!');
11 end if;
12
13 close cur;
14 end;
15 /
SMITH
PL/SQL procedure successfully completed
[本帖最后由 bell6248 于 2011-4-28 17:06 编辑]