2017-10-09 226 views
0

存儲過程我的SQL Server是問題而將SQL Server存儲過程,Oracle存儲過程

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; 

但通過''Parameter Not Found Data執行它。

如何獲取所有數據?

回答

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;