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应用编 ...
随机推荐
- Gym-100923L-Por Costel and the Semipalindromes(进制转换,数学)
链接: https://vjudge.net/problem/Gym-100923L 题意: Por Costel the pig, our programmer in-training, has r ...
- Vue $root、$parent、$refs
Vue处理边界parent.$refs 下面的功能都是有风险的,尽量避免使用 Vue 子组件可以通过 $root 属性访问父组件实例的属性和方法 <div id="app"& ...
- Python:查看解释器的位置
以前学Python时,有时出现这样的情况:明明记得装了scipy包,怎么打import scipy报错说我没这个包? 问题出在,你的电脑上安装了不止一个Python... 而每安装一个包,仅仅在这个P ...
- Github Actions教程:运行python代码并Push到远端仓库
我自己做了一个网站,这个网站会使用一个python脚本来生成. 具体生成的方法是python脚本会读取目录下的csv文件,将每一行数据解析成固定格式,然后生成html文件,最后需要将修改后的文件自动p ...
- MySQL_DQL操作
DQL(Data Query Language)简单的来说就是数据的查询语言. 1.最简单的查询(显示表中的所有信息) 语法: select * from 表名; 2.普通查询 语法: select ...
- DVWA--XSS(stored)
XSS 0X01 1.简介 跨站脚本(cross site script)为了避免与样式css混淆,所以简称为XSS. XSS是一种经常出现在web应用中的计算机安全漏洞,也是web中最主流的攻击方式 ...
- 测试相关shell命令总结2——结构控制语句,命令行参数
1,shell 中单引号和双引号的区别,单引号不进行解释.双引号进行解释 1,在shell中进行数学运算,放在$和[]中 $[1+2] 有些很奇怪,在.sh文件中放在(())中貌似也能够进行数学运算. ...
- [LeetCode]-algorithms-Median of Two Sorted Arrays
There are two sorted arrays nums1 and nums2 of size m and n respectively. Find the median of the two ...
- html初体验#2
碎碎念 关于布局 css布局:横向.纵向 2019年新进展:css grid git bash 上安装 http server 目的在于不使用 file:// 打开自己写的文件,使用 http:// ...
- react注
创建新项目: npm create-react-app test1 运行项目:npm start