PL/SQL语言基础
2 a integer;
3 b varchar2(10);
4 no emp.empno%type;
5 e emp%rowtype;
6 begin
7 a:=10;
8 b:='Axiao';
9 select empno into no from emp where empno=7369;
10 select * into e from emp where empno=7788;
11 dbms_output.put_line(a);
12 dbms_output.put_line(b);
13 dbms_output.put_line(no);
14 dbms_output.put_line(to_char(e.empno)||','||e.ename||','||e.job);
15* end;
16 /
SQL> /
10
Axiao
7369
7788,SCOTT,ANALYST
已写入文件 afiedt.buf
2 a integer;
3 b varchar2(10);
4 no emp.empno%type;
5 e emp%rowtype;
6 type tab_s is table of integer index by binary_integer;
7 t_s tab_s;
8 begin
9 a:=10;
10 b:='Axiao';
11 select empno into no from emp where empno=7369;
12 select * into e from emp where empno=7788;
13 t_s(3):=10;
14 t_s(5):=20;
15 dbms_output.put_line(a);
16 dbms_output.put_line(b);
17 dbms_output.put_line(no);
18 dbms_output.put_line(to_char(e.empno)||','||e.ename||','||e.job);
19 dbms_output.put_line(t_s(3));
20 dbms_output.put_line(t_s(5));
21* end;
SQL> /
10
Axiao
7369
7788,SCOTT,ANALYST
10
20
已写入文件 afiedt.buf
2 a integer;
3 b varchar2(10);
4 no emp.empno%type;
5 e emp%rowtype;
6 type tab_s is table of integer index by binary_integer;
7 t_s tab_s;
8 type rec_s is record
9 (subject varchar2(10),
10 score integer);
11 r_s rec_s;
12 begin
13 a:=10;
14 b:='Axiao';
15 select empno into no from emp where empno=7369;
16 select * into e from emp where empno=7788;
17 t_s(3):=10;
18 t_s(5):=20;
19 r_s.subject='语文';
20 r_s.score=70;
21 dbms_output.put_line(a);
22 dbms_output.put_line(b);
23 dbms_output.put_line(no);
24 dbms_output.put_line(to_char(e.empno)||','||e.ename||','||e.job);
25 dbms_output.put_line(t_s(3));
26 dbms_output.put_line(t_s(5));
27 dbms_output.put_line(r_s.subject||','||to_char(r_s.score));
28* end;
SQL> ed
已写入文件 afiedt.buf
2 a integer;
3 b varchar2(10);
4 no emp.empno%type;
5 e emp%rowtype;
6 type tab_s is table of integer index by binary_integer;
7 t_s tab_s;
8 type rec_s is record
9 (subject varchar2(10),
10 score integer);
11 r_s rec_s;
12 begin
13 a:=10;
14 b:='Axiao';
15 select empno into no from emp where empno=7369;
16 select * into e from emp where empno=7788;
17 t_s(3):=10;
18 t_s(5):=20;
19 r_s.subject:='语文';
20 r_s.score:=70;
21 dbms_output.put_line(a);
22 dbms_output.put_line(b);
23 dbms_output.put_line(no);
24 dbms_output.put_line(to_char(e.empno)||','||e.ename||','||e.job);
25 dbms_output.put_line(t_s(3));
26 dbms_output.put_line(t_s(5));
27 dbms_output.put_line(r_s.subject||','||to_char(r_s.score));
28* end;
SQL> /
10
Axiao
7369
7788,SCOTT,ANALYST
10
20
语文,70
已写入文件 afiedt.buf
2 a integer;
3 b varchar2(10);
4 no emp.empno%type;
5 e emp%rowtype;
6 type tab_s is table of integer index by binary_integer;
7 t_s tab_s;
8 type rec_s is record
9 (subject varchar2(10),
10 score integer);
11 r_s rec_s;
12 begin
13 a:=10;
14 b:='Axiao';
15 select empno into no from emp where empno=9999;
16 select * into e from emp where empno=7788;
17 t_s(3):=10;
18 t_s(5):=20;
19 r_s.subject:='语文';
20 r_s.score:=70;
21 dbms_output.put_line(a);
22 dbms_output.put_line(b);
23 dbms_output.put_line(no);
24 dbms_output.put_line(to_char(e.empno)||','||e.ename||','||e.job);
25 dbms_output.put_line(t_s(3));
26 dbms_output.put_line(t_s(5));
27 dbms_output.put_line(r_s.subject||','||to_char(r_s.score));
28 exception
29 when no_data_found then
30 dmbs_output.put_line('没有找到合适的记录');
31 when too_many_rows then
32 dmbs_output.put_line('找到太多的确记录');
33* end;
SQL> /
dmbs_output.put_line('没有找到合适的记录');
*
ERROR 位于第 30 行:
ORA-06550: 第 30 行, 第 6 列:
PLS-00201: 必须说明标识符 'DMBS_OUTPUT.PUT_LINE'
ORA-06550: 第 30 行, 第 6 列:
PL/SQL: Statement ignored
ORA-06550: 第 32 行, 第 6 列:
PLS-00201: 必须说明标识符 'DMBS_OUTPUT.PUT_LINE'
ORA-06550: 第 32 行, 第 6 列:
PL/SQL: Statement ignored
SQL> ed
已写入文件 afiedt.buf
2 a integer;
3 b varchar2(10);
4 no emp.empno%type;
5 e emp%rowtype;
6 type tab_s is table of integer index by binary_integer;
7 t_s tab_s;
8 type rec_s is record
9 (subject varchar2(10),
10 score integer);
11 r_s rec_s;
12 begin
13 a:=10;
14 b:='Axiao';
15 select empno into no from emp where empno=9999;
16 select * into e from emp where empno=7788;
17 t_s(3):=10;
18 t_s(5):=20;
19 r_s.subject:='语文';
20 r_s.score:=70;
21 dbms_output.put_line(a);
22 dbms_output.put_line(b);
23 dbms_output.put_line(no);
24 dbms_output.put_line(to_char(e.empno)||','||e.ename||','||e.job);
25 dbms_output.put_line(t_s(3));
26 dbms_output.put_line(t_s(5));
27 dbms_output.put_line(r_s.subject||','||to_char(r_s.score));
28 exception
29 when no_data_found then
30 dbms_output.put_line('没有找到合适的记录');
31 when too_many_rows then
32 dbms_output.put_line('找到太多的确记录');
33* end;
SQL> /
没有找到合适的记录
已写入文件 afiedt.buf
2 a integer;
3 b varchar2(10);
4 no emp.empno%type;
5 e emp%rowtype;
6 type tab_s is table of integer index by binary_integer;
7 t_s tab_s;
8 type rec_s is record
9 (subject varchar2(10),
10 score integer);
11 r_s rec_s;
12 begin
13 a:=10;
14 b:='Axiao';
15 select empno into no from emp where job='CLERK';
16 select * into e from emp where empno=7788;
17 t_s(3):=10;
18 t_s(5):=20;
19 r_s.subject:='语文';
20 r_s.score:=70;
21 dbms_output.put_line(a);
22 dbms_output.put_line(b);
23 dbms_output.put_line(no);
24 dbms_output.put_line(to_char(e.empno)||','||e.ename||','||e.job);
25 dbms_output.put_line(t_s(3));
26 dbms_output.put_line(t_s(5));
27 dbms_output.put_line(r_s.subject||','||to_char(r_s.score));
28 exception
29 when no_data_found then
30 dbms_output.put_line('没有找到合适的记录');
31 when too_many_rows then
32 dbms_output.put_line('找到太多的确记录');
33* end;
SQL> /
找到太多的确记录
已写入文件 afiedt.buf
2 a integer;
3 b varchar2(10);
4 c integer;
5 no emp.empno%type;
6 e emp%rowtype;
7 type tab_s is table of integer index by binary_integer;
8 t_s tab_s;
9 type rec_s is record
10 (subject varchar2(10),
11 score integer);
12 r_s rec_s;
13 ee exception;
14 pragma exception_init(ee,-1427);
15 begin
16 a:=10;
17 b:='Axiao';
18 c:=a/0;
19 select empno into no from emp where job='CLERK';
20 select * into e from emp where empno=7788;
21 t_s(3):=10;
22 t_s(5):=20;
23 r_s.subject:='语文';
24 r_s.score:=70;
25 dbms_output.put_line(a);
26 dbms_output.put_line(b);
27 dbms_output.put_line(no);
28 dbms_output.put_line(to_char(e.empno)||','||e.ename||','||e.job);
29 dbms_output.put_line(t_s(3));
30 dbms_output.put_line(t_s(5));
31 dbms_output.put_line(r_s.subject||','||to_char(r_s.score));
32 exception
33 when no_data_found then
34 dbms_output.put_line('没有找到合适的记录');
35 when too_many_rows then
36 dbms_output.put_line('找到太多的确记录');
37 when ee then
38 dbms_output.put_line('除0了!');
39* end;
SQL> /
declare
*
ERROR 位于第 1 行:
ORA-01476: 除数为 0
ORA-06512: 在line 18
SQL> ed
已写入文件 afiedt.buf
2 a integer;
3 b varchar2(10);
4 c integer;
5 no emp.empno%type;
6 e emp%rowtype;
7 type tab_s is table of integer index by binary_integer;
8 t_s tab_s;
9 type rec_s is record
10 (subject varchar2(10),
11 score integer);
12 r_s rec_s;
13 ee exception;
14 pragma exception_init(ee,-1427);
15 begin
16 a:=10;
17 b:='Axiao';
18 c:=a/0;
19 select empno into no from emp where job='CLERK';
20 select * into e from emp where empno=7788;
21 t_s(3):=10;
22 t_s(5):=20;
23 r_s.subject:='语文';
24 r_s.score:=70;
25 dbms_output.put_line(a);
26 dbms_output.put_line(b);
27 dbms_output.put_line(no);
28 dbms_output.put_line(to_char(e.empno)||','||e.ename||','||e.job);
29 dbms_output.put_line(t_s(3));
30 dbms_output.put_line(t_s(5));
31 dbms_output.put_line(r_s.subject||','||to_char(r_s.score));
32 exception
33 when others then
34 dbms_output.put_line(sqlcode);
35* end;
SQL> /
-1476
已写入文件 afiedt.buf
2 a integer;
3 b varchar2(10);
4 c integer;
5 no emp.empno%type;
6 e emp%rowtype;
7 type tab_s is table of integer index by binary_integer;
8 t_s tab_s;
9 type rec_s is record
10 (subject varchar2(10),
11 score integer);
12 r_s rec_s;
13 ee exception;
14 pragma exception_init(ee,-1476);
15 begin
16 a:=10;
17 b:='Axiao';
18 c:=a/0;
19 select empno into no from emp where job='CLERK';
20 select * into e from emp where empno=7788;
21 t_s(3):=10;
22 t_s(5):=20;
23 r_s.subject:='语文';
24 r_s.score:=70;
25 dbms_output.put_line(a);
26 dbms_output.put_line(b);
27 dbms_output.put_line(no);
28 dbms_output.put_line(to_char(e.empno)||','||e.ename||','||e.job);
29 dbms_output.put_line(t_s(3));
30 dbms_output.put_line(t_s(5));
31 dbms_output.put_line(r_s.subject||','||to_char(r_s.score));
32 exception
33 when ee then
34 dbms_output.put_line('除0了!');
35 when others then
36 dbms_output.put_line(sqlcode);
37* end;
SQL> /
除0了!
2 a integer;
3 b varchar2(10);
4 c integer;
5 no emp.empno%type;
6 e emp%rowtype;
7 type tab_s is table of integer index by binary_integer;
8 t_s tab_s;
9 type rec_s is record
10 (subject varchar2(10),
11 score integer);
12 r_s rec_s;
13 ee exception;
14 pragma exception_init(ee,-1476);
15 e1 exception;
16 begin
17 a:=0;
18 b:='Axiao';
19 if a=0 then
20 raise e1;
21 end if;
22 c:=a/0;
23 select empno into no from emp where job='CLERK';
24 select * into e from emp where empno=7788;
25 t_s(3):=10;
26 t_s(5):=20;
27 r_s.subject:='语文';
28 r_s.score:=70;
29 dbms_output.put_line(a);
30 dbms_output.put_line(b);
31 dbms_output.put_line(no);
32 dbms_output.put_line(to_char(e.empno)||','||e.ename||','||e.job);
33 dbms_output.put_line(t_s(3));
34 dbms_output.put_line(t_s(5));
35 dbms_output.put_line(r_s.subject||','||to_char(r_s.score));
36 exception
37 when ee then
38 dbms_output.put_line('除0了!');
39 when e1 then
40 dbms_output.put_line('a不可以为0了!');
41 when others then
42 dbms_output.put_line(sqlcode);
43* end;
SQL> /
a不可以为0了!
已写入文件 afiedt.buf
2 a integer;
3 b varchar2(10);
4 c integer;
5 no emp.empno%type;
6 e emp%rowtype;
7 type tab_s is table of integer index by binary_integer;
8 t_s tab_s;
9 type rec_s is record
10 (subject varchar2(10),
11 score integer);
12 r_s rec_s;
13 ee exception;
14 pragma exception_init(ee,-1476);
15 e1 exception;
16 begin
17 a:=0;
18 b:='Axiao';
19 if a=0 then
20 raise e1;
21 end if;
22 c:=a/0;
23 select empno into no from emp where job='CLERK';
24 select * into e from emp where empno=7788;
25 t_s(3):=10;
26 t_s(5):=20;
27 r_s.subject:='语文';
28 r_s.score:=70;
29 dbms_output.put_line(a);
30 dbms_output.put_line(b);
31 dbms_output.put_line(no);
32 dbms_output.put_line(to_char(e.empno)||','||e.ename||','||e.job);
33 dbms_output.put_line(t_s(3));
34 dbms_output.put_line(t_s(5));
35 dbms_output.put_line(r_s.subject||','||to_char(r_s.score));
36 exception
37 when others then
38 dbms_output.put_line(to_char(sqlcode)||','||sqlerrm);
39* end;
SQL> /
1,User-Defined Exception
已写入文件 afiedt.buf
2 a integer;
3 b varchar2(10);
4 c integer;
5 no emp.empno%type;
6 e emp%rowtype;
7 type tab_s is table of integer index by binary_integer;
8 t_s tab_s;
9 type rec_s is record
10 (subject varchar2(10),
11 score integer);
12 r_s rec_s;
13 ee exception;
14 pragma exception_init(ee,-1476);
15 begin
16 a:=0;
17 b:='Axiao';
18 if a=0 then
19 raise_application_error(-20001,'A不可以为0!');
20 end if;
21 c:=a/0;
22 select empno into no from emp where job='CLERK';
23 select * into e from emp where empno=7788;
24 t_s(3):=10;
25 t_s(5):=20;
26 r_s.subject:='语文';
27 r_s.score:=70;
28 dbms_output.put_line(a);
29 dbms_output.put_line(b);
30 dbms_output.put_line(no);
31 dbms_output.put_line(to_char(e.empno)||','||e.ename||','||e.job);
32 dbms_output.put_line(t_s(3));
33 dbms_output.put_line(t_s(5));
34 dbms_output.put_line(r_s.subject||','||to_char(r_s.score));
35 exception
36 when others then
37 dbms_output.put_line(to_char(sqlcode)||','||sqlerrm);
38* end;
SQL> /
-20001,ORA-20001: A不可以为0!
如果标题未标有<转载、转>等字则属于作者原创,欢迎转载,其版权归作者和博客园共有。
作 者:温景良
文章出处:http://wenjl520.cnblogs.com/ 或 http://www.cnblogs.com/
关注 - 32
粉丝 - 161
» 下一篇:oracle实用sql语句
【推荐】腾讯云新用户域名抢购1元起,抓紧抢购
· 精准率首次超过人类!阿里巴巴机器阅读理解打破世界纪录
· 技术帖:每天被今日头条推送文章 背后的算法技术是什么?
· 支付宝实体版老黄历问世:全球限量1000册
· 趣店被蚂蚁金服送上纽交所,现在是时候该独立了
· 蚂蚁宝卡升级:支付宝/微博即将免流
» 更多新闻...
· 以操作系统的角度述说线程与进程
· 软件测试转型之路
· 门内门外看招聘
· 大道至简,职场上做人做事做管理
» 更多知识库文章...
公告
本文转自我的程序人生博客园博客,原文链接:http://www.cnblogs.com/wenjl520/archive/2009/04/28/1445771.html,如需转载请自行联系原作者
PL/SQL语言基础相关推荐
- KingbaseES PL/SQL 过程语言参考手册(3. PL/SQL语言基础)
3. PL/SQL语言基础¶ 本章节阐述PL/SQL语言的基本组成. 字符集 词法单元 声明 对标识符的引用 标识符的作用域和可见性 为变量赋值 表达式 错误报告函数 3.1. 字符集 任何要由PL/ ...
- 【PL/SQL】PL/SQL语言基础
一.PL/SQL的块 (1)块(Block)是PL/SQL的基本程序单元 (2)一个PL/SQL应用程序由一个或多个块组成 1.PL/SQL块的基本组成 (1)定义部分(declare) --定义常量 ...
- Oracle PL/SQL语言初级教程
http://fs3.dajie.com/2010/09/20/034/12849518348824410.pdf PL/SQL语言基础 复合数据类型 单行函数和组函数 表和视图 完整性约束 过程和函 ...
- Oracle PL/SQL语言初级教程(自学)
Oracle PL/SQL语言初级教程 PL/SQL 语言基础 PL/SQL 是一种高性能的基于事务处理的语言,能运行在任何 ORACLE 环境中,支持所有数据处理命令. 通过使用 PL/SQL 程序 ...
- Oracle PL/SQL语言入门
一.背景介绍 结构化查询语言(Structured Query Language,简称SQL)是用来访问关系型数据库一种通用语言,属于第四代语言(4GL),其执行特点是非过程化,即不用指明执行的具体方 ...
- 10、oracle下PL/SQL编程基础
ORACLE下的PL/SQL编程基础 PL/SQL语言是程序化程序设计语言,块是PL/SQL编程中的基本结构,其优点在于支持SQL.支持面向对象编程.性能好.可移植性.与sql集成.安全性高等. 1. ...
- PL/SQL程序基础1
PL/SQL程序基础1 一.实验目标 1.针对数据库应用领域的数据需求,设计出基于Oracle数据库的解决方案的能力: 2.承担Oracle数据库系统的实施.运行与维护等基本工作的能力. 二.实验项目 ...
- PL/SQL语言必看书籍推荐
PL/SQL Developer是一个集成开发环境,专门开发面向Oracle数据库的应用.PL/SQL也是一种程序语言,叫做过程化SQL语言(Procedural Language/SQL).PL/S ...
- 视频教程-赵强老师:Oracle数据库从10g到11g(4)PL/SQL编程基础-Oracle
赵强老师:Oracle数据库从10g到11g(4)PL/SQL编程基础 毕业于清华大学,拥有超过13年的工作经验. Oracle认证讲师,拥有6年以上授课经验.精通Oracle数据库.中间(Weblo ...
最新文章
- LearnOpenCV学习——平均脸faceAverage.py
- 如何将OpenCV中的Mat类绑定为OpenGL中的纹理
- python【蓝桥杯vip练习题库】ADV-92求最大公约数(递归)
- 单播,组播,广播的区别
- java 递归 堆栈_Java中的堆栈安全递归
- 20000W的电灯泡,真的是叼炸天
- BZOJ 2124 等差子序列 线段树维护哈希
- concurrenthashmap为什么是线程安全_为什么SimpleDateFormat不是线程安全的?
- ajax传值给python_ajax向python脚本传递参数
- SQL 日期格式化处理.sql
- BZOJ1230 [Usaco2008 Nov]lites 开关灯
- Python批量下载XKCD漫画只需20行命令!
- 基于大数据的一线城市住房租赁影响因素分析
- Asterisk-Javanbsp;教程(中文版)…
- HNUST OJ 1997 琪露诺的完美算术教室
- 最强神作 Crysis深度剖析与优化指南
- [微服务]API 路由管理--Gateway网关
- Mac笔记本鼠标滚动方向(老忘记在哪儿记录一下吧)
- viper4android io错误,Go之Viper
- 记2020年元宵节-我又回来了