第一范文网 - 专业文章范例文档资料分享平台

Oracle plsql程序设计基础 

来源:用户分享 时间:2025/8/21 7:47:40 本文由loading 分享 下载这篇文档手机版
说明:文章内容仅供预览,部分内容可能不全,需要完整文档或者需要复制内容,请下载word后使用。下载word有问题请添加微信号:xxxxxxx或QQ:xxxxxx 处理(尽可能给您提供完整文档),感谢您的支持与谅解。

Oracle9i 开发指南:PL/SQL程序设计 清华大学出版社 ISBN 7-302-08002-x

Ben整理 2004年 秋

MSN: mascotzhuang@hotmail.com

Oracle常用命令举例

?? 基本语法

?? % type用法 ?? %rowtype用法 ?? TYPE用法 ?? 游标的使用 ?? for 循环 ?? loop循环 ?? while循环 ?? if / else 的用法 ?? case 的用法 ?? 错误定义

?? error的设定 ?? exception用法 ?? 存储过程及函数

?? procedure 的建立和调用 ?? function的建立和调用

?? 参数的调用(in 模式为按址调用,out / in out模式为按值调用。NOCOPY 强行转换成按址调用)。 ?? 软件包及封装

?? 软件包(PACKAGE)的建立和调用 ?? 软件包的全局结构 ?? 封装函数的纯度

?? 查看源代码及建立用户、用户的权限

?? 源代码的查看 ?? 建立用户及登陆 ?? 授予权限和权限收回 ?? 依赖

?? 直接依赖 ?? 查看依赖 ?? 包之间调用 ?? 触发器

?? 建立简单的触发器 ?? 触发器分类 ?? 稍复杂的触发器 ?? 条件谓词

?? 触发器中不可使用Commit ?? 系统触发器举例(LOGON) ?? instead of 触发器

Oracle9i 开发指南:PL/SQL程序设计 清华大学出版社 ISBN 7-302-08002-x

Ben整理 2004年 秋

MSN: mascotzhuang@hotmail.com

1. % type用法,提取% type所在字段的类型

declare

myid dept.id % type; myname dept.name % type; begin

select id,name into myid,myname from dept; dbms_output.put_line(myid); dbms_output.put_line(myname);

end; /

2. %rowtype用法,提取%rowtype所在的字段的类型

declare

type type_dept is table of dept % rowtype index by binary_integer; tb type_dept; begin

tb(1).id:='001'; tb(2).id:='001';

dbms_output.put_line(tb.COUNT); end; /

3. TYPE用法,相当于结构体

declare

lv_order_date DAte:=sysdate; lv_last_txt varchar2(5) default '001'; lv_last varchar2(10) not null:='us'; TYPE type_test is record( myid dept.id % type, myname dept.name % type); rec type_test; begin

lv_order_date:=sysdate; dbms_output.put_line(lv_last); select id,name into rec from dept;

dbms_output.put_line(rec.myid); dbms_output.put_line(rec.myname); end;

Oracle9i 开发指南:PL/SQL程序设计 清华大学出版社 ISBN 7-302-08002-x

Ben整理 2004年 秋

MSN: mascotzhuang@hotmail.com

/

4. 游标的使用 declare g_id char(10):='002'; find_not char(1):='N'; cursor cur is select * from dept; TYPE type_dept is record( myid dept.id % type, myname dept.name % type, myaddr dept.addr % type); rect type_dept; begin open cur; loop fetch cur into rect; exit when cur% NOTFOUND; if rect.myid=g_id then find_not:='Y'; dbms_output.put_line('Find it!!'); dbms_output.put_line('DEPT ID:' || rect.myid); dbms_output.put_line('NAME:' || rect.myname); dbms_output.put_line('ADDR:' || rect.myaddr); end if; end loop; close cur; if find_not='N' then dbms_output.put_line('no record'); end if; end; / 提取cur指向的记录到rect结构中 cur指向表 5. for 循环

begin

for i in 1..5 loop

dbms_output.put_line(i); end loop; end; /

6.

loop循环

Oracle9i 开发指南:PL/SQL程序设计 清华大学出版社 ISBN 7-302-08002-x

Ben整理 2004年 秋

MSN: mascotzhuang@hotmail.com

declare v number:=1; begin

loop

exit when v>5;

dbms_output.put_line(v); v:=v+1; end loop; end; /

7. while循环

declare v number:=1; begin

while v<5 loop

dbms_output.put_line(v); v:=v+1; end loop; end; /

8. error的设定

declare

v1 number:=90; begin

if v1=10 then dbms_output.put_line('v1 is 10'); elsif v1=20 then dbms_output.put_line('v2 is 20'); else goto err;

dbms_output.put_line('normal end'); <>

dbms_output.put_line('error found'); end if; end; /

Oracle9i 开发指南:PL/SQL程序设计 清华大学出版社 ISBN 7-302-08002-x

Ben整理 2004年 秋

MSN: mascotzhuang@hotmail.com

9. exception用法

declare

ex Exception; begin

Update dept set name='Edison' where id='100'; if SQL%NOTFOUND Then

Raise ex; end if; Exception end; / declare

type rc_dept is record ( myid dept.id%type, myname dept.name%type, myaddr dept.addr%type );

tb rc_dept; begin

select id,name,addr into tb from dept where id=:gb_id; dbms_output.put_line('id:' || tb.myid); dbms_output.put_line('name:' || tb.myname); dbms_output.put_line('addr:' || tb.myaddr); When ex then

dbms_output.put_line('update failed.');

exception

when NO_DATA_FOUND then

dbms_output.put_line('no record is found');

dbms_output.put_line('too many rows are selected');

when TOO_MANY_ROWS then when OTHERS then

dbms_output.put_line('undefine error'); dbms_output.put_line('error coede: ' || SQLCODE); end; /

dbms_output.put_line('error message:' || SQLERRM);

搜索更多关于: Oracle plsql程序设计基础  的文档
Oracle plsql程序设计基础 .doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.diyifanwen.net/c7qna1893aj3uh255bmmg_1.html(转载请注明文章来源)
热门推荐
Copyright © 2012-2023 第一范文网 版权所有 免责声明 | 联系我们
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:xxxxxx 邮箱:xxxxxx@qq.com
渝ICP备2023013149号
Top