Sai Ram

Sai Ram

  • NA
  • 237
  • 115.8k

How to write dynamic select stored Procedure

Aug 22 2012 7:52 AM

How to write dynamic select stored Procedure
I wrote some code like this ...Please correct it and revert back..


create or replace
PROCEDURE SAMPLE
(  p_filter_column IN out  Varchar2,
  p_filter_operator_name IN out varchar2,
  p_filter_value IN out varchar2,
  p_page_size IN out varchar2,
  p_current_page IN out INT,
  p_sort_column IN out varchar2,
  p_sort_direction IN out varchar2,
  p_table_name IN out varchar2
)

IS
 condition_string varchar(300);
 row_start int;
 excute_string varchar(300);

Begin
 condition_string:= p_filter_column || p_filter_operator_name || p_filter_value;

  If (p_current_page > 1) then
  row_start:= to_number(p_current_page) * to_number(p_page_size);
 else
  row_start:=1;
 end If;
  excute_string:='SELECT  * FROM ' ||  p_table_name || 'WHERE' || condition_string || 'AND ROWNUM >' || row_start ||  'order by' || p_sort_column || p_sort_direction;
  EXECUTE IMMEDIATE excute_string;
 
End;


Answers (2)