惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

P
Privacy & Cybersecurity Law Blog
V
V2EX
月光博客
月光博客
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
The Register - Security
The Register - Security
MongoDB | Blog
MongoDB | Blog
P
Privacy International News Feed
The Last Watchdog
The Last Watchdog
Security Archives - TechRepublic
Security Archives - TechRepublic
美团技术团队
Stack Overflow Blog
Stack Overflow Blog
博客园 - 司徒正美
博客园 - 三生石上(FineUI控件)
V
Visual Studio Blog
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
K
Kaspersky official blog
S
Secure Thoughts
T
Tenable Blog
Security Latest
Security Latest
The Cloudflare Blog
S
Security @ Cisco Blogs
H
Heimdal Security Blog
aimingoo的专栏
aimingoo的专栏
TaoSecurity Blog
TaoSecurity Blog
Blog — PlanetScale
Blog — PlanetScale
Microsoft Security Blog
Microsoft Security Blog
Schneier on Security
Schneier on Security
Webroot Blog
Webroot Blog
G
Google Developers Blog
www.infosecurity-magazine.com
www.infosecurity-magazine.com
Scott Helme
Scott Helme
IT之家
IT之家
Latest news
Latest news
The Hacker News
The Hacker News
C
Check Point Blog
T
The Exploit Database - CXSecurity.com
H
Hackread – Cybersecurity News, Data Breaches, AI and More
腾讯CDC
C
CERT Recently Published Vulnerability Notes
NISL@THU
NISL@THU
N
News | PayPal Newsroom
Forbes - Security
Forbes - Security
P
Palo Alto Networks Blog
S
Security Affairs
S
Securelist
Google Online Security Blog
Google Online Security Blog
WordPress大学
WordPress大学
Last Week in AI
Last Week in AI
C
Cybersecurity and Infrastructure Security Agency CISA
A
About on SuperTechFans

博客园 - 逐风者

使用自定义控件的方式实现一个分页控件 在Word 中编辑文档的时候 有时鼠标点击无响应 无法在 COM+ 目录中安装和配置程序集 microsoft.sqlserver.notificationservices.dll [转]关于模态窗口(showModalDialog)的专题讨论! 访问被拒绝:“Interop.Word” [转]oracle临时表相关知识 ASP.NET 未被授权访问所请求的资源。请考虑授予 ASP.NET 请求标识访问此资源的权限。 [转]SQL Server中获得EXEC后面的sql语句或者存储过程的返回值的方法 [转]asp.net中常用的一些小技巧 [转]Oracle中over函数的使用示例 使用OWC生成饼状图和柱状图 Testing SOAP Headers with a Simple Axis Handler 在GetVaryByCustomString方法中使用Session logmnr的简单使用。 Oracle DBA 试题及答案 编写高性能C#代码! dotNet错误集! Oracle错误集! [转]Oracle PL/SQL中如何使用%TYPE和%ROWTYPE
在Oracle的函数中,返回表类型
逐风者 · 2009-05-26 · via 博客园 - 逐风者

在SQL Server中有表变量,可以在function中方便地返回,习惯SQL Server或者需要把脚本从SQL Server转到Oracle中的朋友可以都会碰到这个问题.

Oracle的function中怎么返回表变量?

太晚了,过多的理论知识就不说了,下面简单地说实现吧!..

1、创建表对象类型。

在Oracle中想要返回表对象,必须自定义一个表类型,如下所示:

create or replace type t_table is table of number;

上面的类型定义好后,在function使用可用返回一列的表,如果需要多列的话,需要先定义一个对象类型。然后把对象类型替换上面语句中的number;

定义对象类型:

create or replace type obj_table as object
(
  id 
int,
  name 
varchar2(50)
)

修改表对象类型的定义语句如下:

create or replace type t_table is table of obj_table;

2、 创建演示函数

在函数的定义中,可以使用管道化表函数和普通的方式,下面提供两种使用方式的代码:

1)、管道化表函数方式:

create or replace function f_pipe(s number)
return t_table pipelined
as
    v_obj_table obj_table;   
begin    
for i in 1..s loop 
    v_obj_table :
=  obj_table(i,to_char(i*i));
    
pipe   row(v_obj_table);   
end loop;
return;
end f_pipe;

注意:管道的方式必须使用空的return表示结束.

调用函数的方式如下:

select * from table(f_pipe(5));

2)、 普通的方式:

create or replace function f_normal(s number)
return t_table
as
    rs t_table:
= t_table();
begin
    
for i in 1..s loop
        rs.extend;
        rs(rs.
count) := obj_table(rs.count,'name'||to_char(rs.count));
        
--rs(rs.count).name := rs(rs.count).name || 'xxxx';
    end loop;
return rs;
end f_normal;

初始化值后还可以想注视行那样进行修改.

调用方式如下:

select * from table(f_normal(5));

OK, The End...