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 condition

user520824Nov 9 2020

Hello,
I have an issue getting the where condition dynamically built while joining two tables.
"where_clause" is a column in test_model_tbl and its value should appear in the where condition dynamically.

select * from test_entity_tbl e, test_model_tbl t
where e.div_no = 10
and e.div_no = t.div_no
[and e.trend='BUY' and div_name='MODEL_DIV'] ----> this should be dynamically from t.where_clause column

How do I get the where_clause column as a value and append to the above query?

Scripts
------------------
create table test_entity_tbl ( div_no number, status varchar2(20), trend varchar2(100), st_dt date, div_name varchar2(30), bus_name varchar2(100), proc_value varchar2(20), proc_desc varchar2(30));
insert into test_entity_tbl values (10,'COMPLETE','BUY', trunc(sysdate), 'MODEL_DIV', 'DNC ENTERPRISE LLC', 'Model Accept','This model has been approved');
insert into test_entity_tbl values (20,'COMPLETE','SELL', trunc(sysdate), 'HR_DIV', 'PR WORKERS LLC', 'Model Reject','This model has been rejected');
commit
/

create table test_model_tbl ( div_no number, where_clause varchar2(4000));

Insert into IE_DBA.TEST_MODEL_TBL (DIV_NO, WHERE_CLAUSE)
Values (10, 'e.trend=''BUY'' and div_name=''MODEL_DIV'' ');
Insert into IE_DBA.TEST_MODEL_TBL (DIV_NO, WHERE_CLAUSE) Values
(20, 'e.trend=''SELL'' and bus_name=''DNC ENTERPRISE LLC'' ');
COMMIT;

Comments
Post Details
Added on Nov 9 2020
17 comments
5,055 views