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浏览器的自动翻译功能作初译,然后在一些语句不顺或容易造成误解的地方作局部修正.方便英文不好的开发者查看 ...
随机推荐
- Flask:初次使用Flask-SQLAlchemy读取SQLite3
Windows 10家庭中文版,Python 3.6.4,Flask 1.0.2,Eclipse Oxygen.1a Release (4.7.1a),PyDev 6.3.2 SQLAlchemy是一 ...
- java基础50 配置文件类(Properties)
1. 配置文件类Properties的概念 主要生产配置文件与读取配置文件的信息 2.Properties要注意的细节 1.如果配置文件一旦使用了中文,那么在使用store方法生产的配置文件额时候字符 ...
- ThinkPHP递归删除栏目
ThinkPHP递归删除栏目 https://www.cnblogs.com/zlnevsto/p/7051875.html Thinkphp3.2 无限级分类删除,单个删除,批量删除 https:/ ...
- sql newid()随机函数
从A表随机取2条记录,用SELECT TOP 10 * FROM ywle order by newid()order by 一般是根据某一字段排序,newid()的返回值 是uniqueidenti ...
- SQL Server 管理常用的SQL和T-SQL
1. 查看数据库的版本 select @@version 常见的几种SQL SERVER打补丁后的版本号: 8.00.194 Microsoft SQL Server 2000 8.00.384 Mi ...
- Struts 2 - Hello World Example
As you learnt from the Struts 2 architecture, when you click on a hyperlink or submit an HTML form i ...
- 一步一步学习IdentityServer4 (2) 开始一个简单的事例
前面将来一些配置,但是很多都不是必要的,先放一些事例需要的简要配置把 既然是IdentityServer4 所里下面的例子我 直接放到 Linux上 测试环境 CentOS 7 +Nginx1.9.3 ...
- 实时流计算、Spark Streaming、Kafka、Redis、Exactly-once、实时去重
http://lxw1234.com/archives/2018/02/901.htm
- Bootstrap--响应式图片轮播
<div class="row"> <div class="span12"> <section id="carousel ...
- 8-2 Party Games uva1610 (贪心)
题意: 给出n个串(n为偶数): 要构造一个串,使n串中有一半小于等于它,另外一半大于它: 要求这个串长度尽量小,同时字典序小: 一开始我的优先级是放左 其实优先级是放左加一. 如 AAAA AA ...