[英]Issues while converting sql server stored procedure to oracle stored procedure
My Sql Server Stored Procedure Is 我的Sql Server存储过程是
ALTER PROCEDURE myproc
@iii NVARCHAR(255)
AS
BEGIN
select * from dbo.users where (first_name = @iii OR @iii = '' );
END;
While 而
By Running it 通过运行它
exec myproc ''
Get All Records 获取所有记录
But in 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;
But by executing it with '' Parameter Not Found Data. 但是通过使用''未找到参数数据来执行它。
How do I get all the data? 如何获得所有数据?
You have to declare the output variable, 您必须声明输出变量,
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;
You can as well declare an exception, cause if the output variable end without value then it will return an error too 您也可以声明一个异常,导致如果输出变量的末尾没有值,那么它也会返回一个错误。
Exception: 例外:
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;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.