oracle存储过程中的select语句
导读:在oracle数据库存储过程中如果用了select语句,要么使用"select into 变量"语句要么使用游标,oracle不支持单独的select语句。先看下这个存储过程:create or replace procedure pro_test is begin select * from t_test; end pro_test;这个存储过程正确吗?昨天因为这个,耽误了好久(在一个存储过程中用了select语句,但既没有用游标也没有用into).在存储过程(oracle数据库)中如果用了select语句,要么使用"select into 变量"语句要么使用游标,oracle不支持单独的select语句(如表述有误请指出).select into 比较简单,但是如果返回的是一个结果集就无法满足要求了.游标分Cursor型游标和SYS_REFCURSOR型游标两种Cursor型游标--不能用于参数传递create or replace procedure pro_test() iscusor_1 Cursor is select 字段名 from 表名 where 条件;(或者select class_name into cursor_2 from class where ...;cursor的另一种用法,需要写在begin和end之间)beginselect class_name into cursor_2 from class where ...;可以使用for xxx in cursorloop....end loop; --对Cursor进行遍历end pro_test;SYS_REFCURSOR型游标create or replace procedure pro_test(rsCursor out SYS_REFCURSOR) iscursor SYS_REFCURSOR;name varhcar(20);beginopen cursor forselect name from student where ...; --使用open来打开进行赋值--遍历loopfetch cursor into name --fetch into来打开遍历的每条数据exit when cursor%NOTFOUND; --未找到记录信息dbms_output.putline(xxxx);end loop;rsCursor := cursor;end pro_test;
?