PL/SQL语言简介
一、 PL/SQL语言简介
(本讲义之所有程序均调式通过)
首先我们看一个简单之例子,下面这个例子是统计从1至100的总和.
declare
i number:=0; /*声明变量井给初值*/
t number:=1;
error_message exception; /*声明一个出错处理*/
begin
for t in 1..100 loop
i:=i+t;
end loop;
if i>=5050 then
raise error_message; /*引发错误处理*/
else
insert into c_nt(c_t) values(i);
end if;
exception
when error_message then
insert into c_nt(c_t) values(0);
end;
² 从上例中可以看出PL/SQL语法的一般规则.
PL/SQL中语句以分号(;)结尾.
开始程序块的PL/SQL语句(如IF…或BEGIN语句)没有分句.
文本值括在单引号(‘ ‘)内,而不是(“ “).
过程只允许最后有一个出口..
² PL/SQL程序可以分为三个部分
DECLARE部分用于变量、常量、函数、过程、Cursor.
BEGIN部分包含PL/SQL块中要执行的代码 用于程序处理,其中可以调用函数、过程.
Exception 部分用于出错处理.
下面我们再看一个例子:
declare
i number :=1;
t number :=1;
p number :=1;
/*create table c_ny(c_t number,cou_t number);*/
function aa(xx number)return number is /* define function*/
tt number;
ct number:=1;
j number:=1;
begin
while
相关文档:
INSERT INTO
tableName ( columnName1, columnName2, columnName3, columnName4)
VALUES ( '45', '西藏办', TO_Date( '2010-03-10 12:00:00', 'YYYY-MM-DD HH24:MI:SS'), NULL,);
commit; ......
Student(S#,Sname,Sage,Ssex) 学生表
Course(C#,Cname,T#) 课程表
SC(S#,C#,score) 成绩表
Teacher(T#,Tname) 教师表
问题:
1、查询“001”课程比“002”课程成绩高的所有学生的学号;
select a.S# from (select s#,score from SC where C#='001') a,(select s#,score
fr ......
-----------------------------------------------------------------------------------------------------------------------
create table tb(id varchar(3) , pid varchar(3) , name varchar(10))
insert into tb values('001' , null , '广东省')
insert into tb values('002' , '001' , '广州市')
insert i ......
2010-05-05 13:35:52.06 Server Microsoft SQL Server 2005 - 9.00.1399.06 (Intel X86)
Oct 14 2005 00:33:37
Copyright (c) 1988-2005 Microsoft Corporation
Developer Edition on Windows NT 5.1 (Build 2600: Service Pack 3)
2010-05-05 13:35:52.06 Server (c) 2005 Microsoft Corporation.
201 ......