Loading

oracle 调用存储过程和方法

1,oracle调用存储过程

/*例1*/
CREATE OR REPLACE PROCEDURE test1 
IS 
BEGIN 
 NULL; 
END; 

begin
test1();
end;


/*例2*/
CREATE OR REPLACE PROCEDURE test2
( p1 IN nvarchar2 )
as 
BEGIN 
 dbms_output.put_line(p1);
END; 




declare
msg NVARCHAR2(2000);
begin
test2(p1 => '肖建');
end;




/*例3*/
CREATE OR REPLACE PROCEDURE test3
(
       p1 IN nvarchar2 , 
       p2 out nvarchar2 
)
IS 
BEGIN 
 p2 := p1;
END; 

declare
msg NVARCHAR2(2000);
begin
test3(p1 => 'xxx',p2 =>msg);
dbms_output.put_line(msg);
end;

2,oracle调用方法

create or replace function fun01
(
    inParam in nvarchar2,
    outParam out nvarchar2,
   inAndOutParam in out nvarchar2
)
return nvarchar2 as f_result nvarchar2(200);     
begin
    outParam := inparam;
    inAndOutParam := 'Hello World'; 
    f_result := outParam || inAndOutParam;
    return f_result; 
end;



declare
msg1 NVARCHAR2(2000);
msg2 NVARCHAR2(2000);
msg3 NVARCHAR2(2000);

begin
msg1 := '';
msg2 := '';
msg3 := fun01('5',msg1,msg2);
end;



CREATE OR REPLACE FUNCTION fun02 
(
       num1 IN NUMBER, 
       num2 IN NUMBER
)  
RETURN NUMBER  
AS  
    num3 number;  
    num4 number;  
    num5 number;  
BEGIN  
    num3 := num1 + num2;  
    num4 := num1 * num2;  
    num5 := num3 * num4;  
    RETURN num5;  
END;  

 

posted @ 2013-06-09 15:55  Sam Xiao  阅读(1190)  评论(0编辑  收藏  举报