文章标题
来源:互联网 发布:网络交友的利 编辑:程序博客网 时间:2024/06/05 18:58
一、PL/SQL编程基础
1、pl/sql的组成:声明块、执行块、异常处理块
2、编制代码实现1+2+…+100的计算
declare
n int;
result int;
begin
n:=0;
result:=0;
while n<=100 loop
result:=result+n;
n:=n+1;
end loop;
dbms_output.put_line(‘结果是’||result);
end;
二、存储过程编程
1、存储过程的概念
procedure 存储过程,存储在数据库中的不带返回值的命名PL/sql程序块,(可以反复使用复杂操作,并提高执行效率)
2、存储过程的语法
create or replace procedure procedureName(parm parmType)
as
local varible defination
begin
procedure body;
end;
3、编写求u1+2+…+100的结果并显示的存储过程
create or replace procedure sp_calcSum
as
begin
…
end;
4、编写求1+2+…+n的带参数的存储过程
create or replace procedure sp_calcSum(pEndNumber int)
as
begin
…
end;
三、函数编程
1、函数的概念
function函数,存储在数据库中的带返回值的命名pl/sql程序块
2、函数的语法
create or replace function functionName(parm parmType) return resultType
as
local varible defination
begin
function body
return result;
end;
3、编写求1+2+…+100的函数
create or replace function f_calcSum() return int
as
begin
…
return result;
end
4、编写求1+2+…+n的函数
create or replace function f_calcSum(pEndNumber int) return int
as
begin
….
return result;
end;
四、存储过程与函数的应用
1、编写将指定部门号的所有员工薪水增加指定值的存储过程,并调用此存储过程将30号部门的薪水增加1000
编写存储过程 sp_AlterSalByDeptno(pSalDelta,pDeptno)
调用存储过程将30号部门的薪水增加1000元 execute sp_AlterSalByDeptno(1000,30)
与使用update语句进行对比
2、编写求指定部门号的所有员工平均薪水的函数,并调用此函数计算30号部门的平均薪水
编写函数 f_GetAvgSalByDeptno(pDeptno)
调用函数求出30号部门的平均薪水并显示tempSal:=f_GetAvgSalByDeptno(30)
与使用select语句进行对比
- 文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题 文章标题 文章标题 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 文章标题
- 安卓导图
- xhprof PHP的性能监控神器 mac 环境
- 贪吃蛇(C++)
- angularJs-指令
- 创建数据库心得
- 文章标题
- 实现判断文件是否被占用与解除文件占用
- 一般app测试的最佳方法
- List中Iterator异常
- Syntax error, insert "VariableDeclarators" to complete LocalVariableDeclaration
- mysql中计算两个日期的时间差函数TIMESTAMPDIFF
- 58到家数据库30条军规解读
- 增加自己的so到debian
- 实际问题的算法抽象——动态规划中的01背包问题