--第一个存储过程,打印一个hello world
/*
调用存储过程:
1.exec sayhelloworld();
2.begin
sayhelloworld();
sayhelloworld();
end;
/
*/
create or replace procedure sayhelloworld
as
--说明部分
begin
dbms_output.put_line('Hello world');
end;
/
-------------------------------------------------------------------
--创建一个带参数的存储过程
--给指定的员工涨100块钱的工资,并且打印涨前和涨后的薪水
/*
如何调用:
begin
raisesalary(1);
raisesalary(2);
commit;
end;
/
*/
create or replace procedure raisesalary(eno in number)
as
--定义一个变量保存涨前的工资
psal emp.sal%type;
begin
--得到员工的涨前薪水
select sal into psal from emp where id = eno;
--给该员工涨一百元的工资
update emp set sal = sal + 100 where id=eno;
--需不需要commit?
--注意:一般不在存储过程或者存储函数中,commit和rollback。
--打印涨前和涨后的薪水
dbms_output.put_line('涨前:'||psal||' 涨后:'||(psal + 100));
end;
/
-----------------------------------------------------------
create or replace function queryempincome(eno in number)
return number
as
--定义变量保存员工的薪水和奖金
psal emp.sal%type;
pcomm emp.comm%type;
begin
--得到员工的月薪和奖金
select sal,comm into psal,pcomm from emp where id = eno;
--直接返回年薪
return psal * 12 + nvl(pcomm,0) ;
end;
oracle学习之存储过程
最新推荐文章于 2024-08-09 14:30:13 发布