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!

Dynamic where clause in Plsql

RaghavendraNaraJun 21 2019 — edited Jun 21 2019

Hi All,

As per the requirement,  in a stored procedure ii need to build a dynamic where based on the input parameter.

Example below explained.

DECLARE

l_sysdate varchar2(100);

l_condition VARCHAR2(1000);

l_input_parameter varchar2(100);

BEGIN

IF l_input_parameter  ='X' THEN

l_condition :='WHERE 1=1';

ELSE

l_condition :='WHERE 1=1';

END IF;

SELECT SYSDATE INTO l_sysdate from dual ||l_condition  ;

DBMS_OUTPUT.PUT_LINE('l_sysdate '||l_sysdate);

EXCEPTION

WHEN OTHERS THEN

DBMS_OUTPUT.PUT_LINE('WHEN OTHERS '||SQLERRM);

END;

In the above example assuming that l_input_parameter   is input parameter  based on this i need to  concatenate to the below sql.

Please confirm if it is possible.

Regards

N

This post has been answered by RaghavendraNara on Jun 21 2019
Jump to Answer
Comments
Post Details
Added on Jun 21 2019
5 comments
4,320 views