网管联盟 | 网管论坛 | 网管u家 | 网管博客 | 网管软件 | 网管求职 | 小游戏 | 网管搜索 | 网管原创 | 网管聚合 | 网管读摘 | 网管焦点 | 世界素材 | 会员投稿 | 会员中心 
中国网管联盟
Windows Linux Cisco 网络技术 数据库 黑客攻防 DotNet Java PHP 认证 新闻资讯 服务器 存储资讯 网络设备 网管学堂 技术专题 焦点 网吧频道
 当前位置: > bitsCN.com > 数据库技术 > Oracle > PL/SQL > PL/SQL collection— table() 函数-PLSQL  

PL/SQL collection— table() 函数-PLSQL

2008-07-02  作者:bitsCN整理  来源:中国网管联盟  点评 投稿 收藏

  Oracle 提供了三种集合:联合数组、嵌套表和 VARRAY 数组,但有的工具或语言并不支持 Oracle 的这种集合处理,所以有时你不得不将集合中的数据插入到真正的表中,然后再使用 SQL 查询出这些数据。对于这样的功能,你可以使用 table() 函数来实现。     table() 函数使你可以将集合封装成一个伪表,然后在 SQL 的 from 后面像一个表似的来查询,就像 from 后面可以跟一个子查询一样。下面用嵌套表举几个例子:   1. 创建测试表  
SQL> create table test_yct( id number(2), names tnt_names )
  2  nested table names store as test_yct_names;   表已创建。   SQL> insert into test_yct values(1, tnt_names('yuechaotian1', 'yuexingtian1', 'jinglitian1'));   已创建 1 行。   SQL> insert into test_yct values(2, tnt_names('yuechaotian2', 'yuexingtian2', 'jinglitian2'));   已创建 1 行。   SQL> commit;   提交完成。   SQL> col names format a60 网管bitscn_com
SQL> select * from test_yct;           ID NAMES
---------- ---------------------------------------------------------
         1 TNT_NAMES('yuechaotian1', 'yuexingtian1', 'jinglitian1')
         2 TNT_NAMES('yuechaotian2', 'yuexingtian2', 'jinglitian2')
  2. 测试   (1)为了将列 test_yct.names 中的数据返回给应用程序,你可以使用 table() 函数:  
SQL> select y.id, c.* from test_yct y, table(y.names) c;           ID COLUMN_VALUE
---------- --------------------
         1 yuechaotian1
         1 yuexingtian1 中国网管联盟bitsCN.com
         1 jinglitian1
         2 yuechaotian2
         2 yuexingtian2
         2 jinglitian2   已选择6行。   SQL> select y.id, c.* from test_yct y, table(y.names) c where y.id = 2;           ID COLUMN_VALUE
---------- --------------------
         2 yuechaotian2
         2 yuexingtian2
         2 jinglitian2
  这个结果集看起来就像是表 test_yct 与集合 table(y.names) 的左外连接一样,而事实确实如此:  
SQL> insert into test_yct(id) values(3);   已创建 1 行。   SQL> commit;   提交完成。   SQL> select y.id, c.* from test_yct y, table(y.names) c;           ID COLUMN_VALUE 网管网www.bitscn.com
---------- --------------------
         1 yuechaotian1
         1 yuexingtian1
         1 jinglitian1
         2 yuechaotian2
         2 yuexingtian2
         2 jinglitian2   已选择6行。   SQL> select y.id, c.* from test_yct y, table(y.names)(+) c;           ID COLUMN_VALUE
---------- --------------------
         1 yuechaotian1
         1 yuexingtian1
         1 jinglitian1
         2 yuechaotian2
         2 yuexingtian2
         2 jinglitian2
网管u家u.bitscn@com

           3   已选择7行。
 上一篇:PL/SQL----触发器-PLSQL   下一篇:SQL Server 2005 中的架构与用户-PLSQL
PL/SQL collection— table() 函数-PLSQL 评论:
loading.. 评论加载中…
评论:请自觉遵守互联网相关政策法规,评论不得超过250字。

验证码: 注册用户
本类热门排行:
最新推荐文章:
网管论坛交流: