在模式下显示程序使用示例
================================================== ===
CREATE OR REPLACE PROCEDURE REVNUM (NUM NUMBER)
IS
REV INTEGER;
NUM1 NUMBER;
BEGIN
NUM1:=NUM;
REV:=0;
WHILE NUM1>0
LOOP
REV:=REV * 10 + MOD(NUM1,10);
NUM1:=TRUNC(NUM1/10);
END LOOP;
DBMS_OUTPUT.PUT_LINE(REV);
END REVNUM;
示例程序,用于显示程序的立即使用以及具有默认参数的程序。
================================================== ===
CREATE OR REPLACE PROCEDURE delete_rows
(
table_name IN VARCHAR2,
condition IN VARCHAR2 DEFAULT NULL
)
AS
where_clause VARCHAR2(100) := ' WHERE ' || condition;
BEGIN
IF condition IS NULL THEN where_clause := NULL;
END IF;
--EXECUTE IMMEDIATE is used to dynamically execute any SQL statment at run time.
EXECUTE IMMEDIATE 'DELETE FROM ' || table_name || where_clause;
END;
无参数的SAPMLE程序
======================================
create or replace procedure display
(
eno in emp.empno%type,
name out emp.ename%type,
job out emp.job%type,
salary out emp.sal%type,
location out dept.loc%type
)
is
begin
--the values are selected into the out paramater.
select ename,job,sal,loc into name,job,salary,location from emp e,dept d
where e.deptno=d.deptno AND empno=eno;
end;
注意:----如果过程包含任何OUT或IN OUT参数,则无法从SQL提示符下执行该过程,而必须在匿名块中使用来调用它。
执行上述过程。
declare
name emp.ename%type;
job emp.job%type;
salary emp.sal%type;
location dept.loc%type;
begin
--only the frist parameter accepts the value and the rest 4 returns after processing.
display(7839,name,job,salary,location);
dbms_output.put_line(name||' '||job||' '||salary||' '||location);
end;
还要检查
PL / SQL程序-3From: https://bytes.com/topic/oracle/insights/745603-pl-sql-procedures-2-a