Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

SP_EXECUTESQL

269332Nov 11 2002
Hi all... I come from a SQL Server back round, and have a question about how to do something in Oracle...

I have a SQL statement, that reuses a constant 8 times... How can I write the SQL so I just have to pass it once? An example for SS would be:

EXECUTE sp_ExecuteSQL N'SELECT field1 FROM table WHERE field2=@Var',N'@Var varchar(100)',@Var='Hello World';

Note: This is a simple example where "@Var" is used only once, but I think you get the idea.

The issue is, I have a 40-line query that is very complex, and it's where clause does 8 different comparisons of a variable to various columns. Our JAVA server builds the SQL statement ok before passing it to Oracle, but performance is really bad. In SQL Server in some cases this would have been caused by the parser not being able to parameterize the SQL, and having to build a new execution plan each time the SQL was called with a deffient variable. using sp_ExecuteSQL forces the parser engine into a different routine to force the plan to be cached.

Any help would be great. Thanks.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 9 2002
Added on Nov 11 2002
2 comments
1,240 views