plsql与tsql的语法不同
来源:asp之家 发布时间:2009-09-13 17:33:00
insert into testtable(recordnumber,currentdate) values (i,sysdate);
print ‘';
select @i=@i+1;
end;
比较一下就可以看出来到底那里不一样了
plsql里面命令的结构为
delacre
定义语句段
begin
执行语句段
exception
异常处理语句段
end
这就是plsql程序总体结构图
定义变量与mssql的不同
基本方法
变量名 类型标识符【notnull】:=值
例 age number(8):=26
多了定义复合数据类型变量的功能
1.多了%type 变量
declare
mydate user。testtable.currentdate%type;
还有 %rowtype类型的变量可以识变量获得字段的数据类型,使用%rowtype可以识变量获得整个记录的数据类型。
变量名 数据表.列名%type
变量名 数据表%rowtype
declare
mytable testtbale%rowtype 包含了testtable 所有字段 只不过在输出时候可以选择输出那个
begin
shelect * into mytable
from temuuser.tedttbale
where recordnumber=88
dbms_output.put_line(mytable.currentdate);
end;
还有就是有了定义符合变量
格式
type 复合变量名 is record(
变量 类型, 可以有好几个);
变量名 复合变量名 这个变量名就好像java中类的对象一样而复合变量名就是类名可以这样理解 个人观点
begin
select * into 变量名 from 表名 where 条件
dbms_output.put_line(变量名.表中的值)
end
另外还可以定义一维数组
type 表类型 is table of 类型 index by binary_integer
表变量名 表类型
index by binary_integer子句代表以符号整数为索引,
这样访问表类型变量中的数据方法就是“表变量名(索引符号整数)”
Declare
type tabletype1 is table of varchar2(4) index by binary_integer;
type tabletype2 is table of tempuser.testtable.recordnumber%type index by
binary_integer;
table1 tabletype1;
table2 tabletype2;
begin
table1(1):='大学';
table1(2):='大专';
table2(1):=88;
table2(2):=55;
dbms_output.put_line(table1(1)||table2(1));
dbms_output.put_line(table1(2)||table2(2));
end;
一个标准的一维数组
定义多维表类型变量
定义了名为 tabletype1 的多维表类型,相当于多维数组,table1 是多维表类型变量,将数据表 tempuser.testtable 中
recordnumber为 60 的记录提取出来存放在 table1 中并显示。
type tabletype1 is table of testtable%rowtype index by binary_integer;
table1 tabletype1;
begin
select * into table1(60)
from tempuser.testtable
where recordnumber=60;
dbms_output.put_line(table1(60).recordnumber||table1(60).currentdate);
end;
在来看下面的这个程序
set serveroutput on
Declare
result integer;
begin
result:=10+3*4-20+5**2;
dbms_output.put_line('运算结果是:'||to_char(result));
end;
|| 这个符号是连接语句
to_char(result) dbms_output.put_line函数输出只能是字符串,因此利用 to_char函数将数值型结果转换为字符型。
To_char:将其他类型数据转换为字符型。 To_date:将其他类型数据转换为日期型。 To_number:将其他类型数据转换为数值型。
再说下plsql中的控制语句组合有哪几种
1. if..then..end if条件控制
if 条件 then
语句段;
end if;
2. if..then..else..end if条件控制
if 条件 then
语句段1;
else
语句段2;
end if;
3. if 嵌套条件控制
if 条件1 then
if 条件2 then
语句段1;
else
语句段2;
end if;
else
语句段3;
end if;
4.loop..exit..end loop 循环控制
loop
循环语句段;
if 条件语句 then
exit;
else
退出循环的处理语句段
end if;
end loop;
5. loop..exit..when..end loop 循环控制
采用 loop..exit..when..end loop 循环控制的语法结构与loop..exit..end loop 循环控制类似
exit when 实际上就相当于
if 条件 then
exit;
end if;
6.while..loop..end loop 循环控制
while 条件 loop
执行语句段
end loop;
7.for..in..loop..end 循环控制
for 循环变量 in [reverse] 循环下界..循环上界 loop
循环处理语句段;
end loop;
最后一个出个例子
set serveroutput on
declare
number1 integer:=80;
number2 integer:=90;
i integer:=0;
begin
for i in 1..10 loop
number1:=number1+1; 在mssql里是 sclect @number=@number+1
end loop;
dbms_output.put_line('number1的值:'||to_char(number1));
end;
猜你喜欢
- 经过了上个星期的努力学习,对处理html又有了新的发现感觉真的很不错可以说js的威力在处理html代码方面我又有所领悟了1、截取特定长度字符
- 最近参与了将一个Sybase数据库移植到Microsoft SQL Server 2000上的项目,我在这一项目上获得的经验,将对Sybas
- XML同HTML一样,都来自Standard Generalized Markup Language, 即标准通用标记语言,简称SGML。早
- 本周的豆知识分享就来深入研究一下window.event对象。请先看看下边的代码片断。 <button id=”btn”&g
- 于是写测试程序。。。不行 下载最新的ODBC。。。还是不行 通过sql plus查询。。。咦?竟然也查不到。。。 于是,折腾。。。折腾。。。
- 最好也是最简单的办法就是利用Cookie,而不必用到数据库。当然,你愿意用数据库也可以。下面就是利用Cookie来实现的:< 
- 在ASP.net页面中,我们编写JavaScript脚本附加有注释时,这些注释也往往会随JavaScript脚本一起送到客户端。
- 注释:在大多数的情况下,修改MySQL是需要有mysql里的root权限的,所以一般用户无法更改密码,除非请求管理员。方法1使用phpmya
- MySQL由于它本身的小巧和操作的高效, 在数据库应用中越来越多的被采用.我在开发一个P2P应用的时候曾经使用MySQL来保存P2P节点,由
- 最近在D4得到一本(美) Penny Mcintire写的《Visual Design for the Modern Web》.突然觉得可用
- 内容摘要:本文介绍了使用asp来JMail v4.3发信的大部分常用方法,包括邮件基本信息、身份验证、附件等。无需很多的修改就可以
- SQL Server定位于中型的数据库应用,操作较Oracle和MySQL等要相对简便,SQL Server在处理海量数据的效率,后台开发的
- 如何用METADATA替换ADOVBS.INC? 在ASP中,使用组件时,如ADO,得先包含
- 上一课:ACCESS入门教程:窗口和菜单的使用向导简介 这一课我们要建立一个客户订单管理数据库,这个数据库将用ACCESS提供的数据库向导来
- 今天同事 明城 在项目中碰到一个 BUG,代码具体如下:<!DOCTYPE html PUBLIC "-//W3C//DTD
- 在XHTML中定义ID、CLASS都用得上,主要是方面CSS定义样式时能一眼看穿。所以,CSS命名仅作参考。(1)页面结构类容器: cont
- [参与测试的浏览器:IE6 / IE7 / IE8 / FF3 / OP10 / SF4 / Chrome2 ][操作系统:Windows]
- URL 编码是什么东东呢?看看我从网上抄的定义: 引用: url编码是一种浏览器用来打包
- 由于javascript是一种无类型语言,所以一个数组的元素可以具有任意的数据类型,同一个数组的不同元素可以具有不同的类型,数组的元素设置可
- PL/SQL是ORACLE对标准数据库语言的扩展,ORACLE公司已经将PL/SQL整合到ORACLE 服务器和其他工具中了,近几年中更多的