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)
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'.
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
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.