码迷,mamicode.com
首页 > 数据库 > 详细

『ORACLE』 PLSQL创建存储过程(11g)

时间:2017-05-15 23:47:05      阅读:299      评论:0      收藏:0      [点我收藏+]

标签:out   get   success   ons   ted   tput   res   char   tno   

不带参数的存储过程

SQL> create or replace procedure get_time is
2 begin
3 dbms_output.put_line(sysdate);
4 end;
5 /

Procedure created.

SQL> exec get_time;

15-MAY-17

PL/SQL procedure successfully completed.

带in参数的存储过程

SQL> create or replace procedure add_dept
2 (v_dept_id in number, v_dept_name in varchar2) is
3 begin
4 insert into dept(deptno, dname)
5 values (v_dept_id,v_dept_name);
6 dbms_output.put_line(‘ inserted ‘ || SQL%ROWCOUNT || ‘ row ‘);
7 end;
8 /

Procedure created.

SQL> var s1 number
SQL> var s2 varchar2
SQL> exec :s1 :=60

PL/SQL procedure successfully completed.

SQL> exec :s2 :=‘sss‘

PL/SQL procedure successfully completed.

SQL> exec add_dept(:s1,:s2);
inserted 1 row

PL/SQL procedure successfully completed.

SQL> print s1 s2;

S1
----------
60


S2
--------------------------------
sss

SQL> select deptno, dname from dept;

DEPTNO DNAME
---------- --------------
10 ACCOUNTING
20 RESEARCH
30 SALES
40 OPERATIONS
50 sam
60 sss

带in和out参数的存储过程

SQL> create or replace procedure compute
2 (num1 in out number,num2 in out number)
3 is
4 v1 number;
5 v2 number;
6 begin
7 v1 := num1/num2;
8 v2 := mod(num1,num2);
9 num1 := v1;
10 num2 := v2;
11 end;
12 /

Procedure created.

 

『ORACLE』 PLSQL创建存储过程(11g)

标签:out   get   success   ons   ted   tput   res   char   tno   

原文地址:http://www.cnblogs.com/KT-melvin/p/6858789.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!