oracle开发学习篇之集合运算符以及集合异常捕获
--取出集合;长度
declare
type list_nested is table of varchar2(50) not null;
v_all list_nested := list_nested('a','b','c','d','c','d');
begin
dbms_output.put_line('list leng :' || cardinality(v_all));
end;
/ --从集合中取出取消重复的元素
declare
type list_nested is table of varchar2(50) not null;
v_all list_nested := list_nested('a','b','c','d','c','d');
begin
dbms_output.put_line('list leng :' || cardinality((set(v_all))));
end;
/ --判断集合是否为空
declare
type list_nested is table of varchar2(50) not null;
v_allA list_nested := list_nested('shanghai','beijing','changan');
v_allB list_nested := list_nested('shanghai');
begin
if v_allA is not empty then
dbms_output.put_line('v_allA not null!');
end if;
if v_allB is empty then
dbms_output.put_line('v_allB is null!');
else
dbms_output.put_line('v_allB not null!!');
end if;
end;
/ --判断字符是否存在
declare
type list_nested is table of varchar2(50) not null;
v_allA list_nested := list_nested('shanghai','beijing','changan');
v_allB list_nested := list_nested('shanghai');
v_str varchar2(20) := 'shanghai';
begin
if v_str member of v_allA then
dbms_output.put_line('shanghai value is exists');
end if;
end;
/( --使用for循环遍历集合的每一个元素; 取出list中交集
declare
type list_nested is table of varchar2(50) not null;
v_allA list_nested := list_nested('shanghai','beijing','hunan');
v_allB list_nested := list_nested('Java','beijing','tianjing');
v_newlist list_nested ;
BEGIN
v_newlist := v_allA multiset except v_allB;
for x in 1 .. v_newlist.count loop
dbms_output.put_line(v_newlist(x));
end loop;
end;
/ --使用for循环遍历集合的每一个元素; 取出集合中所有的元素
declare
type list_nested is table of varchar2(50) not null;
v_allA list_nested := list_nested('shanghai','beijing','hunan');
v_allB list_nested := list_nested('Java','beijing','tianjing');
v_newlist list_nested ;
BEGIN
v_newlist := v_allA multiset union v_allB;
for x in 1 .. v_newlist.count loop
dbms_output.put_line(v_newlist(x));
end loop;
end;
/ 判断集合是否为集合
declare
type list_nested is table of varchar2(50) not null;
v_allA list_nested := list_nested('shanghai','beijing','Java');
begin
if v_allA is A set then
dbms_output.put_line('v_allA is list');
end if;
end;
/ declare
type list_nested is table of varchar2(50) not null;
v_allA varchar2(20) := 'a';
begin
if v_allA is A set then
dbms_output.put_line('v_allA is list');
end if;
end;
/ --判断B是否为A的子集合
declare
type list_nested is table of varchar2(50) not null;
v_allA list_nested := list_nested('shanghai','beijing','hunan','Java');
v_allB list_nested := list_nested('Java','beijing');
BEGIN
if v_allB submultiset v_allA then
dbms_output.put_line('v_allB is v_allA submultiset');
end if;
end;
/
--集合的异常处理;
--理解集合异常的缠身及处理操作; 所有异常捕获都能够使用others进行捕获; DECLARE
type list_varray is varray(8) of varchar2(50);
v_info list_varray; --此时的集合变量没有初始化
BEGIN
v_info(0) := 10; --此集合未初始化,所以会存在错误,
exception
when collection_is_null then
dbms_output.put_line('The error collection is not initialized');
END;
/ DECLARE
type list_varray is varray(8) of varchar2(50);
v_info list_varray := list_varray('shanghai','changan','facebook');
BEGIN
dbms_output.put_line(v_info(5));
exception
when subscript_beyond_count then
dbms_output.put_line('索引值超过定义的元素个数!!');
end;
/ DECLARE
type list_varray is varray(8) of varchar2(50);
v_info list_varray := list_varray('shanghai','changan','facebook');
BEGIN
dbms_output.put_line(v_info(''));
dbms_output.put_line(v_info('a'));
exception
when value_error then
dbms_output.put_line('索引值类型错误');
end;
/ declare
type info_index is table of varchar2(100) index by PLS_INTEGER;
v_info info_index;
begin
v_info(1) := 'fireof';
v_info(2) := 'firefox.com';
v_info(3) := 'www.firefox.com';
v_info.delete(1);
dbms_output.put_line(v_info(1));
dbms_output.put_line(v_info(2));
dbms_output.put_line(v_info(3));
exception
when no_data_found then
dbms_output.put_line('data not found !!!');
end;
/
oracle开发学习篇之集合运算符以及集合异常捕获的更多相关文章
- oracle开发学习篇之集合函数
集合函数; declare type list_nested ) not null; v_all list_nested := list_nested('changan','hubei','shang ...
- Oracle 多表查询、查询运算符和集合运算
一.多表查询 1.内连接 一般使用INNER JOIN关键字指定内连接,INNER可以省略,默认表示内连接.查询结果中只包含两表的公共字段值相等的行,列可以是两表中的任意列 2.外连接 包括左外连接. ...
- [adb 学习篇] python将adb命令集合到一个工具上
https://testerhome.com/topics/6938 qzhi的更全面,不过意思是一样的,另外补充一个开源的https://github.com/264768502/adb_wrapp ...
- Oracle DBA学习篇之SQL_TRACE
SQL_TRACE ; ; set serveroutput on; alter session set sql_trace=true; select count(*) from firefox; a ...
- ASP.NET Core Web开发学习笔记-1介绍篇
ASP.NET Core Web开发学习笔记-1介绍篇 给大家说声报歉,从2012年个人情感破裂的那一天,本人的51CTO,CnBlogs,Csdn,QQ,Weboo就再也没有更新过.踏实的生活(曾辞 ...
- Unity 3D游戏开发学习路线(方法篇)
Unity 3D本来是由德国的一些苹果粉丝开发的一款游戏引擎,一直只能用于Mac平台,所以一直不被业外人士所知晓.但是后来也推出了2.5版,同时发布了PC版本,并将其发布方向拓展到手持移动设备.Uni ...
- iOS开发Swift篇—(四)运算符
iOS开发Swift篇—(四)运算符 一.运算符 1.Swift所支持的部分运算符有以下一些 赋值运算符:= 复合赋值运算符:+=.-= 算术运算符:+.-.*./ 求余运算符:% 自增.自减运算符: ...
- 李洪强iOS开发Swift篇—04_运算符
李洪强iOS开发Swift篇—04_运算符 一.运算符 1.Swift所支持的部分运算符有以下一些 赋值运算符:= 复合赋值运算符:+=.-= 算术运算符:+.-.*./ 求余运算符:% 自增.自减运 ...
- 跟Google学习Android开发-起始篇-构建你的第一个应用程序(4)
说明:此系列教程翻译自Google Android开发者官网的Training教程,利用Chome浏览器的自动翻译功能作初译,然后在一些语句不顺或容易造成误解的地方作局部修正.方便英文不好的开发者查看 ...
随机推荐
- qt使用动态库(DLL)
本文主要讲解在QT开发环境中如何使用VC生成的DLL及QT自身生成的DLL.至于其它情况本文不作讨论. 连接库分为2种 (1)动态连接库,通常有.h .lib .dll三个文件,功能实现在dll中 ( ...
- 08 Packages 包
Packages Standard library Other packages Sub-repositories Community Standard library Name Synopsis ...
- 组合比较符(PHP7+)
php7+支持组合比较符,即<=>,英文叫做combined comparison operator,组合比较运算符可以轻松实现两个变量的比较,当然不仅限于数值类数据的比较. 语法:$a& ...
- python中set
集合update方法:是把要传入的元素拆分,做为个体传入到集合中,例如: >>> a = set('boy') >>> a.update('python') > ...
- 2018JAVA复习摘要
由于公司内部原因,2018年感觉自己可能会换个新环境:虽然时间尚未确定,但还是得提前做好防范,毕竟面试复习是需要时间好好准备才能拿到自己理想的offer.打算从清明节之后开始好复习基本知识要点,先整理 ...
- html meta标签使用总结(转)
之前学习前端中,对meta标签的了解仅仅只是这一句. <meta charset="UTF-8"> 但是打开任意的网站,其head标签内都有一列的meta标签.比如我博 ...
- mysql 通过sqoop导入hive
sudo -u hdfs sqoop import --connect jdbc:mysql://192.168.33.93:3306/leochentest --username root --pa ...
- day1作业:编写登录窗口一个文件实现
思路: 1.参考模型,这个作业我参考了linux的登录认证流程以及结合网上银行支付宝等锁定规则: 1)认证流程参考的是Linux的登录:当你输入完用户名密码后再验证用户名是否存在用户是否被锁定,然后在 ...
- PHP 统计数据合并
将不同的统计结果整合在一起,如图,根据年级统计出不同成绩段人数(此处只为举例),然后写了一个方法来处理这些统计数组 <?php /** * 合并统计数据 * @param $key_column ...
- JSP的学习二(指令与标签)
一:page指令 1.JSP的指令 放在<%@ 指令 属性=“值”%> 主要有page,include,tablib. 2.page指令 用于定义JSP页面的各种属性,作用于是JSP的整个 ...