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
相关文档:
SELECT g.rid, room_no, planed_count,cc from
(SELECT rid,room_no, planed_count from YC_HOTEL_ROOM_T ) r
left join
(SELECT rid,count(*) cc from YC_GUEST_INFO_T group by rid ) g
ON r.rid = g.rid WHERE planed_ ......
最近一直在用javascript在做项目
可是做着做着
感觉很多功能代码都是重复的。
比如对javascript数组的排序
还有对数组数据的删选以及分组
所以,后来兴致以上来。
一发不可收拾。
写了一个能在javascript中应用的 SQL 库
后来又想,怎么不能用javascript直接连接数据库呢?
又做了一个javascript直连Sql数据的类库 ......
1、查询两个时间之间
select * from [tablename] where date between \'value1\' and \'value2\'
2、显示最后回复时间
select a.title,a.username,b.adddate from table a,(select max(adddate) adddate from table where table.title=a.title) b
3、日程安排提前5分钟提醒
select * from 日程安排 w ......
if not object_id('Tempdb..#T') is null
drop table #T
Go
Create table #T([ID] int,[Name] nvarchar(1),[Memo] nvarchar(2))
Insert #T
select 1,N'A',N'A1' union all
select 2,N'A',N'A2' union all
select 3,N'A',N'A3' union all
select 4,N'B',N'B1' union all
select 5,N'B',N'B2'
G ......
--合并行,并返回合并的值
Create proc [dbo].[proUniteRow]
@tab varchar(30), --表名
@col varchar(30), --合并的列名
@where varchar(2000), &nbs ......