473,387 Members | 1,619 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Dynamic sql generation using oracle 10g stored procedures

Hi,

I created a stored procedure as --

Expand|Select|Wrap|Line Numbers
  1.  
  2.  
  3. (
  4. V_Search_Key in varchar2,
  5. P_LinkSearchResults_CUR out sys_refcursor
  6. )
  7. as
  8. lv_sql varchar2(1000);
  9. begin
  10. lv_sql := 'select b.link_id, b.link_display_name, b.override_link_display_name, b.link_path
  11. from oppe_search a, lu_links b 
  12. where a.content_id=b.link_ID and upper(a.search_key) in (:v_search_key)' ;
  13. open P_LinkSearchResults_CUR FOR 
  14. lv_sql using v_search_key;
  15. end;
  16.  
  17.  


I dont get any errors but when I pass on values to it, it returns no rows although there are rows in the table for the search string. Any clue on how I can form this search string. Is it the best way of writing the procedure?

Any immediate help is greatly appreciated.

Thanks,
Archna
Mar 18 '08 #1
3 2379
amitpatel66
2,367 Expert 2GB
Try this:

Expand|Select|Wrap|Line Numbers
  1.  
  2. (
  3. V_Search_Key IN VARCHAR2,
  4. P_LinkSearchResults_CUR OUT sys_refcursor
  5. )
  6. AS
  7. lv_sql VARCHAR2(1000);
  8. BEGIN
  9. lv_sql := 'select b.link_id, b.link_display_name, b.override_link_display_name, b.link_path
  10. from oppe_search a, lu_links b 
  11. where a.content_id=b.link_ID and upper(a.search_key) = UPPER(:v_search_key)' ;
  12. OPEN P_LinkSearchResults_CUR FOR 
  13. lv_sql USING v_search_key;
  14. END;
  15.  
  16.  

I have used "=" sign instead of IN becuase it is got to be one value passed as input parameter right?
Mar 18 '08 #2
My input parameter is comma separated values to search within a table, hence I needed dynamic sql and the 'IN' clause. It is part of a 'Search' function I am building for an intranet, so I needed all the values entered by the user for Search--

I tried this code and unexpectedly it worked..
Expand|Select|Wrap|Line Numbers
  1.  
  2. (
  3. V_Search_Key in varchar2,
  4. P_LinkSearchResults_CUR out sys_refcursor
  5. )
  6. as
  7. begin
  8. open P_LinkSearchResults_CUR FOR 
  9. 'select b.link_id, b.link_display_name, b.override_link_display_name, b.link_path ' ||
  10. 'from oppe_search a, lu_links b ' ||
  11. 'where a.content_id=b.link_ID and upper(a.search_key) in (' || 
  12. V_Search_Key || ')';
  13.  
  14. end;
  15.  
Thanks for your reply.

----------------------------------------------------------------------------------------------------------------



Try this:

Expand|Select|Wrap|Line Numbers
  1.  
  2. (
  3. V_Search_Key IN VARCHAR2,
  4. P_LinkSearchResults_CUR OUT sys_refcursor
  5. )
  6. AS
  7. lv_sql VARCHAR2(1000);
  8. BEGIN
  9. lv_sql := 'select b.link_id, b.link_display_name, b.override_link_display_name, b.link_path
  10. from oppe_search a, lu_links b 
  11. where a.content_id=b.link_ID and upper(a.search_key) = UPPER(:v_search_key)' ;
  12. OPEN P_LinkSearchResults_CUR FOR 
  13. lv_sql USING v_search_key;
  14. END;
  15.  
  16.  

I have used "=" sign instead of IN becuase it is got to be one value passed as input parameter right?
Mar 20 '08 #3
Saii
145 Expert 100+
There is nothing unexpected about this. When you pass a list of values to NDS, you have to enclose the list in quotes.
Mar 20 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Suresh Tri | last post by:
Hi all, I am in search of any Enterprise level Opensource Project that uses Java Stored Procedures supported by Oracle. I could not find any by googling. Can any one plese point me to any such...
1
by: Guinness Mann | last post by:
When you guys talk about "dynamic SQL," to what exactly are you referring? Is dynamic SQL anything that isn't a stored procedure? Specifically, I use ASP.NET to communicate with my SQL Server...
5
by: Ralph | last post by:
Hi all, I'm a newbie to MS-SQL UDFs and seem to have a real big problem. I need to implement a logic to receive an adress build out of various user definable fields from various user defined...
11
by: jrefactors | last post by:
I want to know the differences between SQL Server 2000 stored procedures and oracle stored procedures? Do they have different syntax? The concept should be the same that the stored procedures...
1
by: Todd Peterson | last post by:
I'm a newbie to DB2 and am trying to figure out how to write a stored procedure, using dynamic SQL statements to return a result set. I believe the majority of the hurdles I have been facing might...
2
by: Irfan | last post by:
hi, I am getting the following error. Dynamic SQL generation is not supported against a SelectCommand that does not return any base table information when i try to use da.update I squeezed...
4
ayanmitra2007mindtree
by: ayanmitra2007mindtree | last post by:
Consider I have five stored procedures viz. pr_sp1 (int_num1 IN number, int_num2 IN Number, v_cur OUT s_pkg.s_cur) pr_sp2 (int_num1 IN number, int_num2 IN Number, v_cur OUT s_pkg.s_cur) pr_sp3...
4
by: --CELKO-- | last post by:
I need to convert a bunch of DB2 triggers to Oracle. Is there any kind of tools for this?
6
by: =?ISO-8859-1?Q?Tim_B=FCthe?= | last post by:
Hi, we are building a Java webapplication using JSF, running on websphere, querying a DB2 9 on Suse Enterprise 10. The app uses JDBC and PreparedStatements only (aka dynamic SQL). Every night,...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.