Home > database >  Oracle how to implement the where dynamic condition (statements best mysql and oracle general)
Oracle how to implement the where dynamic condition (statements best mysql and oracle general)

Time:10-08

To achieve dynamic behind the where condition, according to different conditions, the where condition also will find change, don't use process approach, the following is a mysql statement, but don't run in oracle, a great god, please look at how to convert them to oracle and can run mysql statement:
SELECT t.p rov_name AS 'level, tc ity_name AS' secondary institutions, t.s ales_name AS 'solicitors' t.i nt_value AS' number '
The FROM yl_order_table t
WHERE 1=1
Filter grade 1 - (1) department AND the CASE WHEN (SELECT COUNT (1) the FROM fr_user_city t WHERE t.v alid='t' AND t.l evel IN (1, 2, 3) AND t.u ser_code='username') & lt;> 1 0 THEN t.p rov_name IN (SELECT distinct t.org _name FROM fr_user_city t WHERE t.v alid='t' AND t.l evel IN (1, 2, 3) AND t.u ser_code='username') ELSE 1=1 END - (2) filter AND level 2 department CASE WHEN (SELECT COUNT (1) the FROM fr_user_city t WHERE t.v alid='t' AND t.l evel IN (2, 3) AND t.u ser_code='username') & lt;> 2 0 THEN tc ity_name IN (SELECT distinct t.org _name FROM fr_user_city t WHERE t.v alid='t' AND t.l evel IN (2, 3) AND t.u ser_code='username') ELSE 1=1 END - (3) filtering level 3 departments AND CASE WHEN (SELECT COUNT (1) the FROM fr_user_city t WHERE t.v alid='t' AND t.l evel=3 AND t.u ser_code='username') & lt;> 0 THEN t.s ales_name IN (SELECT distinct t.org 3 _name FROM fr_user_city t WHERE t.v alid='t' AND t.l evel=3 AND t.u ser_code='username') ELSE 1=1 END
;

CodePudding user response:

In A (... ) is considered judgment expression rather than return a value, you can then nested case again after the when, or put the t.p rov_name IN written into the back of the query

CodePudding user response:

reference 1st floor nayi_224 response:
A (in... ) is considered judgment expression rather than return a value, you can then nested case again after the when, or put the t.p rov_name IN written into the back of the query
I just want this IN () as the expression of the where condition, only according to the different article, where the expression is different,
  • Related