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. 【leetcode】1178. Number of Valid Words for Each Puzzle

    题目如下: With respect to a given puzzle string, a word is valid if both the following conditions are sa ...

  2. html applet标签 语法

    html applet标签 语法 作用:定义嵌入的 applet. 说明:某些浏览器中依然存在对 <applet> 但是需要额外的插件和安装过程才能起作用.大理石机械构件 注释:HTML5 ...

  3. Redis单节点部署

    安装Redis 由于REDIS使用单线程处理请求,CPU的快慢最对REDIS的性能有较大影响,官方建议INTEL的CPU,其效率能比AMD高一倍左右. 下载Redis:wget http://down ...

  4. bootstrap editable初始化后表单可修改数据

    function loadData() { var url = "${ctx }/sys/marketing/product/page"; $('#tablepager').boo ...

  5. bootstrap的editTable实现方法

    首先下载基于bootstrap的源码到本地.引用相关文件. <link href="/Content/bootstrap/css/bootstrap.min.css" rel ...

  6. [LeetCode]-009-Palindrome_Number

    Determine whether an integer is a palindrome. Do this without extra space. Some hints: Could negativ ...

  7. python基础之 数据格式化

    %还是format 皇城PK Python中格式化字符串目前有两种阵营:%和format,我们应该选择哪种呢? 自从Python2.6引入了format这个格式化字符串的方法之后,我认为%还是form ...

  8. 02 body标签中的相关标签

    今日内容: 字体标签: h1~h6.<font>.<u>.<b>.<strong><em>.<sup>.<sub> ...

  9. @清晰掉 sprintf sscanf双胞胎

    sprintf() 格式化输出函数(图形) 功能: 函数sprintf()用来作格式化的输出.用法: 此函数调用方式为int sprintf(char *string,char *format,arg ...

  10. @清晰掉 spi协议及工作原理分析

    说明.文章摘自:SPI协议及其工作原理浅析 http://bbs.chinaunix.net/thread-1916003-1-1.html 一.概述. SPI, Serial Perripheral ...