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;


猜你喜欢
- javascript中给数组加元素是一个非常简单的问题,javascript本身就提供了大量这类函数,我们可以使用js自带函数快速给数组增加
- 本文实例总结了常用SQL语句优化技巧。分享给大家供大家参考,具体如下:除了建立索引之外,保持良好的SQL语句编写习惯将会降低SQL性能问题发
- 常用的module是 os ,os.path 和shutil,所以要先引入他们. python遍历文件夹和文件
- 导言在上两节教程中,我们看到了如何使用TemplateField来自定义GridView和DetailsView的输入。TemplateFi
- 本文实例为大家分享了python+logging+yaml实现日志分割的具体代码,供大家参考,具体内容如下1、建立log.yaml文件ver
- MySQL 是完全网络化的跨平台关系型数据库系统,同时是具有客户机/服务器体系结构的分布式数据库管理系统。MySQL 是完全网络化
- 大家好,都说追女孩方法大于态度,学Python也是,今天就给大家分享的是我在用Python编写程序时常用的一些小技巧。1.多次打印同一个字符
- 写一个学生管理系统,最好用python。我都没学过python呢,只好开始临时抱佛脚,再到网上找找有没有例子看看,下面是我参照另一个博主写的
- 通过设置Keras的Tensorflow后端的全局变量达到。import osimport tensorflow as tfimport k
- pip search报错在用pip查包名时搜到的都是:pip search xxx。但这样是报错的:查找发现pip search由于一些bu
- 定义本地站点在Dreamweaver中制作网站,您必须定义一个本地站点,它是您的计算机上任意位置的一个
- 要使用多个定界符拆分字符串:使用 re.split() 方法,例如 re.split(r',|-', my_str)。re.
- 目录前言什么是 VueUse简单上手还有我们熟悉的 防抖 和 节流还还有全局状态共享的函数更多前言上次在看前端早早聊大会中, 尤大大再一次提
- 在使用python做大数据和机器学习处理过程中,首先需要读取hdfs数据,对于常用格式数据一般比较容易读取,parquet略微特殊。从hdf
- 本文实例为大家分享了PHP实现简易计算器的具体代码,供大家参考,具体内容如下老规矩,先上GIF动态图,看个效果,如果符合你的项目或者确定你要
- 环境python3,开发平台pycharm,使用urllib时,当url中存在中文时会出现以下错误:UnicodeEncodeError:
- 导言Python官方文档对于内置函数的介绍较为简略,但这些内置函数在日常工作中却扮演着不可或缺的角色。为了更加便捷地使用和查阅这些函数,笔者
- 1、随机生成0-1的浮点数random.randomrandom.random()用于生成一个0到1的随机浮点数: 0 <= n &l
- # -*- encoding: utf8 -*-import osimport sysimport ftplibclass FTPSync(
- Python写入Excel有时需要合并单元格、或者改变文字内容的颜色首先导入xlwt模块import xlwt创建文件名创建Excel工作簿