PL/SQL基本操作
1、常规过程化形式
declare
o_booking_flag char(10);
begin -- Call the procedure
destine_ticket('',
20,
'E',
2,
o_booking_flag);
dbms_output.put_line(o_booking_flag);
end;
2、存储过程
create or replace procedure destine_ticket(i_flightId in char, --不需要些类型值
i_LuggageLimit in number ,
i_class_code in char ,
i_seats in number,
o_booking_flag out char
)
is
v_temp integer;
v_temp1 integer;
begin begin
select 1 into v_temp from flight t1 where t1.flightid=i_flightId and to_number(t1.estdeparturedatetime-sysdate)*24 >= 3;
exception --异常捕获
when no_data_found then
v_temp:=0; --复制要写:=
end;
return; --退出存储过程 end destine_ticket; 异常处理
--一异常处理的代码
--sqlcode 异常编号
--sqlerrm 信号字符串 /* 在plsql 块中格式 Declare
变量
Begin
代码块 EXCEPTION
when 异常的名称 then
如生上面的异常时做的具体工作。
End; */ set serveroutput on;
create or replace procedure pr12
as
--定义一个int变liang
v_age integer;
v_name varchar(30);
begin
v_age:=89;
--通过select给v_name设置值
--修改成过程
select name into v_name from stud where id=1;
DBMS_OUTPUT.PUT_LINE('没有出错');
exception
when value_error then
SYS.DBMS_OUTPUT.PUT_LINE('数值错误');
when no_data_found then
SYS.DBMS_OUTPUT.PUT_LINE('没有数据');
when others then
SYS.DBMS_OUTPUT.PUT_LINE(sqlcode||'你出错了'||sqlerrm);
end; exec pr12();
-----------------------------------------
--自定义异常自己抛出异常/
/*
定义一个自己的异常
myException Exception;
抛出异常
RAISE myException; 处理自己的异常:
Exception
When myException then
....
*/
set serveroutput on;
declare
myEx exception;
begin
DBMS_OUTPUT.PUT_LINE('这里没错');
raise myEx;
DBMS_OUTPUT.PUT_LINE('不会输出,前面抛出异常');
--处理异常
exception
when myEx then
DBMS_OUTPUT.PUT_LINE('自己的异常'||sqlcode||' '||sqlerrm);
when others then
DBMS_OUTPUT.PUT_LINE('不知知道什么错误'||sqlcode||sqlerrm);
END;
---出错直接抛出 declare
begin
DBMS_OUTPUT.PUT_LINE('no errors');
--直接抛出
RAISE_APPLICATION_ERROR(-20000, 'A');
DBMS_OUTPUT.PUT_LINE('go okk....');
exception
when others then
DBMS_OUTPUT.PUT_LINE(sqlcode||' '||sqlerrm);
end;
3、过程调用
declare
o_booking_flag char(10);
begin -- Call the procedure
destine_ticket(i_flightid =>'',
i_luggagelimit =>20,
i_class_code =>'E',
i_seats =>2,
o_booking_flag =>o_booking_flag);
end;
4、触发器
注意,一般删除、更新等触发器,不能调用触发器表本身
create or replace trigger flight_staff_check
before insert or update or delete on flight
for each row
declare
-- local variables here
cap_id char(100);
fir_id char(100);
flag integer;
begin
if inserting then
--select :new.captainstaffid into cap_id,:new.firstofficerstaffid into fir_id from dual;
cap_id:=:new.captainstaffid;
fir_id:=:new.firstofficerstaffid;
end if; if updating then
--select :new.captainstaffid into cap_id,:new.firstofficerstaffid into fir_id from dual;
cap_id:=:new.captainstaffid;
fir_id:=:new.firstofficerstaffid;
end if;
if deleting then
--select :old.captainstaffid into cap_id,:old.firstofficerstaffid into fir_id from dual;
cap_id:=:old.captainstaffid;
fir_id:=:old.firstofficerstaffid;
end if; end
PL/SQL基本操作的更多相关文章
- ORACLE PL/SQL编程详解
ORACLE PL/SQL编程详解 编程详解 SQL语言只是访问.操作数据库的语言,并不是一种具有流程控制的程序设计语言,而只有程序设计语言才能用于应用软件的开发.PL /SQL是一种高级数据库程序设 ...
- Oracle Pl/SQL编程基础
Pl/SQL简介 提高应用程序的运行性能, 提供模块化的程序设计, 自定义标示符, 具有过程语言控制结构, 良好的兼容性, 处理运行错误. Pl/SQL语言基础 sql是关系数据库的基本操作语言. s ...
- pl/sql command window 初步接触
pl/sql command window基本操作 PL/SQL Developer应用两年了,今天第一次应用command window. command window类似于sqlplus窗口: 1 ...
- PL/SQL之基础篇
参考文献:<Oracle完全学习手册>第11章 1.PL/SQL概述 PL/SQL(Procedure Language/Structuer Query Language)是Oracle对 ...
- Oracle PL/SQL随堂笔记总结
1.pl/sql编程 2.存储过程 3.函数 4.触发器 5.包 6.pl/sql基础 -定义并使用变量 7.pl/sql的进阶 8.oracle的视图 1.pl/sql编程 1.理解oracle的p ...
- Oracle学习笔记十 使用PL/SQL
PL/SQL 简介 PL/SQL 是过程语言(Procedural Language)与结构化查询语言(SQL)结合而成的编程语言,是对 SQL 的扩展,它支持多种数据类型,如大对象和集合类型,可使用 ...
- PL/SQL连接错误:ora-12705:cannot access NLS data files or invalid environment specified
适合自己的解决方法: 排查问题: 1. 你没有安装Oracle Client软件.这是使用PL/SQL Developer的必须条件.安装Oracle Client后再重试.2. 你安装了多个Orac ...
- PL/SQL循环
1.if循环做判断 SET SERVEROUTPUT ON accept num prompt 'qinshuu'; DECLARE pnum NUMBER :=& num ; BEGIN T ...
- PL/SQL存储过程编程
PL/SQL存储过程编程 /**author huangchaobiao *Email:huangchaobiao111@163.com */ PL/SQL存储过程编程(上) 1. Oracle应用编 ...
随机推荐
- 【leetcode】1105. Filling Bookcase Shelves
题目如下: We have a sequence of books: the i-th book has thickness books[i][0] and height books[i][1]. W ...
- Codeforces 912D Fishs ( 贪心 && 概率期望 && 优先队列 )
题意 : 给出一个 N * M 的网格,然后给你 K 条鱼给你放置,现有规格为 r * r 的渔网,问你如果渔网随意放置去捕捞小鱼的情况下,捕到的最大期望值是多少? 分析 : 有一个很直观的想法就是 ...
- hdu_3466(01背包)
其实,就是让C商品的q不等于p,其他都相同,这时,你就会发现如果要买C商品的话,肯定得先买C商品,因为买C商品的代价最大.所以,我们可以按照qi-pi的顺序来确定大顺序.这里我们还可以用更严谨的方式来 ...
- 今天跟outlook顶上牛了
之前使用的是2007,然后之前弄东西的时候给升到2010了,之前就是把所有的邮件都保存到本地的文件中,我还想使用之前的文件,然后2010就是不好使,后来查了半天发现原来是需要手动创建账户,参考http ...
- C# 使用 MsieJavaScriptEngine 引擎运行JavaScript
用这个东西实现了一个js脚本引擎代码生成器,调研的时候这个东西的资料比较少. 我就根据自己的这点应用来讲解讲解,有错误,不符的地方还请园友指出. 使用 Nuget 安装 MsieJavaScriptE ...
- ORACLE 错误案例—ORA-27102: out of memory
SQL> startupORA-27102: out of memoryLinux-x86_64 Error: 28: No space left on deviceAdditional inf ...
- java中FastJson的json类型转换
JSON Gson: 来自Google,功能全面.快速.简洁.面向对象.数据传递和解析方便. Jackson:来源FasterXML项目,社区活跃,更新快 解析速度和效率比Gson快,但无法按需解析, ...
- 3、Shiro授权
Shiro授权过程和认证过程相似: 项目结构: package com.shiro.shiroframe; import org.apache.shiro.SecurityUtils; import ...
- IE浏览器中图片路径正确< img ... />标签不显示图片
如下图所示,下面的html要去加载上面的jpg图片: 代码如下: <img src="luzhanshi1.jpg" alt="图片加载失败"> 使 ...
- 自定义配置节点configSections的使用
//App.config <?xml version="1.0" encoding="utf-8" ?><configuration> ...