当前位置: 首页 > 编程日记 > 正文

PL SQL笔记(三)

loopif credit_rating < 3 then..exit;end if;
end loop;

select to_char(sysdate, 'YYYY-MM-DD HH24:MI:SS') from dual;
select cast(sysdate as timestamp) from dual;

复合类型数据

1.记录:

declaretypeemp_record_typeis record(r_name emp.ename%type,r_job emp.job%type);emp_record emp_record_type;
beginselect t.ename, t.job into emp_record from emp t where t.empno = '7369';dbms_output.put_line('ename = ' || emp_record.r_name || ', r_job = ' || emp_record.r_job);
end;
/ 

2.联合数组:

declaretypeemp_table_typeis table ofemp.ename%typeindex by binary_integer;emp_table emp_table_type;
beginselect ename into emp_table(0) from emp where empno = '7369';dbms_output.put_line('ename = ' || emp_table(0));
end;
/

3.嵌套表:

嵌套表和联合数组类似,但嵌套表可以作为列的数据类型使用,而联合数组不能。

create or replace type item_type as object
(t_username varchar2(20),t_password varchar2(20),t_age smallint
);
declaretype itemtable is table of item_type;v_table itemtable := itemtable();
beginv_table.extend;v_table(v_table.last) := item_type('dys', 'dys123', 10);
end;

利用嵌套表当表列数据类型:

create or replace type itemtable is table of Item_Type;
create table TestTable
(address varchar2(100),phoneNumber varchar2(11),itemList itemtable
)
nested table itemList store as itemList;

4.变长数组:
变长数组可以作为表列的数据类型或对象类型属性的数据类型,嵌套表长度没有限制,而变长数组长度有限制:

create or replace type idArray_Type as varray(100) of number;create or replace type item_type as object
(v_itemCode char(10),v_name varchar2(20)
);create or replace type itemArray as varray(10) of item_type;create table TestT
(v_id number(8),items itemArray
)

pl sql 基本结构:

declarev_id number(8) := 10;v_username varchar2(20);
begindelete from A;insert into A values(v_id, 'ding', 'ding123');select username into v_username from A where id = v_id;dbms_output.put_line('v_username = ' || v_username);exceptionwhen no_data_found thendbms_output.put_line('no data');
end;
/

常量:

declarePI constant number(9) := 3.1415926;
begincommit;
end;

变量:

declareage number(3) := 26;
begincommit;
end;

其他类型:

emp.empno%type
emp%rowtype

分支:

if ... then

if sales > 10 thencompute_bonus(empid);update payroll set pay = pay + bonus where empno = emp_id;
end if;

if .. then ... else

if trans_type = 'CR' thenupdate accounts set balance = balance + debit where ...
elseupdate accounts set balance = balance - debit wehre ...
end if;
if trans_type = 'CR' thenupdate accounts set balance = balance - debit where ...
elseif new_balance >= minimum_balance thenupdate accounts set balance = balance - debit where ...elseraise insufficient_funds;end if;
end if;

if .. then ...elsif

beginif sales > 50000 thenbonus := 1500;elsif sales > 35000 thenbonus := 500;elsebonus := 100;end if;insert into payroll values(emp_id, bonus...);
end;

case语句:

case gradewhen 'A' thendbms_output.put_line('A');when 'B' thendbms_output.put_line('B');elsedbms_output_put_line('wrong!');
end case;

搜寻式case语句:

casewhen grade = 'A' thendbms_output.put_line('A');when grade = 'B' thendbms_output.put_line('B');elsedbms_output.put_line(''wrong!);
end case;

loop

loop....
end loop;

exit(只能入到循环中,如果普通PL SQL 块要退出用return)

loopif a > 3 then...exit;end if;
end loop;

exit .. when

loopfetch c1 into ...exit  when c1%notfound;...
end loop;
close c1;

if == exit ... when

if a > 100 thenexit;
end if;-----------------------------------------------------------
exit when a > 100;

loop label(循环标签)

<<outer>>
loop...loop...exit outer when ...end loop;
end loop outer;

while ... loop

while a < 100 loop...select sal into salary from emp where x = x;...total := total + salary;
end loop;

其他用法:

loop...exit when a > 10;
end loop;
--------------------------------------------
do{
} while()
---------------------------------------------
done := false;
while not done loop....done := boolean_expression;
end loop;

for ... loop

declaretype datelist is table of date index by binary_integer;dates datelist;k constant integer := 5;
beginfor j in 1 .. 3 loopdates(j * k) := sysdate;end loop;
end;
select count(empno) into emp_count from emp;
for i in 1 .. emp_count loop...
end loop;
-----------------------------------------------------------
<<main>>
declarectr integer;
begin...for ctr in 1 .. 25 loop...if main.ctr > 10 then...end if;end loop;
end main;

for exit

for j in 1 .. 10 loopfetch cl into emp_rec;exit when cl%notfound;...
end loop;
-------------------------------------------------
<<outer>>
for i in 1 .. 5 loop...for j in 1 .. 10 loopfetch cl into emp_rec;exit outer when cl%notfound;...end loop;
end loop outer;

goto

declaredone boolean;for i in 1 .. 10 loopif done thengoto end_loop;end if;...<<end_loop>>null;end loop;
endl;
declaremy_ename char(10);
begin<<get_name>>select ename into my_ename from emp wher ...begin...goto get_name;end;
end;

null

exceptionwhen zero_divide thenrollback;when value_error theninsert into errors values...when others thennull;
if rating > 90 thencompute_bonus(emp_id);
elsenull
end if;

DCL(数据控制语句)

权限说明
create user创建其他用户(dba角色)
drop user删除其他用户
select any table查询任何用户表或视图
create any table在任何表空间中创建表
drop any table删除在任何表空间中所创建的表
create session连接数据库
create table在用户自己表空间中创建表
create view在用户自己表空间中创建视图
create sequence在用户自己的表空间中创建序列
create proceudre在用业内自己表空间中创建存储过程

授权:

grant create any table to scott;

撤销授权:

revoke create any table from scott;

保存点:

savepoint a;

execute dbms_transaction.savepoint('B');

回滚保存点:

rollback to B;

exeucte dbms_transaction.rollback_savepoint('A');

回滚全部事物:

rollback;

execute dbms_transaction.rollback;

转载于:https://www.cnblogs.com/dingyingsi/p/3246587.html

相关文章:

iOS-仿膜拜贴纸滚动(物理仿真)

导读 简单用OC写了一个小球滚动效果; 类似平衡球. GitHub地址&#xff1a;https://github.com/wangliujiayou/WLBallView 欢迎Star. 膜拜滚动进入正题-(传感器) 传感器是一种感应\检测装置, 目前已经广泛应用于智能手机上&#xff0c;用于感应\检测设备周边的信息&#xff0c;不…

Redhat、centos安装配置postgresql

一.安装postgresql 本文仅以 redhat&#xff0c;postgresql9.4为例&#xff0c;使用yum方式进行介绍。 官网&#xff1a;http://www.postgresql.org/download/linux/redhat/ 1.下载postgresql的yum源 yum install http://yum.postgresql.org/9.4/redhat/rhel-6-x86_64/pgdg-red…

Spring Cloud应用开发(七:使用Git存储方式实现分布式配置管理 )

1、使用Git存储实现管理&#xff1b; 1.1、配置Git。在Git上创建microservice-study-config目录&#xff0c;并在目录中添加开发&#xff0c;预发布和测试的配置文件&#xff1b; 1.2、修改服务端配置文件。将microservice-config-server工程的配置文件中本地文件存储方式的配…

IOS 自定义相机, 使用 AVFoundation(附实现部分腾讯水印相机功能 demo)

原文链接&#xff1a;http://www.jianshu.com/p/c64bf543f16a这是一款使用 AVFoundation 自定义的相机&#xff0c;与系统原生相机有一样的外观但比系统的相机更好、更符合实际的开发需要、可以自己修改 UI、实现拍照、取消、闪光灯控制、前后摄像头控制、聚焦、放大缩小、拍照…

如何成为一个好的测试工程师(转载,大意)

对于测试功能是的两个不同观点&#xff1a;软实力和技术能力。 个人觉得技术能力80%可以被大众掌握&#xff0c;但是软实力是需要花费很多时间去培养和塑造的。一下几点也是能够衡量个人技能的一些标准&#xff1a; 1&#xff0c;沟通技能-口头和书面能力 与人的第一印象&#…

ubuntu下7z文件的解压方法

apt-get install p7zip-full 控制台会打出以下信息&#xff1a; 正在读取软件包列表... 完成正在分析软件包的依赖关系树 正在读取状态信息... 完成 建议安装的软件包&#xff1a; p7zip-rar下列【新】软件包将被安装&#xff1a; p7zip-full升级了 0 个软件包&…

Docker的使用(一:Docker入门程序)

1、编写Dockerfile文件&#xff1b; 注&#xff1a;创建一个空的Docker工作目录dockerspace&#xff0c;进而进入该目录&#xff0c;并创建编写dockerfile文件&#xff1b; 2、编写外部文件。 注&#xff1a;在当前目录&#xff08;dockerspace&#xff09;下分别创建require…

iOS OpenCV 图像灰度处理

2017-06-21 小溪彼岸 Cocoa开发者社区推荐人&#xff1a;wo709128079 有时候开发过程中&#xff0c;切图满足不了我们的需求&#xff0c;此时我们需要对图像进行灰度处理&#xff0c;例如QQ头像在线、离线等不同状态等。 可以尝试的解决方案&#xff1a; 第一种&#xff1a;让U…

【VS开发】【电子电路技术】RJ45以太网传输线研究

RJ45以太网传输线研究 最近研究远距离差分视频传输方案&#xff0c;理所当然想到了LVDS协议。至于选用cameralink传输线&#xff0c;还是选用其他方案&#xff0c;本人更倾向于廉价的RJ45以太网线来实现LVDS差分信号的传输。 由于RJ45网线内部为4对双绞线&#xff0c;至于以太网…

Wiz开发 定时器的使用与处理

这只是一些代码片段&#xff0c;由于Wiz开发的资料实在不多&#xff0c;而且内容都不够新。这里的代码主要参考Tools.Timer这个插件&#xff0c;但是由于内部实现的很多变化&#xff0c;Tools.Timer这个插件基本上已经无法使用了。定时器的注册与删除 使用定时器&#xff0c;是…

Docker的使用(二:Docker客户端常用指令练习)

1、列出镜像&#xff1b; 2、搜索镜像&#xff1b; 3、拉取镜像&#xff1b; 4、构建镜像&#xff1b; 4.1、在Dockerfile文件所在目录构建镜像&#xff1b; 4.2、在其他目录构建镜像&#xff1b; 4.3、查看镜像是否构建成功&#xff1b; 5、删除镜像&#xff1b; 6、创建并启…

实现简书个人中心UI效果

这两天比较闲&#xff0c;简单实现了一下个人中心页面scrollView嵌套的效果&#xff0c;也就是下边这个页面,大家感受一下先&#xff1a; JSDemo2.gif 首先讲下实现思路&#xff0c;很多人看到这个界面觉得是多个scrollView嵌套实现的&#xff0c;其实苹果不推荐scrollView的嵌…

PHPCMSv9首页显示分页点击下一页跳转链接出现错误,跳转到后台的解决方案

1 引用页写为 {pc:content action"lists" catid"10" order"updatetime DESC" thumb"0" num"1" page"$_GET[page]"}{loop $data $v}....{/loop}{$pages} {/pc}2 phpcms/libs/functions/global.func.php文件 get_…

顺序查找和二分查找

{线性的顺序查找}function seqSearch(sArr: array of Integer;aCount: Integer;const index: Integer):Integer;var i: Integer;begin Result : -1; for i : 0 to aCount do if sArr[i]index then begin Result : i; Break; end;end;{对数性的二分查找}f…

Docker的使用(三:Docker Hub远程镜像管理)

1、登录 Docker Hub&#xff1b; 2、修改镜像名称&#xff1b; 3、登录认证&#xff1b; 4、推送镜像&#xff1b; 5、查看验证&#xff1b;

啊里大鱼短信发送API

https://api.alidayu.com/doc2/apiDetail?spm0.0.0.0.SEe3dm&apiId25450 转载于:https://www.cnblogs.com/shiningrise/p/5626708.html

GCD API

&#xff08;可直接复制到Xcode中查看&#xff09; /***********************************************************************************************************************************##目录##知识点&#xff1a;GCD中有2个核心概念&#xff1a;任务和队列任务&#…

查看Linux系统中某目录的大小

命令&#xff1a;du -sh 目录名来查看&#xff0c;如下 du -sh /root 命令显示结果为&#xff1a;1.2M /root 检查是否有分区使用率use&#xff05;过高&#xff0c;如发现某个分区空间接近用完&#xff0c;可以进入该分区的挂载点&#xff0c;用以下命令找出占用空间最多的文件…

Docker的使用(四:Docker Registry本地私有仓库搭建知识点总结)

任务一&#xff1a; Docker Registry本地私有仓库搭建 1、启动Docker Registry&#xff1b; 2、重命名镜像&#xff1b; 3、推送镜像&#xff1b; 4、浏览器查看验证&#xff1b; 5、文件查看验证&#xff1b; 任务二&#xff1a;Docker Registry本地私有仓库配置&#xff1b;…

iOS多线程全套:线程生命周期,多线程的四种解决方案,线程安全问题,GCD的使用,NSOperation的使用(上)

2017-07-08 remember17 Cocoa开发者社区目的 本文主要是分享iOS多线程的相关内容&#xff0c;为了更系统的讲解&#xff0c;将分为以下7个方面来展开描述。 多线程的基本概念 线程的状态与生命周期 多线程的四种解决方案&#xff1a;pthread&#xff0c;NSThread&#xff…

C基础知识小总结(十)

"如有不正确之处&#xff0c;请指出&#xff0c;谢谢" --Mood <指针和函数> 指针函数 函数指针 <最基本的使用函数指针> < 函数指针做为形参 > <字符指针> <字符数组> < 返回局部变量指针 > < 结构体指针> 指向结构体变…

支付方式(2)——支付宝集成及使用

每一个支付平台都有自己的加密、解密的原理&#xff1b;还有各种签名的原理&#xff1b;通过各种内容发送数据&#xff0c;防止恶意攻击等功能的原理。 接下来对于部署支付方式&#xff0c;首先要分清几个名词&#xff1a; 集成接入&#xff1a;支付宝已经集成好各种原理和函数…

Kali Linux攻防系统(一:攻防系统Kali Linux下载安装与更新)

任务一&#xff1a;攻防系统Kali Linux下载安装与更新 1.1、安装Kali Linux虚拟机 1.1.1、电脑硬件配置至少达到 CPU 内存 存储 >四核 >4G >20G 1.1.2、VMware Workstations版本为14及以上&#xff1b; 1.1.3、虚拟机系统版本选择Debian 8.X或者Ubuntu&#x…

iOS多线程全套:线程生命周期,多线程的四种解决方案,线程安全问题,GCD的使用,NSOperation的使用(下)

2017-07-08 remember17 Cocoa开发者社区7NSOperation的理解与使用 No.1&#xff1a;NSOperation简介 NSOperation是基于GCD之上的更高一层封装&#xff0c;NSOperation需要配合NSOperationQueue来实现多线程。 NSOperation实现多线程的步骤如下&#xff1a; 1. 创建任务&#x…

linux网卡绑定脚本

2013-08-20 15:30:51 此脚本适用于CentOS5.x和CentOS6.x。 #!/bin/bash #******************************************** # Copyright (c) Beijing DaoWoo Times Technology Co., Ltd. 2011 # # Author : Wu XuLei (wuxuleidaowoo.com) # FILE : bonding.sh …

EBS 抓trace 文件

如果要对FORM的操作做TRACE操作&#xff0c;可以使用 帮助->诊断->跟踪 中启用跟踪功能来实现。 但是如果要实现对并发请求的trace&#xff0c;需要在 系统管理员->并发->方案->定义 里找到对应的并发请求&#xff0c;并勾选”启用跟踪”项。然后提交这个并发请…

Kali Linux攻防系统(三:在Kali Linux系统中配置安全测试浏览器及系统清理备份)

任务三&#xff1a;配置安全测试浏览器及系统清理备份 3.1、汉化Firefox并安装安全插件 3.1.1、汉化Firefox浏览器&#xff0c;安装中文插件&#xff0c;并更改设置&#xff1b; 3.1.2、在浏览器附加组件管理器中查找“Web Developr”插件 3.1.3、安装添加附件组件 3.2、手动…

一篇文章学懂Shell脚本

Shell脚本,就是利用Shell的命令解释的功能&#xff0c;对一个纯文本的文件进行解析&#xff0c;然后执行这些功能&#xff0c;也可以说Shell脚本就是一系列命令的集合。 Shell可以直接使用在win/Unix/Linux上面&#xff0c;并且可以调用大量系统内部的功能来解释执行程序&#…

OC系列foundation Kit基础-NSDate

一.获取当前时间 1.1创建一个日期对象 NSDate *date [NSDate date];NSLog("%",date);输出结果&#xff1a; 2016-07-01 17:31:02.410 OCString[907:402963] 2016-07-01 09:31:02 0000 //因为时区不一样&#xff0c;需要格式化为本地时间 Program ended with exit…

sql server 中将由逗号“,”分割的一个字符串,转换为一个表,并应用与 in 条件...

select * from tablenmae where id in(1,2,3) 这样的语句和常用&#xff0c;但是如果in 后面的 1&#xff0c;2&#xff0c;3是变量怎么办呢&#xff0c;一般会用字符串连接的方式构造sql语句 string aa"1,2,3";string sqltxt"select * from tablename where id…