




全文预览已结束
下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
替换已存在的过程名创建存储过程create (or replace) procedure my_pl isbegin/执行部分/end;/ 带参SQL create procedure sp_test2(spname varchar2,newclassid number)is 2 begin 3 update student set classid=newclassid where studentname=spname; 4 end; 5 /show error查看错误调用过程1、 exec 过程名(参数值1,)2、 call过程名(参数值1,)命名规范:变量:v_变量名;常量:c_常量名;游标:名字_cursor;例外:e_名字;/块结构set serveroutput on(默认为off)declared -定义部分(可选)begin-执行部分(必须)exception-例外处理end;-结束/ 例:begindbms_output.put_line(hello); end;/输出结果:hello当.put_line换成.put是不能输出!?变量命名规则字母、数字、特殊符号 字母开头,不区分大小写;最大30个字符不能有空格例:set serveroutput on;declarev_student varchar2(20);beginselect studentname into v_student from student where xh=&xh;dbms_output.put_line(姓名:|v_student); exception when no_data_found then dbms_output.put_line(查无此人);异常处理end;/ 2012/2/211、函数的创建;create function sp_fun1(spname varchar2)returnnumber is spage number(3);begin select age+1 into spage from student where studentname=spname; return spage;end;2、调用函数 var 变量名 类型;exec 函数名(参数) into:变量名;创建包- 创建包名create package sp_pa is-声明过程procedure update_age(name varchar2,newage number);-声明函数function fun_age(name varchar2) return number;end;创建包体2012/2/22使用标量declarec_tax_rate number(3,2):=0.03;v_ename varchar2(5);v_sal number(7,2);v_tax_sal number(7,2);begin select ename ,sal into v_ename,v_sal from emp where empno=&no; v_tax_sal:=v_sal*c_tax_rate; dbms_output.put_line(姓名:|v_ename|工资:|v_sal|税款:|v_tax_sal);end;表名.列名%type 会引用原表属性解决缓冲区小的问题,防止溢出定义记录类型记录多个变量declaretype emp_record_type is record(name emp.ename%type,salary emp.sal%type,title emp.job%type);sp_record emp_record_type;beginselect ename,sal,job into sp_record from emp where empno=7788;dbms_output.put_line(员工:|sp_|工资|sp_record.salary);end;游标declare -定义游标类型为 sp_emp_cursortype sp_emp_cursor is ref cursor;test_cursor(游标变量) sp_emp_cursor; v_ename emp.ename%type;v_sal emp.sal%type; begin open test_cursor for select ename,sal from emp where deptno=&no; loop fetch test_cursor into v_ename,v_sal;(循环) exit when test_cursor%notfound; dbms_output.put_line(员工|v_ename|工资|v_sal); end loop; close test_cursor; (关闭游标)end; 2012/2/23if语句create or replace procedure pro_if(proName varchar2) isv_sal emp.sal%type;beginselect sal into v_sal from emp where ename=proName;if v_sal2000 thenupdate emp set sal=sal+sal*0.1 where ename=proName;end if;end;if-else语句if v_comm0 thenupdate emp set comm=comm+100 where ename=proName;elseupdate emp set comm=200 where ename=proName;end if;if-elsif-else 注:plsql为elsif ! ! !select job into v_job from emp where empno=proNo; if v_job=presidene then update emp set sal=sal+1000 where empno=proNo; elsif v_job=manager then update emp set sal=sal+500 where empno=proNo; else update emp set sal=sal+200 where empno=proNo; end if;loop 循环create or replace procedure pro_loop(proName varchar2) isv_userid number:=5;begin loop insert into user1 values(v_userid,proName); exit when v_userid=7; v_userid:=v_userid+1; end loop
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 三级数据库考试知识网络试题及答案
- 学校扶贫部门管理制度
- 公路工程多媒体展示技术试题及答案
- 公司疫情门卫管理制度
- 库房存储安全管理制度
- 安全生产瓦斯管理制度
- 安全监测设施管理制度
- 工厂配件领用管理制度
- 公路交通组织设计试题及答案
- 前台工作安全管理制度
- 个人信用报告异议申请表
- 统计学学习指导书(完整版)
- 初中数学 北师大版 七年级下册 变量之间的关系 用图象表示的变量间关系 课件
- 2023年艺术与审美期末试卷答案参考
- 电气工程竣工验收表格模板
- Teladoc全球领先的远程医疗服务商
- 制程品质检验流程图
- 必修地球圈层结构通用PPT课件
- 物联网体系结构PPT课件
- 80吨吊车性能表
- 智能照明控制系统工程报价清单明细表
评论
0/150
提交评论