学习数据库的第六天

一、IF

1.

if 条件 then....;

end if;

2.

if 条件 then.....;

else.....

end if;

3.

if 条件 then.....;

elsif 条件 then....

else ....

end if;

三、while do..while

do {} while (i<5)

1.

while 条件

loop

...

end loop;

2.

loop

....

exit when i>5;

end loop;

四、for

for i in 1.....10

loop

..

end loop;

五、存储过程

语法基本结构

create [or replace]producedure 过程名(参数列表)

as

begin

......

end;

无参:

有参:

--传入一个员工编号,给该员工帐500 create or replace PROCEDURE raiseSalary(pid in number) as psal emp.sal%type; begin select sal into psal from emp where empno=pid; update emp set sal = sal +500 where empno=pid; DBMS_OUTPUT.put_line(psal || '-------' || psal+500); end;

六、存储函数

与存储过程最大的区别:必须有return

语法

create [or replace] function 函数名(参数列表)

rerurn 数据类型

as

....

begin

.....

end;

create or replace function getTotalSal(pid in number) return number as empSal emp.sal%type; empComm emp.comm%type; begin select sal ,comm into empSal,empComm from emp where empno=pid;

return empSal*12+ nvl(empComm,0);

end;

总结:存储过程/存储函数?

只有一个返回值适合使用,存储函数return

没有、多个返回值适合使用,存储过程 out out。。。

存储过程:传入员工编号,传入姓名、工作

存储函数:传入员工编号,传入姓名、工作

六、包、包头和包体的使用

使用

CREATE OR REPLACE PACKAGE BODY PACKAGE AS

procedure queryEmpList(dno in number,empList out empcursor) AS BEGIN open empList for SELECT * FROM emp where deptno=dno; END queryEmpList;

END PACKAGE;

验证

desc package

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值