0

我有一个甲骨文查询:

select * from table1,table2 where table1.id1 = table2.id2 and 
--filters
table1.col2 = 'value_11' and table2.col2 = 'value_21'
or
table1.col2 = 'value_12' and table2.col2 = 'value_22'
or
table1.col2 = 'value_13' and table2.col2 = 'value_23'
...

如果过滤条件达到 100,如何重写查询?喜欢(value_11,value_21),(value_12,value_22)......(value_1100,value_2200)

编辑:原始查询是这样的:

select 
    cust_country.cust_login_id 
  , cust_country.user_login_id
  , cust_country.country_name
  , cust_email.email 
from ( select 
           APP_USER.USER_ID, customer.cust_login_id
         , user_credential.user_login_id, COUNTRY.COUNTRY_NAME 
       from 
           app_user
         , user_ci
         , contact_info
         , address
         , country
         , customer
         , user_credential 
       where APP_USER.USER_ID = USER_CI.USER_ID 
         and CONTACT_INFO.CI_ID=USER_CI.CI_ID
         and ADDRESS.ADDR_ID=CONTACT_INFO.CI_ID 
         and ADDRESS.COUNTRY_ID=COUNTRY.COUNTRY_ID 
         and APP_USER.CUST_ID=CUSTOMER.CUST_ID 
         and USER_CREDENTIAL.USER_ID=APP_USER.USER_ID
     ) cust_country,

     ( select 
           customer.cust_login_id, APP_USER.USER_ID
         , user_credential.user_login_id, ipty_email.email
       from 
         app_user,user_ci,contact_info,ipty_email,customer,user_credential 
       where APP_USER.USER_ID = USER_CI.USER_ID 
         and CONTACT_INFO.CI_ID=USER_CI.CI_ID 
         and ipty_email.ipe_ID=CONTACT_INFO.CI_ID 
         and APP_USER.CUST_ID=CUSTOMER.CUST_ID 
         and USER_CREDENTIAL.USER_ID=APP_USER.USER_ID
     ) cust_email

where cust_country.user_id = cust_email.user_id 
  and (cust_country.cust_login_id, cust_country.user_login_id) in 
      (('xxxxyyyyy','ADMIN2'))
4

1 回答 1

4

您可以使用以下方法(稍微)压缩它:

SELECT *                                       --- irrelevant to the question:
FROM table1 JOIN table2                        --- use the explicit JOIN syntax
             ON table1.id1 = table2.id2        --- not the implicit join with the
---table1,table2 where table1.id1 = table2.id2 --- WHERE syntax (removed)
WHERE
--- filters
  AND (table1.col2, table2.col2) IN
        (  ('value_11', 'value_21'),
           ('value_12', 'value_22'),
           ('value_13', 'value_23'),
           ...
           (value_1100, value_2200)
        ) 

如果您在表格中有这些过滤条件,您甚至可以制作它:

  AND (table1.col2, table2.col2) IN
        (  SELECT filter1, filter2
           FROM filter_table
        )
于 2012-05-04T23:29:57.450 回答