Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Mailing Lists -> Oracle-L -> RE: Dynamic SQL: where do you draw the line?
<FONT face="Courier New" color=#0000ff
size=2>Thomas,
<FONT face="Courier New" color=#0000ff
size=2>
<FONT face="Courier New" color=#0000ff
size=2>I'd prefer your approach than a spaghetti code of if-then-else, lucky you
they haven't discovered GOTO yet ... <g>
<FONT face="Courier New" color=#0000ff
size=2>
<FONT face="Courier New" color=#0000ff
size=2>Raj
<FONT face="Courier New"
size=2>--------------------------------------------------------------------------------Rajendra dot Jamadagni at nospamespn dot com All Views expressed in this email
<FONT face=Tahoma
size=2>-----Original Message-----From: Thomas Jeff
[mailto:[EMAIL PROTECTED]Sent: Wednesday, June 25, 2003 3:25
PMTo: Multiple recipients of list ORACLE-LSubject: RE:
Dynamic SQL: where do you draw the line?
<FONT face="Courier New" color=#0000ff
size=2>Raj,
<FONT face="Courier New" color=#0000ff
size=2>
<FONT face="Courier New" color=#0000ff
size=2>I'm aware of the table technique for converting inlists and employed
that a few weeks ago in a
<FONT face="Courier New" color=#0000ff
size=2>different stored procedure. I was thinking if we
could make the DELETE static, then it could
<FONT face="Courier New" color=#0000ff
size=2>soemthing look like this:
<FONT face="Courier New" color=#0000ff
size=2>
<FONT face="Courier New" color=#0000ff
size=2>DELETE FROM TABLE
WHERE ASSET_GUID IN (SELECT * FROM THE (SELECT CAST(
str2tab(p_str) as STRTABTYPE ) FROM DUAL))
<FONT face="Courier New" color=#0000ff
size=2> AND SITE_GUIDE = p_site_guid
<FONT face="Courier New" color=#0000ff
size=2> AND OBJECT_GUID = p_object_guid;
<FONT face="Courier New" color=#0000ff
size=2>
<FONT face="Courier New" color=#0000ff
size=2>And I would have them code 7 small procedures each with the similar
DELETE syntax. This way, with
<FONT face="Courier New" color=#0000ff
size=2>static SQL, you eliminate both the hard and soft
parsing. With EXEC IMMEDIATE, you will always at
least
<FONT face="Courier New" color=#0000ff
size=2>get the soft parsing. That's my
understanding.
<FONT face="Courier New" color=#0000ff
size=2>
<FONT face="Courier New" color=#0000ff
size=2>
<FONT face="Courier New" color=#0000ff
size=2>
<FONT face=Tahoma
size=2>-----Original Message-----From: Jamadagni, Rajendra
[mailto:[EMAIL PROTECTED]Sent: Wednesday, June 25, 2003
12:35 PMTo: Multiple recipients of list ORACLE-LSubject:
RE: Dynamic SQL: where do you draw the line?
Thomas,
IMHO You probably picked up a BAD example to make your point.
Yes I agree with you, but here the table is unknown, which would make this a
Dynamic_sql of type 4 or 3?). in this case you are constructing whole
statement dynamically.
Also it seems user developers are sending a string of numbers
separated by space, which is replaced by semicolon to make a dynamic IN List.
This might be the weekenss, Send them a URL to Asktom site and show them how
to convert inlists into a table for max flexibility in the code.
You could, OTOH run some quick tests on this code and another
where you have one delete statement per table and use 10046 event to show them
what impact it has on the database. I hate long if-then-else structures
too.
ps: if you want to break this code, send in p_site_guid value
as '1,2' and watch the fun. In case of dynamic sql like this (and especially
if it is coming from web), have your developers learn about sql-injecting
techniques ... you _must_ validate input against a KNOWN set of values before
using them. You _must_ also reject all unknowns with appropriate
feedback.
Raj <FONT
size=2>--------------------------------------------------------------------------------Rajendra dot Jamadagni at nospamespn dot com <FONT size=2>All Views expressed in this email are strictly personal. QOTD: Any clod can have facts, having an opinion is an art !
CREATE OR REPLACE PROCEDURE test <FONT
size=2>(
p_Asset_Guid IN VARCHAR2,
p_Object_Id IN VARCHAR2, p_Object_Definition IN VARCHAR2, p_Site_Guid IN VARCHAR2, p_result IN
size=2> strWhere VARCHAR2(100); <FONT size=2> strQuery LONG; BEGIN IF
execute immediate strQuery; p_result := '1'; RETURN; <FONT size=2>END; -------------------------------------------- <FONTsize=2>Jeffery D Thomas DBA <FONT
********************************************************************This e-mailmessage is confidential, intended only for the named recipient(s) above and may contain information that is privileged, attorney work product or exempt from disclosure under applicable law. If you have received this message in error, or are not the named recipient(s), please immediately notify corporate MIS at (860) 766-2000 and delete this e-mail message from your computer, Thank
you.*********************************************************************2Received on Wed Jun 25 2003 - 14:22:47 CDT
![]() |
![]() |