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基本操作的更多相关文章

  1. ORACLE PL/SQL编程详解

    ORACLE PL/SQL编程详解 编程详解 SQL语言只是访问.操作数据库的语言,并不是一种具有流程控制的程序设计语言,而只有程序设计语言才能用于应用软件的开发.PL /SQL是一种高级数据库程序设 ...

  2. Oracle Pl/SQL编程基础

    Pl/SQL简介 提高应用程序的运行性能, 提供模块化的程序设计, 自定义标示符, 具有过程语言控制结构, 良好的兼容性, 处理运行错误. Pl/SQL语言基础 sql是关系数据库的基本操作语言. s ...

  3. pl/sql command window 初步接触

    pl/sql command window基本操作 PL/SQL Developer应用两年了,今天第一次应用command window. command window类似于sqlplus窗口: 1 ...

  4. PL/SQL之基础篇

    参考文献:<Oracle完全学习手册>第11章 1.PL/SQL概述 PL/SQL(Procedure Language/Structuer Query Language)是Oracle对 ...

  5. Oracle PL/SQL随堂笔记总结

    1.pl/sql编程 2.存储过程 3.函数 4.触发器 5.包 6.pl/sql基础 -定义并使用变量 7.pl/sql的进阶 8.oracle的视图 1.pl/sql编程 1.理解oracle的p ...

  6. Oracle学习笔记十 使用PL/SQL

    PL/SQL 简介 PL/SQL 是过程语言(Procedural Language)与结构化查询语言(SQL)结合而成的编程语言,是对 SQL 的扩展,它支持多种数据类型,如大对象和集合类型,可使用 ...

  7. PL/SQL连接错误:ora-12705:cannot access NLS data files or invalid environment specified

    适合自己的解决方法: 排查问题: 1. 你没有安装Oracle Client软件.这是使用PL/SQL Developer的必须条件.安装Oracle Client后再重试.2. 你安装了多个Orac ...

  8. PL/SQL循环

    1.if循环做判断 SET SERVEROUTPUT ON accept num prompt 'qinshuu'; DECLARE pnum NUMBER :=& num ; BEGIN T ...

  9. PL/SQL存储过程编程

    PL/SQL存储过程编程 /**author huangchaobiao *Email:huangchaobiao111@163.com */ PL/SQL存储过程编程(上) 1. Oracle应用编 ...

随机推荐

  1. java面向对象2-封装

    2 封装 封装:是指隐藏对象的属性和实现细节,仅对外提供公共访问方式,面向对象三大特点之一.好处: 防止数据被任意篡改,提高安全性 隐藏了实现细节,仅暴露方法 如何实现封装? 使用private关键字 ...

  2. CodeForces-682C(DFS,树,思维)

    链接: https://vjudge.net/problem/CodeForces-682C 题意: Alyona decided to go on a diet and went to the fo ...

  3. 容器"共享"宿主机的hosts文件(终极方案)

    0.背景 有时候制作docker镜像生成容器时需要宿主机的hosts文件共享到容器中.首先想的是通过挂载的方式共享hosts文件,但是实践时发现根本行不通,hosts文件在/etc/目录下,如进行挂载 ...

  4. 【leetcode】1219. Path with Maximum Gold

    题目如下: In a gold mine grid of size m * n, each cell in this mine has an integer representing the amou ...

  5. app自动化的执行

    appium --address 127.0.0.1 --port 10000 --bootstrap-port 10100 --webdriveragent-port 10110 在指定的目录下执行 ...

  6. 编译caffe-gpu-cuda及cudnn-tar 下载地址

    y下载 https://github.com/BVLC/caffe https://github.com/BVLC/caffe/archive/master.zip gcc caffe安装 有2个问题 ...

  7. Linux 系统磁盘空间占满,df 和 du 结果不一致

    服务器运行一段时间后df查看磁盘剩余空间不足,通过du统计发现被几个文件占用,遂删除之.过了一段时间磁盘空间再次不足,通过du统计却找不到那么多大文件.搜索后才得知原因:文件删除后空间没有释放,du统 ...

  8. webUploader---实现大文件断点续传

    核心原理: 该项目核心就是文件分块上传.前后端要高度配合,需要双方约定好一些数据,才能完成大文件分块,我们在项目中要重点解决的以下问题. * 如何分片: * 如何合成一个文件: * 中断了从哪个分片开 ...

  9. Qt新建工程

    1.基本步骤 (1)Qt Quick Project是开发QML语言的: (2)Qt Widget Project是基于部件的开发,一种是PC的Qt Gui Application,一种是手机的Mob ...

  10. JUnit——assertThat(acture,matcher)

    使用hamcrest之前需要引入相关的jar包,包括hamcrest-core.1.3.jar和hamcrest-library-1.3.jar. 具体引入的方法为:右击JUnit工程——build ...