ORACLE 11g 中的表值函数? (参数化视图)
我过去见过有关此问题的讨论,例如 这里。但我想知道是否在某个地方,也许是 10g 或 11g(我们正在使用 11g),ORACLE 引入了对“参数化视图”的更好支持,而不需要在数据库中乱扔各种用户定义的类型和/或游标定义或 sys_context 变量。
我希望 ORACLE 添加了对简单“正常工作”的支持,如 T-SQL 中的以下示例:
CREATE FUNCTION [dbo].[getSomeData] (@PRODID ROWID)
RETURNS TABLE AS
RETURN SELECT PRODID, A, B, C, D, E
FROM MY_TABLE
WHERE PRODID = @PRODID
然后按如下方式选择它:
SELECT * FROM dbo.getSomeData(23)
I've seen discussions about this in the past, such as here. But I'm wondering if somewhere along the line, maybe 10g or 11g (we are using 11g), ORACLE has introduced any better support for "parameterized views", without needing to litter the database with all sorts of user-defined types and/or cursor definitions or sys_context variables all over.
I'm hoping maybe ORACLE's added support for something that simply "just works", as per the following example in T-SQL:
CREATE FUNCTION [dbo].[getSomeData] (@PRODID ROWID)
RETURNS TABLE AS
RETURN SELECT PRODID, A, B, C, D, E
FROM MY_TABLE
WHERE PRODID = @PRODID
Then just selecting it as so:
SELECT * FROM dbo.getSomeData(23)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
不需要 SYS_CONTEXT 或游标定义。
您确实需要一个类型,以便在解析 SQL 时确定要返回哪些列。
也就是说,您可以轻松编写一个脚本,根据 user_tab_columns 中的数据为一个或多个表生成类型和集合类型定义。
最接近的是
No need for SYS_CONTEXT or cursor definitions.
You do need a type so that, when the SQL is parsed, it can determine which columns are going to be returned.
That said, you can easily write a script that will generate type and collection type definitions for one or more tables based on the data in user_tab_columns.
The closest is
可以在 Oracle 中定义一种“参数化”视图。
步骤是:
要使用此机制,用户应该:
备注:用户必须在一个会话中完成所有三个步骤,因为包成员范围恰好是一个会话。
It is possible to define a kind of "parametrized" views in Oracle.
The steps are:
To use this mechanism one user should:
SELECT
data from the view,REMARK: it is essential for the user to do all the three steps in only one session as the package members scope is exactly a session.
SQL SERVER 中有两种类型的表值函数:
内联表值函数:对于内联表值函数,没有函数体;该表是单个 SELECT 语句的结果集。该类型可以命名为
据我所知,ORACLE 中没有对应的“参数化视图”。
多语句表值函数:对于多语句表值函数,在
BEGIN...END
块中定义的函数体包含一系列构建和插入的 Transact-SQL 语句行写入将返回的表中。上面的示例(作者:Gary Myers)创建了第二种类型的表函数,它不是“参数化视图”。
There are TWO types of table-valued functions in SQL SERVER:
Inline table-valued function: For an inline table-valued function, there is no function body; the table is the result set of a single
SELECT
statement. This type can be named as'parameterized view' and it has no equivalent in ORACLE as I know.
Multistatement table-valued function: For a multistatement table-valued function, the function body, defined in a
BEGIN...END
block, contains a series of Transact-SQL statements that build and insert rows into the table that will be returned.The above sample (By Gary Myers) creates a table function of the second type and it is NOT a 'parameterized view'.