我的Sql Server存储过程是
ALTER PROCEDURE myproc
@iii NVARCHAR(255)
AS
BEGIN
select * from dbo.users where (first_name = @iii OR @iii = '' );
END;
虽然
通过运行
exec myproc ''
获取所有记录
但是在oracle中
CREATE OR REPLACE PROCEDURE myproc (fname IN STRING, name1 OUT STRING) AS
BEGIN
SELECT "first_name" INTO name1 FROM "users" WHERE ( "first_name" = fname OR fname = '');
END;
但是通过''执行它参数未找到数据。
如何获取所有数据?
答案 0 :(得分:0)
您必须声明输出变量
declare
--declare the output variable
v_output varchar2(100);
begin
-- call it
myproc('King', v_output);
-- print it
dbms_output.put_line(v_output);
end;
你也可以声明一个异常,如果输出变量没有值结束那么它也会返回错误
例外:
CREATE OR REPLACE PROCEDURE myproc ( fname IN STRING
, name1 OUT STRING) AS
BEGIN
select First_name
into name1
from hr.employees x
where x.last_name = fname
and rownum = 1;
EXCEPTION
when others then
name1 := null;
END;