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应用编 ...
随机推荐
- 利用poi操作word文档
关键字:POI JAVA 批注 总页数 总字符数 一:认识POI Apache POI是一个开源的利用Java读写Excel.WORD等微软OLE2组件文档的项目.最新的3.5版本有很多改进,加入了对 ...
- git 清除缓存
清除git缓存 git config --local --unset credential.helper git config --global --unset credential.helper g ...
- CodeForces 1100F Ivan and Burgers
CodeForces题面 Time limit 3000 ms Memory limit 262144 kB Source Codeforces Round #532 (Div. 2) Tags da ...
- pycharm的个性化设置
1. 调整背景颜色 file -- settings -- Editor -- Color Scheme 2. 调整字体.字号.行间距 file -- settings -- Editor -- Fo ...
- eclipse代码自动补全设置
1.说明 eclipse安装好了之后,在编辑框中输入某个英文字符,默认不自动弹出自动代码选择框,需要手动按下 Alt + / 或者输入的字符为 . 才弹出代码自动补全框.其实eclipse是可以设置 ...
- sqli-labs(10)
基于双引号的时间盲注 先来随便测试一下 发现 错不错都是返回的真确的结果 那么应该是被从定向了 我们可以输入 and sleep(5) %23 测试 加’发现立刻返回 加双引号发现报错了 过了5秒才返 ...
- windows7 中 wacom数位板如何关闭点击水波 和长按右键这两个特效
就是点住笔尖不动,就会弹出右键,这个功能是微软操作系统具有的一项功能,,如果您感觉不便,可以按以下方法将其去掉: 1.打开"控制面板--笔和触摸--笔选项--按下并保持--设置": ...
- python之random随机函数
random.random()用于生成 用于生成一个指定范围内的随机符点数,两个参数其中一个是上限,一个是下限.如果a > b,则生成随机数 1 n: a <= n <= b.如果 ...
- 一、基础篇--1.1Java基础-面向对象的特征
面向对象的特征 封装.继承和多态 https://blog.csdn.net/jianyuerensheng/article/details/51602015 封装: 定义:封装就是将数据或函数等集合 ...
- c++11多线程---std::ref和std::cref
std::ref和std::cref 解释 std::ref 用于包装按引用传递的值. std::cref 用于包装按const引用传递的值. 为什么需要std::ref和std::cref ...