嵌套表

嵌套表是一种类似于索引表的结构,也可以用于保存多个数据,而且也可以保存复合类型的数据

嵌套表指的是一个数据表定义事同时加入了其他内部表的定义,这一概念是在oracle 8中引入的,它们可以使用SQL进行访问,也可以进行动态扩展。

创建表指定嵌套表存储空间名称

Create table 表名称(

字段名称 类型

……

嵌套表字段名称 嵌套表类型

)NESTED TABLE 嵌套表字段名称 STORE AS 存储空间名称;

定义部门表

DROP TABLE department

Create table department(

Did number,

Deptname varchar(30) not null,

Projects project_nested,

Constraint pk_did primary key(did)

)NESTED TABLE projects STORE AS projects_nested_table;

创建新的对象类型

Create type 类型名称 AS OBJECT(

列名称 数据类型,

列名称 数据类型,

……

列名称 数据类型

);

/

范例:创建一个表示项目类型的对象

Create or replace type kingsql_type as object(

Projectid number,

Projectname varchar(50),

Projectfunds number,

Pubdate date

);

/

CREATE OR REPLACE TYPE kingsql_type AS OBJECT(

projectid NUMBER ,

projectname VARCHAR(50),

projectfunds NUMBER ,

pubdate DATE

) ;

定义嵌套表类型——project_nested

CREATE OR REPLACE TYPE kingsql_nested AS TABLE OF kingsql_type NOT NULL ;

CREATE TABLE department_01 (

did NUMBER ,

deptname VARCHAR(50) NOT NULL ,

qt_column kingsql_nested

) NESTED TABLE qt_column STORE AS kingsql_nested_t1((

projectid NOT NULL ,

projectname NOT NULL ,

projectfunds NOT NULL ,

pubdate NOT NULL)) ;

嵌套表插入数据

insert into department_01 values(

1,--第一列

'hehe1',--第二列

kingsql_nested(kingsql_type(1,'hehe1',1,sysdate),kingsql_type(11,'hehe11',11,sysdate))); 第三列第一行/第三列第二行

插入数据

declare

v1 kingsql_nested:=kingsql_nested(kingsql_type(2,'haha2',2,sysdate));

begin

insert into department_01

values(1,'hehe1',kingsql_nested(kingsql_type(1,'hehe1',1,sysdate),kingsql_type(11,'hehe11',11,sysdate)));

insert into department_01 values(2,'haha2',v1);

end;

/

查询嵌套表数据

select * from the(select department_01.qt_column from department_01 where did=1);

PROJECTID PROJECTNAME     PROJECTFUNDS PUBDATE

---------- -------------------------------------------------- ------------ -------------------

1 hehe1  1  2018-05-21 14:35:32

11 hehe11 11 2018-05-21 14:35:32

select * from the(select department_01.qt_column from department_01 where did=2);

PROJECTID PROJECTNAME PROJECTFUNDS PUBDATE

---------- -------------------------------------------------- ------------ -------------------

2 haha2  2  2018-05-21 14:35:32

select * from the(select department_01.qt_column from department_01 where did=1) where projectid=1;

PROJECTID PROJECTNAME  PROJECTFUNDS PUBDATE

---------- -------------------------------------------------- ------------ -------------------

1 hehe1  1  2018-05-21 14:35:32

直接插入嵌套表数据

insert into the(select department_01.qt_column from department_01 where did=1) values(111,'hehe111',111,sysdate);

Select * from the(select department_01.qt_column from department_01 where did=1);

循环插入一百行

declare
x number:=3;
begin
for x in 3..103 loop
insert into the(select department_01.qt_column from department_01 where did=2) values(x,'hehe',111,sysdate);
end loop;
commit;
end;

直接更新嵌套表数据

update the(select department_01.qt_column from department_01 where did=1) set projectid=1111 where projectid=1;

commit;

select * from the(select department_01.qt_column from department_01 where did=1)

直接删除嵌套表数据

delete the(select department_01.qt_column from department_01 where did=1) where projectid=1111;

commit;

select * from the(select department_01.qt_column from department_01 where did=1);

DROP TABLE department_01 PURGE ; 从回收站删除

嵌套表用法详解(PLSQL)的更多相关文章

  1. 1:CSS中一些@规则的用法小结 2: @media用法详解

    第一篇文章:@用法小结 第二篇文章:@media用法 第一篇文章:@用法小结 这篇文章主要介绍了CSS中一些@规则的用法小结,是CSS入门学习中的基础知识,需要的朋友可以参考下     at-rule ...

  2. oracle数据库定时任务dbms_job的用法详解

    本文来源:Ruthless <oracle数据库定时任务dbms_job的用法详解> 一.dbms_job涉及到的知识点   1.创建job: variable jobno number; ...

  3. 【转】 #define用法详解

    #define用法详解   1.#define 的作用 在C或C++语言源程序中允许用一个标识符来表示一个字符串,称为“宏”.被定义为“宏”的标识符称为“宏名”.在编译预处理时,对程序中所有出现的“宏 ...

  4. Vue1.0用法详解

    Vue.js 不支持 IE8 及其以下版本,因为 Vue.js 使用了 IE8 不能实现的 ECMAScript 5 特性. 开发环境部署 可参考使用 vue+webpack. 基本用法 1 2 3 ...

  5. C#中string.format用法详解

    C#中string.format用法详解 本文实例总结了C#中string.format用法.分享给大家供大家参考.具体分析如下: String.Format 方法的几种定义: String.Form ...

  6. mysql中event的用法详解

    一.基本概念mysql5.1版本开始引进event概念.event既“时间触发器”,与triggers的事件触发不同,event类似与linux crontab计划任务,用于时间触发.通过单独或调用存 ...

  7. CSS中伪类及伪元素用法详解

    CSS中伪类及伪元素用法详解   伪类的分类及作用: 注:该表引自W3School教程 伪元素的分类及作用: 接下来让博主通过一些生动的实例(之前的作业或小作品)来说明几种常用伪类的用法和效果,其他的 ...

  8. jQuery 事件用法详解

    jQuery 事件用法详解 目录 简介 实现原理 事件操作 绑定事件 解除事件 触发事件 事件委托 事件操作进阶 阻止默认事件 阻止事件传播 阻止事件向后执行 命名空间 自定义事件 事件队列 jque ...

  9. SVN组成中trunk,branches and tags功能用法详解

    SVN组成中trunk,branches and tags功能用法详解  我相信初学开发在SVN作为版本管理时,都估计没可能考虑到如何灵活的运用SVN来管理开发代码的版本,下面我就摘录一篇文章来简单说 ...

随机推荐

  1. SAP Study Notes: BW Queriy-Variables(变量)

    About Variable:1.Variable 是和InfoObject绑定的,可用于任何含有该IO的query中.2.Variable有以下几种类型:Characteristic:用于限制Cha ...

  2. Oracle的NVL函数用法

    从两个表达式返回一个非 null 值. 语法 NVL(eExpression1, eExpression2) 参数eExpression1, eExpression2 如果 eExpression1 ...

  3. (转载)完成端口(Completion Port, I/OCP)详解

    http://www.cnblogs.com/lancidie/archive/2011/12/19/2293773.html 手把手叫你玩转网络编程系列之三    完成端口(Completion P ...

  4. Java知多少(60)isAlive()和join()的使用

    如前所述,通常你希望主线程最后结束.在前面的例子中,这点是通过在main()中调用sleep()来实现的,经过足够长时间的延迟以确保所有子线程都先于主线程结束.然而,这不是一个令人满意的解决方法,它也 ...

  5. An SPI class of type org.apache.lucene.codecs.PostingsFormat with name 'Lucene50' does not exist. You need to add the corresponding JAR file supporting this SPI to your classpath. The current classp

    背景介绍: 当ES中guava库与hive等组件的库冲突时,对Elasticsearch库进行shade,relocate解决库冲突问题. 当使用"org.apache.maven.plug ...

  6. 牛客网_Go语言相关练习_判断&选择题(5)

    一.判断题 defer应该在if后面,如果文件为空,close会崩溃. package main import ( "os" "fmt" ) func main ...

  7. Scala学习笔记——样本类和模式匹配

    1.样本类 在申明的类前面加上一个case修饰符,带有这种修饰符的类被称为样本类(case class). 被申明为样本类的类的特点:1.会添加和类名一致的工厂方法:2.样本类参数列表中的所有参数隐式 ...

  8. Centos7 防火墙常用配置及说明

    一. Centos7和Centos6 防火墙的区别: 使用的工具不一样了.Centos6 使用的是iptables ,Centos7 使用的是filewall iptables 用于过滤数据包,属于网 ...

  9. Mac 环境 Vue 开发 CPU 占用率高 问题

    Mac开发Vue应用时,发现CPU风扇转的老高. htop查看一下: 问题找到了,就是这个dev-server.js,node起的进程. 然后就是 dtruss -p 1230(进程ID) 命名跟踪一 ...

  10. 给hmailserver添加DKIM签名

    上一篇说了hmailserver如何设置反垃圾邮件功能,现在来说说如何让自己的hmailserver发出去的邮件不要被别人反垃圾了.在hmailserver的反垃圾邮件功能中有提到给垃圾评分标准,其中 ...