If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > Oracle > stored procedure for search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-09-12, 00:47
kannama kannama is offline
Registered User
 
Join Date: Feb 2012
Posts: 9
stored procedure for search

Is this stored procedure in oracle is correct for searching data from table by passing table name as a parameter

CREATE OR REPLACE PROCEDURE bank_search_sp
(
p_tablename IN VARCHAR2,
p_searchname IN VARCHAR2,
p_bankcode OUT VARCHAR2,
p_bankname OUT VARCHAR2,
p_dist_code OUT NUMBER
)
AS
v_tem VARCHAR2(5000);
BEGIN
v_tem := 'SELECT bankcode,bankname,dist_code FROM ' || UPPER (p_tablename) || '
WHERE bankname LIKE '''|| p_searchname||'''';
EXECUTE IMMEDIATE v_tem
INTO p_bankcode,p_bankname,p_dist_code
USING p_searchname ;
END bank_search_sp;
Reply With Quote
  #2 (permalink)  
Old 02-09-12, 01:40
Littlefoot Littlefoot is offline
Lost Boy
 
Join Date: Jan 2004
Location: Croatia, Europe
Posts: 3,629
Is it correct? You wrote it, you tested it. What do you say?
Reply With Quote
  #3 (permalink)  
Old 02-09-12, 01:44
kannama kannama is offline
Registered User
 
Join Date: Feb 2012
Posts: 9
Reply

When i execute this the procedure is getting created but it is not working properly it shows errors like this

Running "PENSIONS"."BANK_SEARCH_SP" ( P_TABLENAME = bank, P_SEARCHNAME = S ).

ORA-01006: bind variable does not exist
ORA-06512: at "PENSIONS.BANK_SEARCH_SP", line 15
ORA-06512: at line 1
Reply With Quote
  #4 (permalink)  
Old 02-09-12, 03:06
Littlefoot Littlefoot is offline
Lost Boy
 
Join Date: Jan 2004
Location: Croatia, Europe
Posts: 3,629
I don't have your tables, so here's an example based on Scott's schema. See how I did it, and then adjust your code.
Code:
SQL> create or replace procedure p_search
  2    (p_tablename in char,
  3     p_job in char,
  4     p_ename out char
  5    )
  6  is
  7    v_tem varchar2(500);
  8  begin
  9    v_tem := 'select max(ename) from ' || p_tablename || ' where job like ''%' ||
 10             p_job || '%''';
 11    execute immediate v_tem into p_ename;
 12  end;
 13  /

Procedure created.

SQL> declare
  2    l_out varchar2(30);
  3  begin
  4    p_search('emp', 'CLERK', l_out);
  5    dbms_output.put_line(l_out);
  6  end;
  7  /
SMITH

PL/SQL procedure successfully completed.

SQL>
Reply With Quote
  #5 (permalink)  
Old 02-09-12, 03:46
kannama kannama is offline
Registered User
 
Join Date: Feb 2012
Posts: 9
Thank u

Its working
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On