我正在尝试使用以下形式创建作业:
BEGIN
SYS.DBMS_SCHEDULER.CREATE_JOB
(
job_name => 'OWNER.TEST_PROM'
,start_date => TO_TIMESTAMP_TZ('2018/12/07 03:00:00.324000 -05:00','yyyy/mm/dd hh24:mi:ss.ff tzh:tzm')
,repeat_interval => 'freq=daily'
,end_date => NULL
,job_class => 'DEFAULT_JOB_CLASS'
,job_type => 'PLSQL_BLOCK'
,job_action => '
BEGIN
DECLARE
VAR_1 VARCHAR2(30) := '001';
VAR_2 VARCHAR2(20) := '';
VAR_3 VARCHAR2(20) := TO_CHAR(TO_DATE(SYSDATE-15),''YYYYMMDD'');
VAR_4 VARCHAR2(20) := TO_CHAR(TO_DATE(SYSDATE),''YYYYMMDD'');
OWNER.LOAD_DATA_LOCAL.LOAD_PROM (VAR_1,VAR_2,VAR_3,VAR_4);
OWNER.LOAD_DATA_LOCAL.LOAD_COB_PROM (VAR_1,VAR_2,VAR_3,VAR_4);
OWNER.LOAD_DATA_LOCAL.LOAD_CUP (VAR_1,VAR_2,VAR_3,VAR_4);
end;'
,comments => 'Ejecuta LOAD_prueba_cupones'
);
end;
/
运行它时,出现以下错误:
Error at line 1
ORA-01756: quoted string not properly terminated
ORA-06512: at "SYS.DBMS_ISCHED", line 185
ORA-06512: at "SYS.DBMS_SCHEDULER", line 486
ORA-06512: at line 2
Script Terminated on line 1.
答案 0 :(得分:2)
job_action
声明用单引号引起来。因此,您需要转义其中的所有单引号,否则Oracle无法正确解析它。
因此,您应在'
中的''
中将job_action
替换为VAR1
,即在VAR2
和VAR3
(VAR4
和BEGIN
SYS.DBMS_SCHEDULER.CREATE_JOB
(
job_name => 'OWNER.TEST_PROM'
,start_date => TO_TIMESTAMP_TZ('2018/12/07 03:00:00.324000 -05:00','yyyy/mm/dd hh24:mi:ss.ff tzh:tzm')
,repeat_interval => 'freq=daily'
,end_date => NULL
,job_class => 'DEFAULT_JOB_CLASS'
,job_type => 'PLSQL_BLOCK'
,job_action => '
BEGIN
DECLARE
VAR_1 VARCHAR2(30) := ''001'';
VAR_2 VARCHAR2(20) := '''';
VAR_3 VARCHAR2(20) := TO_CHAR(TO_DATE(SYSDATE-15),''YYYYMMDD'');
VAR_4 VARCHAR2(20) := TO_CHAR(TO_DATE(SYSDATE),''YYYYMMDD'');
OWNER.LOAD_DATA_LOCAL.LOAD_PROM (VAR_1,VAR_2,VAR_3,VAR_4);
OWNER.LOAD_DATA_LOCAL.LOAD_COB_PROM (VAR_1,VAR_2,VAR_3,VAR_4);
OWNER.LOAD_DATA_LOCAL.LOAD_CUP (VAR_1,VAR_2,VAR_3,VAR_4);
end;'
,comments => 'Ejecuta LOAD_prueba_cupones'
);
end;
/
已经可以了):
{{1}}
有关创建作业的示例,请参见this Oracle doc。
答案 1 :(得分:2)
或者使用Oracle引号字符串构造q'[...]',不必担心转义引号的数量:
BEGIN
SYS.DBMS_SCHEDULER.CREATE_JOB
(
job_name => 'OWNER.TEST_PROM'
,start_date => TO_TIMESTAMP_TZ('2018/12/07 03:00:00.324000 -05:00','yyyy/mm/dd hh24:mi:ss.ff tzh:tzm')
,repeat_interval => 'freq=daily'
,end_date => NULL
,job_class => 'DEFAULT_JOB_CLASS'
,job_type => 'PLSQL_BLOCK'
,job_action => q'[
BEGIN
DECLARE
VAR_1 VARCHAR2(30) := '001';
VAR_2 VARCHAR2(20) := '';
VAR_3 VARCHAR2(20) := TO_CHAR(TO_DATE(SYSDATE-15),'YYYYMMDD');
VAR_4 VARCHAR2(20) := TO_CHAR(TO_DATE(SYSDATE),'YYYYMMDD');
OWNER.LOAD_DATA_LOCAL.LOAD_PROM (VAR_1,VAR_2,VAR_3,VAR_4);
OWNER.LOAD_DATA_LOCAL.LOAD_COB_PROM (VAR_1,VAR_2,VAR_3,VAR_4);
OWNER.LOAD_DATA_LOCAL.LOAD_CUP (VAR_1,VAR_2,VAR_3,VAR_4);
end;]'
,comments => 'Ejecuta LOAD_prueba_cupones'
);
end;
/
答案 2 :(得分:-1)
尝试:
BEGIN
DECLARE
VAR_1 VARCHAR2(30) := '001';
VAR_2 VARCHAR2(20) := '';
VAR_3 VARCHAR2(20) := TO_CHAR(TO_DATE(SYSDATE-15),'YYYYMMDD');
VAR_4 VARCHAR2(20) := TO_CHAR(TO_DATE(SYSDATE),'YYYYMMDD');
begin
OWNER.LOAD_DATA_LOCAL.LOAD_PROM (VAR_1,VAR_2,VAR_3,VAR_4);
OWNER.LOAD_DATA_LOCAL.LOAD_COB_PROM (VAR_1,VAR_2,VAR_3,VAR_4);
OWNER.LOAD_DATA_LOCAL.LOAD_CUP (VAR_1,VAR_2,VAR_3,VAR_4);
end;
--comments => 'Ejecuta LOAD_prueba_cupones'
--);
end;
我在这里猜测是因为我无法测试代码,但是乍一看似乎存在一些语法错误。