SP_EXECUTESQL
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.