as begin Declare var_sql varchar2(8000); --存放构造游标的sql语句 type mycursor is ref cursor; --定义游标类型 mycur mycursor; --定义动态游标 有这么写法的吗?我真的怀疑你是在逗我们。不过还是指出一下吧。 1.变量定义要在as之后。并且不要用declare. 2.begin要在变量定义之后写。
楼上正解~ 定义存储过程不需要 declare 关键字~ 只需要: create or replace procedure name as .....--定义 begin ... --内容 exception ... --异常 end;只有在写test script时,才需要declare关键字. declare ... --定义 begin ... --内容 exception ... --异常 end;
给你个例子~ 我测试通过的.create or replace procedure ex_dsql_cursorvariable(colName varchar2, colValue varchar2) is --表名,列名等object schema不确定时,不能使用cursor; --必须使用ref cursor; (即cursor variable) type CurTypeTerm is ref cursor; curTerm CurTypeTerm; sqlSelect varchar(100); recTerm term%rowtype; begin --千万不可在 :colValue 前后加%, 参照本例中在using时加%. sqlSelect:='select * from term where '||colName||' like :colValue '; open curTerm for sqlSelect using '%'||colValue||'%';
loop fetch curTerm into recTerm; exit when curTerm%notfound; dbms_output.put_line('Result '||curTerm%rowcount||':'); dbms_output.put_line(' '||recTerm.eng_name); dbms_output.put_line(' '||recTerm.eng_abbr_name); dbms_output.put_line(' '||recTerm.chn_name); end loop;
close curTerm; exception when others then dbms_output.put_line(sqlerrm); raise; end;
CREATE PROCEDURE RP_TEST( itable1 varchar, itable2 varchar, ReturnValue out number ) IS var_sql varchar2(8000); BEGIN DECLARE CURSOR C IS SELECT * FROM ...; BEGIN OPEN C; LOOP ............ END; 不知道这种类型的写法是不是你需要的?
begin
Declare var_sql varchar2(8000); --存放构造游标的sql语句
type mycursor is ref cursor; --定义游标类型
mycur mycursor; --定义动态游标
有这么写法的吗?我真的怀疑你是在逗我们。不过还是指出一下吧。
1.变量定义要在as之后。并且不要用declare.
2.begin要在变量定义之后写。
定义存储过程不需要 declare 关键字~
只需要:
create or replace procedure name as
.....--定义
begin
... --内容
exception
... --异常
end;只有在写test script时,才需要declare关键字.
declare
... --定义
begin
... --内容
exception
... --异常
end;
--表名,列名等object schema不确定时,不能使用cursor;
--必须使用ref cursor; (即cursor variable)
type CurTypeTerm is ref cursor;
curTerm CurTypeTerm;
sqlSelect varchar(100);
recTerm term%rowtype;
begin
--千万不可在 :colValue 前后加%, 参照本例中在using时加%.
sqlSelect:='select * from term where '||colName||' like :colValue ';
open curTerm for sqlSelect using '%'||colValue||'%';
loop
fetch curTerm into recTerm;
exit when curTerm%notfound;
dbms_output.put_line('Result '||curTerm%rowcount||':');
dbms_output.put_line(' '||recTerm.eng_name);
dbms_output.put_line(' '||recTerm.eng_abbr_name);
dbms_output.put_line(' '||recTerm.chn_name);
end loop;
close curTerm;
exception
when others then
dbms_output.put_line(sqlerrm);
raise;
end;
itable1 varchar,
itable2 varchar,
ReturnValue out number
)
IS
var_sql varchar2(8000);
BEGIN
DECLARE
CURSOR C IS SELECT * FROM ...; BEGIN
OPEN C;
LOOP
............
END;
不知道这种类型的写法是不是你需要的?