oracle存储过程和函数
SQL> CREATE OR REPLACE PROCEDURE HelloWorld2 (
2 p_user_name IN VARCHAR2,
3 p_out_val OUT VARCHAR2,
4 p_inout_val IN OUT VARCHAR2
5 ) AS
6 BEGIN
7 dbms_output.put_line('Hello ' || p_user_name || p_inout_val || '!');
8 p_out_val := 'A';
9 p_inout_val := 'B';
10 END HelloWorld2;
11 /
Procedure created.
SQL> DECLARE
2 p_outval VARCHAR2(10);
3 p_inoutval VARCHAR2(10) := '~Hi~';
4 BEGIN
5 HelloWorld2('Edward', p_outval, p_inoutval);
6
7 dbms_output.put_line('p_outval=' || p_outval);
8 dbms_output.put_line('p_inoutval=' || p_inoutval);
9 END;
10 /
Hello Edward~Hi~!
p_outval=A
p_inoutval=B
PL/SQL procedure successfully completed.
函数一般情况下是用来计算并返回一个计算结果而存储过程一般是用来完成特定的数据操作(比如修改、插入数据库表或执行某些DDL语句等等),
CREATE OR REPLACE FUNCTION FUN3(IN_NAME IN VARCHAR2)
RETURN VARCHAR2 IS
OUT_RETURN VARCHAR2(20);
OUT_RETURN1 VARCHAR2(20);
BEGIN
SELECT 'HELLO' ||' ' || IN_NAME INTO OUT_RETURN FROM DUAL ;
SELECT TO_CHAR(SYSDATE, 'YYYYMMDDHH24MI') INTO OUT_RETURN1 FROM DUAL;
RETURN OUT_RETURN || ' ' || OUT_RETURN1;
END;
我的异常网推荐解决方案:oracle存储过程,http://www.myexception.cn/oracle-develop/177537.html