Answer the question
In order to leave comments, you need to log in
How to execute SELECT in a stored procedure?
Hello comrades! I am using Oracle 12c.
I'm trying to write a stored procedure. It takes 2 parameters as input, which are used in a simple select query. The query returns all records for a specified period.
Questions :
1) Do I need to write all columns as output parameters? For example, in my case, the number of columns is 15.
2) Since the query returns more than one record, you need to set the cursor, do I understand correctly? How it is correct to register it in stored procedure? Could you give an example.
SQL :
SELECT * FROM TABLE_NAME
WHERE CREATE_DATE BETWEEN TO_DATE(FIRST_DATE, 'YYYY-MM-DD') AND TO_DATE(SECOND_DATE , 'YYYY-MM-DD')
Answer the question
In order to leave comments, you need to log in
Why do you need the procedure? According to the description, it seems that the function is enough. If it is necessary to thrust in a packet - that function too is possible. And it's bad to write "select *", list the parameters that are needed explicitly. I would write like this.
/*
* Заголовок
*/
function get_params_from_table (p_param1 in number,
p_param2 in number) return TCursor;
/
/*
* Тело
*/
function get_params_from_table (p_param1 in number,
p_param2 in number) return TCursor
is
c_ret TCursor;
begin
open c_ret for
SELECT param1, param2, param3 FROM TABLE_NAME
WHERE CREATE_DATE BETWEEN TO_DATE(FIRST_DATE, 'YYYY-MM-DD') AND TO_DATE(SECOND_DATE , 'YYYY-MM-DD');
return c_ret;
end;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question