I want to create a stored procedure with one argument which will return different sets of records depending on the argument. What is the way to do this? Can I call it from plain SQL?
相关问题
- SQL join to get the cartesian product of 2 columns
- sql execution latency when assign to a variable
- Difference between Types.INTEGER and Types.NULL in
- php PDO::FETCH_ASSOC doesnt detect select after ba
- Bulk update SQL Server C#
Here is how to build a function that returns a result set that can be queried as if it were a table:
You may use Oracle pipelined functions
Simple Example - Generating Some Random Data
How could you create N unique random numbers depending on the input argument?
Suppose we needed three rows for something. We can now do that in one of two ways:
COLUMN_VALUE
or
COLUMN_VALUE
pipelied Functions1 pipelied Functions2
I think you want to return a REFCURSOR:
Update: If you need to call this from SQL, use a table function like @Tony Andrews suggested.
If you want to use it in plain SQL, I would let the store procedure fill a table or temp table with the resulting rows (or go for @Tony Andrews approach).
If you want to use @Thilo's solution, you have to loop the cursor using PL/SQL. Here an example: (I used a procedure instead of a function, like @Thilo did)