0

I am preparing stored procedure with oracle .I m using multiple inner joins with the same table where an input parameter value is checked within each inner join. I want to eliminate particular inner join if the input parameter is null

1 Answer 1

3

You would need to use dynamic SQL to construct the appropriate query for the parameters like this:

PROCEDURE myproc (p1 VARCHAR2) IS
   l_sql LONG;
   l_cursor SYS_REFCURSOR;
BEGIN
   l_sql := 'SELECT a, b, c FROM table1';
   IF p1 IS NOT NULL THEN
      l_sql := l_sql || ' JOIN table2 ON table2.x = table1.x';
   END IF;
   l_sql := l_sql || ' WHERE table1.y = :bind1';
   OPEN l_cursor FOR l_sql USING 123;
   ...
END;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.