关于sql条件执行顺序

下边这个sql第六行,我怎样能限制它先执行c.source_location_c like 'Q%',现在的情况就是它先不执行这个条件,
不能过滤掉不符合条件的行

( b.berth_seq_n=to_number(substr(c.source_location_c,9,1)) and b.vv_c=to_number(substr(c.source_location_c, 3,5)) and c.source_location_c like 'Q%')


SQL> select b.terminal_c,b.section_n,c.job_n,c.cntr_n,c.yard_block_m, c.create_dt, c.source_location_c, c.destination_location_c,c.start_dt, c.job_type_c,c.operation_type_c,c.mount_dt,c.offload_dt, c.pm_m,c.operation_group_c
  2  from cntr_job c, berth_allocation b
  3  where  c.pm_m is not null and
  4               ( b.terminal_c='B' and
  5                        (
  6                                  ( b.berth_seq_n=to_number(substr(c.source_location_c,9,1)) and b.vv_c=to_number(substr(c.source_location_c, 3,5)) and c.source_location_c like 'Q%')
  7                                   or
  8                                  (b.berth_seq_n=to_number(substr(c.destination_location_c,9,1)) and  b.vv_c=to_number(substr(c.destination_location_c, 3,5)) and c.destination_location_c like 'Q%')
  9                         )
10               )
11               or (c.source_location_c like 'Y,B%' and c.destination_location_c like 'Q%' and b.terminal_c<>'B' and b.berth_seq_n=to_number(substr(c.destination_location_c,9,1)) and  b.vv_c=to_number(substr(c.destination_location_c, 3,5)))
12               or (c.destination_location_c like 'Y,B%' and c.source_location_c like 'Q%' and b.terminal_c<>'B' and b.berth_seq_n=to_number(substr(c.source_location_c,9,1)) and  b.vv_c=to_number(substr(c.source_location_c, 3,5)))
13               and (job_type_c=2 or(job_type_c=1 and pm_m not in(select pm_m from cntr_job where job_type_c=2 AND pm_m IS NOT NULL AND offload_dt IS NULL)));
                                ( b.berth_seq_n=to_number(substr(c.source_location_c,9,1)) and b.vv_c=to_number(substr(c.source_location_c, 3,5)) and c.source_location_c like 'Q%')
                                                                                                                *
ERROR at line 6:
ORA-01722: invalid number


SQL>
SQL>
SQL>
SQL> set autot trace exp
SQL> select b.terminal_c,b.section_n,c.job_n,c.cntr_n,c.yard_block_m, c.create_dt, c.source_location_c, c.destination_location_c,c.start_dt, c.job_type_c,c.operation_type_c,c.mount_dt,c.offload_dt, c.pm_m,c.operation_group_c
  2  from cntr_job c, berth_allocation b
  3  where  c.pm_m is not null and
  4               ( b.terminal_c='B' and
  5                        (
  6                                  ( b.berth_seq_n=to_number(substr(c.source_location_c,9,1)) and b.vv_c=to_number(substr(c.source_location_c, 3,5)) and c.source_location_c like 'Q%')
  7                                   or
  8                                  (b.berth_seq_n=to_number(substr(c.destination_location_c,9,1)) and  b.vv_c=to_number(substr(c.destination_location_c, 3,5)) and c.destination_location_c like 'Q%')
  9                         )
10               )
11               or (c.source_location_c like 'Y,B%' and c.destination_location_c like 'Q%' and b.terminal_c<>'B' and b.berth_seq_n=to_number(substr(c.destination_location_c,9,1)) and  b.vv_c=to_number(substr(c.destination_location_c, 3,5)))
12               or (c.destination_location_c like 'Y,B%' and c.source_location_c like 'Q%' and b.terminal_c<>'B' and b.berth_seq_n=to_number(substr(c.source_location_c,9,1)) and  b.vv_c=to_number(substr(c.source_location_c, 3,5)))
13               and (job_type_c=2 or(job_type_c=1 and pm_m not in(select pm_m from cntr_job where job_type_c=2 AND pm_m IS NOT NULL AND offload_dt IS NULL)));

Execution Plan
----------------------------------------------------------
Plan hash value: 4217501771

-----------------------------------------------------------------------------------------------------------
| Id  | Operation                           | Name                | Rows  | Bytes | Cost (%CPU)| Time     |
-----------------------------------------------------------------------------------------------------------
|   0 | SELECT STATEMENT                    |                     |    73 |  8979 |   181   (3)| 00:00:03 |
|*  1 |  FILTER                             |                     |       |       |            |          |
|   2 |   TABLE ACCESS BY INDEX ROWID       | BERTH_ALLOCATION    |     1 |    13 |   181   (3)| 00:00:03 |
|   3 |    NESTED LOOPS                     |                     |   549 | 67527 |   181   (3)| 00:00:03 |
|   4 |     TABLE ACCESS FULL               | CNTR_JOB            |   841 | 92510 |     6   (0)| 00:00:01 |
|   5 |     BITMAP CONVERSION TO ROWIDS     |                     |       |       |            |          |
|   6 |      BITMAP OR                      |                     |       |       |            |          |
|   7 |       BITMAP OR                     |                     |       |       |            |          |
|   8 |        BITMAP CONVERSION FROM ROWIDS|                     |       |       |            |          |
|*  9 |         INDEX RANGE SCAN            | BERTH_ALLOCATION_PK |       |       |     0   (0)| 00:00:01 |
|  10 |        BITMAP CONVERSION FROM ROWIDS|                     |       |       |            |          |
|* 11 |         INDEX RANGE SCAN            | BERTH_ALLOCATION_PK |       |       |     0   (0)| 00:00:01 |
|  12 |       BITMAP CONVERSION FROM ROWIDS |                     |       |       |            |          |
|* 13 |        INDEX RANGE SCAN             | BERTH_ALLOCATION_PK |       |       |     0   (0)| 00:00:01 |
|  14 |       BITMAP CONVERSION FROM ROWIDS |                     |       |       |            |          |
|* 15 |        INDEX RANGE SCAN             | BERTH_ALLOCATION_PK |       |       |     0   (0)| 00:00:01 |
|* 16 |   TABLE ACCESS FULL                 | CNTR_JOB            |     1 |    16 |     6   (0)| 00:00:01 |
-----------------------------------------------------------------------------------------------------------

Predicate Information (identified by operation id):
---------------------------------------------------

   1 - filter("B"."TERMINAL_C"='B' AND ("B"."BERTH_SEQ_N"=TO_NUMBER(SUBSTR("C"."SOURCE_LOCATION_C",
              9,1)) AND "B"."VV_C"=TO_NUMBER(SUBSTR("C"."SOURCE_LOCATION_C",3,5)) AND "C"."SOURCE_LOCATION_C"
              LIKE 'Q%' OR "B"."BERTH_SEQ_N"=TO_NUMBER(SUBSTR("C"."DESTINATION_LOCATION_C",9,1)) AND
              "B"."VV_C"=TO_NUMBER(SUBSTR("C"."DESTINATION_LOCATION_C",3,5)) AND "C"."DESTINATION_LOCATION_C"
              LIKE 'Q%') AND "C"."PM_M" IS NOT NULL OR "C"."SOURCE_LOCATION_C" LIKE 'Y,B%' AND
              "C"."DESTINATION_LOCATION_C" LIKE 'Q%' AND "B"."BERTH_SEQ_N"=TO_NUMBER(SUBSTR("C"."DESTINATION_LOCA
              TION_C",9,1)) AND "B"."VV_C"=TO_NUMBER(SUBSTR("C"."DESTINATION_LOCATION_C",3,5)) AND
              "B"."TERMINAL_C"<>'B' OR "C"."DESTINATION_LOCATION_C" LIKE 'Y,B%' AND "C"."SOURCE_LOCATION_C" LIKE
              'Q%' AND "B"."BERTH_SEQ_N"=TO_NUMBER(SUBSTR("C"."SOURCE_LOCATION_C",9,1)) AND
              "B"."VV_C"=TO_NUMBER(SUBSTR("C"."SOURCE_LOCATION_C",3,5)) AND ("JOB_TYPE_C"=2 OR "JOB_TYPE_C"=1
              AND  NOT EXISTS (SELECT /*+ */ 0 FROM "CITOSADMIN"."CNTR_JOB" "CNTR_JOB" WHERE "OFFLOAD_DT" IS
              NULL AND "JOB_TYPE_C"=2 AND "PM_M" IS NOT NULL AND LNNVL("PM_M"<>:B1))) AND "B"."TERMINAL_C"<>'B')
   9 - access("B"."VV_C"=TO_NUMBER(SUBSTR("C"."SOURCE_LOCATION_C",3,5)) AND
              "B"."BERTH_SEQ_N"=TO_NUMBER(SUBSTR("C"."SOURCE_LOCATION_C",9,1)))
  11 - access("B"."VV_C"=TO_NUMBER(SUBSTR("C"."DESTINATION_LOCATION_C",3,5)) AND
              "B"."BERTH_SEQ_N"=TO_NUMBER(SUBSTR("C"."DESTINATION_LOCATION_C",9,1)))
  13 - access("B"."VV_C"=TO_NUMBER(SUBSTR("C"."DESTINATION_LOCATION_C",3,5)) AND
              "B"."BERTH_SEQ_N"=TO_NUMBER(SUBSTR("C"."DESTINATION_LOCATION_C",9,1)))
  15 - access("B"."VV_C"=TO_NUMBER(SUBSTR("C"."SOURCE_LOCATION_C",3,5)) AND
              "B"."BERTH_SEQ_N"=TO_NUMBER(SUBSTR("C"."SOURCE_LOCATION_C",9,1)))
  16 - filter("OFFLOAD_DT" IS NULL AND "JOB_TYPE_C"=2 AND "PM_M" IS NOT NULL AND
              LNNVL("PM_M"<>:B1))

SQL>

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/507279/viewspace-659789/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/507279/viewspace-659789/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值