查询嵌套表问题,如何展开嵌套表内容?

jeff_nie 2014-03-25 11:39:29
我在PL/SQL中写入以下语句:
create or replace type test_array is table of number(7);

create table friends (
id number(7),
friend test_array
)
nested table friend
store as friend_tab;

insert into friends(id, friend) values (1, test_array(1, 2, 3, 4, 5, 6, 7))

select * from friends

我通过以上方式创建了一张表,friend 字段为一个数组,当我插入一条记录后,查询出来的结果是:
ID FRIEND
1 <Collection>
我想看到 Collection 里数组的内容,也就是想看到类似这样的结果:
ID FRIEND
1 1234567

谢谢!
...全文
226 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
jeff_nie 2014-03-25
  • 打赏
  • 举报
回复
没人回答吗?
善若止水 2014-03-25
  • 打赏
  • 举报
回复
引用 3 楼 jeff_nie 的回复:
找到了一种解决办法: select f.id, r.* from friends f, table(f.friend) r; 基本上能解决了上面的问题。
这才是 正解
流浪川 2014-03-25
  • 打赏
  • 举报
回复
引用 6 楼 zlloct 的回复:
[quote=引用 5 楼 jeff_nie 的回复:] 嗯,谢谢楼上,我后来找到了解决方法,具体用法在这:http://oracle.chinaitlab.com/PLSQL/754906.html
平时很少用嵌套表,学习了[/quote] 我也没怎么用过啊。。学习。。
CT_LXL 2014-03-25
  • 打赏
  • 举报
回复
引用 5 楼 jeff_nie 的回复:
嗯,谢谢楼上,我后来找到了解决方法,具体用法在这:http://oracle.chinaitlab.com/PLSQL/754906.html
平时很少用嵌套表,学习了
jeff_nie 2014-03-25
  • 打赏
  • 举报
回复
嗯,谢谢楼上,我后来找到了解决方法,具体用法在这:http://oracle.chinaitlab.com/PLSQL/754906.html
CT_LXL 2014-03-25
  • 打赏
  • 举报
回复
引用 2 楼 jeff_nie 的回复:
在网上看到有种方法,但还是不行。 declare fri_tab test_array; begin select friend into fri_tab from friends where id = 1; for i in 1..fri_tab.count loop dbms_output.put_line('id' || fri_tab(i)); end loop; end; 求帮助!
SELECT t1.id,t2.* FROM friends t1,TABLE(t1.friend)t2;
jeff_nie 2014-03-25
  • 打赏
  • 举报
回复
找到了一种解决办法: select f.id, r.* from friends f, table(f.friend) r; 基本上能解决了上面的问题。
jeff_nie 2014-03-25
  • 打赏
  • 举报
回复
在网上看到有种方法,但还是不行。 declare fri_tab test_array; begin select friend into fri_tab from friends where id = 1; for i in 1..fri_tab.count loop dbms_output.put_line('id' || fri_tab(i)); end loop; end; 求帮助!

17,377

社区成员

发帖
与我相关
我的任务
社区描述
Oracle 基础和管理
社区管理员
  • 基础和管理社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧