zoukankan      html  css  js  c++  java
  • 转 SQL*PLUS中的替换变量(& &&)

    今天oracle support提供一个脚本,大致如下:

    PROMPT ROUTING_SEQUENCE_ID = &ROUT_SEQ_ID 

    PROMPT OPERATION_SEQUENCE_ID = &OP_SEQ_ID

    PROMPT RESOURCE_SEQ_NUM = &RES_SEQ_NUM 

    PROMPT RESOURCE_ID = &RES_ID

    SELECT 
      SCHEDULE_SEQ_NUM SSN,
      BASIS_TYPE BT,
      UOM_CODE UC,
      PRINCIPAL_FLAG PF
    FROM 
      MRP_AP_OPERATION_RESOURCES_V
    WHERE 
      ROUTING_SEQUENCE_ID = &ROUT_SEQ_ID  AND
      OPERATION_SEQUENCE_ID = &OP_SEQ_ID  AND
      --RESOURCE_ID = &RES_ID  --AND 
      RESOURCE_SEQ_NUM = &RES_SEQ_NUM;



    SELECT 
      SCHEDULE_SEQ_NUM SSN,
      BASIS_TYPE BT,
      UOM_CODE UC,
      PRINCIPAL_FLAG PF
    FROM 
      MRP_AP_OPERATION_RESOURCES_V
    WHERE 
      --ROUTING_SEQUENCE_ID = &ROUT_SEQ_ID  AND 
      --OPERATION_SEQUENCE_ID = &OP_SEQ_ID  AND 
      RESOURCE_ID = &RES_ID  AND
      RESOURCE_SEQ_NUM = &RES_SEQ_NUM;

    SELECT 
      SCHEDULE_SEQ_NUM SSN,
      BASIS_TYPE BT,
      UOM_CODE UC,
      PRINCIPAL_FLAG PF
    FROM 
      MRP_AP_OPERATION_RESOURCES_V
    WHERE 
      ROUTING_SEQUENCE_ID = &ROUT_SEQ_ID  AND
      OPERATION_SEQUENCE_ID = &OP_SEQ_ID  AND
      RESOURCE_ID = &RES_ID;  
      --AND  RESOURCE_SEQ_NUM = &RES_SEQ_NUM

    SELECT 
      SCHEDULE_SEQ_NUM,
      NVL(ALTERNATE_NUMBER  ,
      0) ALT_NUM ,
      RESOURCE_SEQ_NUM
    FROM 
      MRP_AP_OPERATION_RESOURCES_V
    WHERE 
      ROUTING_SEQUENCE_ID = &ROUT_SEQ_ID  AND
      OPERATION_SEQUENCE_ID = &OP_SEQ_ID  AND
      RESOURCE_ID = &RES_ID;

    SELECT 
      SCHEDULE_SEQ_NUM,
      RESOURCE_SEQ_NUM,
      SCHEDULE_FLAG
    FROM 
      BOM_OPERATION_RESOURCES
    WHERE 
      RESOURCE_ID = (&RES_ID/2)  AND
      OPERATION_SEQUENCE_ID = (&OP_SEQ_ID/2);

    SELECT 
      REPLACEMENT_GROUP_NUM,
      SCHEDULE_SEQ_NUM,
      SCHEDULE_FLAG,
      SUBSTITUTE_GROUP_NUM
    FROM 
      BOM_SUB_OPERATION_RESOURCES
    WHERE 
      RESOURCE_ID = (&RES_ID/2)  AND
      OPERATION_SEQUENCE_ID = (&OP_SEQ_ID/2);

     我运行的时候发现输入四个变量后,在紧跟着的每个select中还要再次输入,很麻烦。后来查了一下资料知道了&与&&的区别。在这里做个小记录:

    &:引用的变量只存在当前的语句中。举例如下:

    SQL> select 1+&var from dual;
    Enter value for var: 1
    old   1: select 1+&var from dual
    new   1: select 1+1 from dual

           1+1
    ----------
             2

    SQL> /                    --重复执行需要重新输入变量var的值。
    Enter value for var: 2
    old   1: select 1+&var from dual
    new   1: select 1+2 from dual

           1+2
    ----------
             3

    &&:引用的变量存在于当前的sesion。举例如下:

    SQL> select 1+&&var from dual;
    Enter value for var: 1
    old   1: select 1+&&var from dual
    new   1: select 1+1 from dual

           1+1
    ----------
             2

    SQL> /
    old   1: select 1+&&var from dual
    new   1: select 1+1 from dual

           1+1
    ----------
             2

    SQL> select 100+&var from dual;
    old   1: select 100+&var from dual
    new   1: select 100+1 from dual

         100+1
    ----------
           101

    所以我只要在前面的变量前加一个&就使它的作用范围变成session级的了。如下:

    PROMPT ROUTING_SEQUENCE_ID = &&ROUT_SEQ_ID 

    PROMPT OPERATION_SEQUENCE_ID = &&OP_SEQ_ID

    PROMPT RESOURCE_SEQ_NUM = &&RES_SEQ_NUM 

    PROMPT RESOURCE_ID = &&RES_ID

     
    http://blog.chinaunix.net/uid-20274021-id-1969700.html
  • 相关阅读:
    openstack--9--深入理解虚拟机
    KVM部署、使用、调优
    Mysql主从---删除master.info和relya-log.info实验
    saltstack实战4--综合练习3
    saltstack实战4--综合练习4
    saltstack实战4--综合练习2
    nmap命令-----高级用法
    saltstack实战4--综合练习1
    saltstack实战3--配置管理之pillar
    nmap命令-----基础用法
  • 原文地址:https://www.cnblogs.com/feiyun8616/p/6934156.html
Copyright © 2011-2022 走看看