今天读了oracle性能诊断艺术,发现游标的另一种写法
declare
l_name emp.last_name%type :='HARTSTEIN';
l_empno emp.EMPLOYEE_ID%type;
l_cursor integer;
l_retval integer;
begin
l_cursor:= dbms_sql.open_cursor;
dbms_sql.parse(l_cursor, 'select EMPLOYEE_ID from emp where last_name=:ename',1);
dbms_sql.define_column(l_cursor,1,l_empno);
dbms_sql.bind_variable(l_cursor,':ename',l_name);
l_retval:=dbms_sql.execute(l_cursor);
if dbms_sql.fetch_rows(l_cursor) >0
then
dbms_sql.column_value(l_cursor,1,l_empno);
end if;
dbms_sql.close_cursor(l_cursor);
dbms_output.put_line(l_empno);
l_name emp.last_name%type :='HARTSTEIN';
l_empno emp.EMPLOYEE_ID%type;
l_cursor integer;
l_retval integer;
begin
l_cursor:= dbms_sql.open_cursor;
dbms_sql.parse(l_cursor, 'select EMPLOYEE_ID from emp where last_name=:ename',1);
dbms_sql.define_column(l_cursor,1,l_empno);
dbms_sql.bind_variable(l_cursor,':ename',l_name);
l_retval:=dbms_sql.execute(l_cursor);
if dbms_sql.fetch_rows(l_cursor) >0
then
dbms_sql.column_value(l_cursor,1,l_empno);
end if;
dbms_sql.close_cursor(l_cursor);
dbms_output.put_line(l_empno);
end;
/
/
这种写法更能发现游标执行的内部过程。
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/7551038/viewspace-619439/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/7551038/viewspace-619439/