1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
| select * from scott.emp
--1、什么是存储过程? --预编译好的程序,简化应用程序的调用
--2、语法 (特殊的PL/SQL) create procedure proc_test as begin --sql语句 --exception end;
--例1 --无参的存储过程 create procedure proc_sel4 as myname varchar(10); deptname varchar(10); begin --联表查询 select ename,dname into myname,deptname from scott.emp,scott.dept where scott.emp.deptno = scott.dept.deptno and empno = 7369; dbms_output.put_line(myname||deptname); end;
--调用存储过程 begin proc_sel4; end;
select * from scott.emp; select * from scott.dept;
--带参数的存储过程 create procedure proc_test(参数1,参数2....) as begin --sql语句 end;
---加工资,manage岗位工资加?(参数1员工编号,参数2工资加多少)
create procedure proc_addsal1(myempno number,mysal number) as myjob varchar(10); begin select job into myjob from scott.emp where empno = myempno; if myjob = 'MANAGER' then update scott.emp set sal = sal+mysal where empno = myempno; dbms_output.put_line('恭喜!你加了'||mysal||'工资'); else dbms_output.put_line('sorry!没有加工资,赶紧往上爬!'); end if; end;
--调用存储过程 begin proc_addsal1(7698,1000); end;
select * from scott.emp
create procedure proc_addsal3(myempno number,mysal number,jobtest varchar) as myjob varchar(10); begin select job into jobtest from scott.emp where empno = myempno; if myjob = 'MANAGER' then update scott.emp set sal = sal+mysal where empno = myempno; dbms_output.put_line('恭喜!你加了'||mysal||'工资'); else dbms_output.put_line('sorry!没有加工资,赶紧往上爬!'); end if; end;
|