我试图在ORACLE SQL Developer中定义变量中的标准值,但它一直要求我输入一个值。如何避免这种情况并将其作为默认值设置为v_mode =' X1',' X2'并将COB_DATE设置为7月14日,以便没有弹出窗口?
variable COB_DATE date
variable v_mode varchar(20);
exec :COB_DATE := '14-JUL-2016';
exec :v_mode := 'MAG';
select *
FROM DF_RISK_SIT2_OWNER.recon_ts_rs
WHERE SRC_HUB = 'DBRS'
AND TRD_SRC_SYS in :v_mode
AND DSET_COB_DT = :COB_DATE
但我收到错误:Bind Variable" COB_DATE"未声明
答案 0 :(得分:2)
SQL> help var
VARIABLE
--------
Declares a bind variable that can be referenced in PL/SQL, or
lists the current display characteristics for a single variable
or all variables.
VAR[IABLE] [variable [type]]
where type represents one of the following:
NUMBER CHAR CHAR (n [CHAR|BYTE])
NCHAR NCHAR (n) VARCHAR2 (n [CHAR|BYTE])
NVARCHAR2 (n) CLOB NCLOB
REFCURSOR BINARY_FLOAT BINARY_DOUBLE
正如您所看到的,这里没有DATE类型。我想整个
variable COB_DATE date
被忽略。
作为一种解决方法,您可以将COB_DATE定义为varchar2并将其转换为sql中的DATE
variable COB_DATE varchar2(30)
variable v_mode varchar2(20)
exec :COB_DATE := '14-JUL-2016';
exec :v_mode := 'MAG';
select *
FROM DF_RISK_SIT2_OWNER.recon_ts_rs
WHERE SRC_HUB = 'DBRS'
AND TRD_SRC_SYS in :v_mode
AND DSET_COB_DT = TO_DATE(:COB_DATE, 'DD-MON-YYYY')
或依靠使用原始查询的隐式转换
答案 1 :(得分:1)
答案 2 :(得分:0)
对于Oracle SQL Developer:
定义defVar ='AA%'
选择... 像“ && defVar”;