我正在使用Java代码创建新的dbms_job,作业创建成功,但是处理失败,无法调用job_action。在job_action中,我正在调用过程来调用Oracle加载的Java代码。 Clob由json字符串组成。 似乎json格式导致oracle.sql.Clob对象出现问题。
我不确定,将json复制到json是否有任何问题。 为什么这里失败了?
java代码:
connection = DBBroker.getConnection();
stmt = (CallableStatement) connection.prepareCall("begin ? := PKGRESTASSIGNBLOCK.CREATEJOB(?, ?, ?); end;");
CLOB clob = null;
clob = CLOB.createTemporary(connection, false, CLOB.MODE_READWRITE);
clob.open(CLOB.MODE_READWRITE);
clob.setString(1, requestString);
stmt.registerOutParameter(1, java.sql.Types.VARCHAR);
stmt.setClob(2, clob);
stmt.setString(3, requestID);
stmt.setInt(4, requestType);
stmt.execute();
oracle过程:
CREATE OR REPLACE
PACKAGE BODY PKGRESTASSIGNBLOCK
AS
FUNCTION createjob(request IN CLOB, requestID IN VARCHAR2, type IN NUMBER) RETURN VARCHAR2
IS
l_jobname varchar2(1044);
BEGIN
BEGIN
l_jobname := NULL;
l_jobname := SUBSTR('JOB_IPBlk_' || requestID ||'_'|| to_char(SYSTIMESTAMP, 'yymmddhhmmssFF'), 0, 30);
DBMS_SCHEDULER.create_job(
job_name => l_jobname,
job_type => 'PLSQL_BLOCK',
job_action => 'begin pkgrestassignblock.assignblock ('|| request || ', ' || requestID || ', '|| type||'); end ;',
start_date => SYSTIMESTAMP,
repeat_interval => NULL,
end_date => NULL,
enabled => TRUE,
comments => 'Job defined entirely by the CREATE JOB procedure.');
END;
DBMS_OUTPUT.put_line ('l_jobname : ' ||l_jobname);
RETURN l_jobname;
END createjob;
PROCEDURE assignblock (request IN CLOB, requestID IN VARCHAR2, type IN NUMBER)
AS
LANGUAGE JAVA
NAME 'com.abcd.efgh.AssignBlock.handleRequest(java.sql.Clob, java.lang.String, java.lang.String, int)';
END PKGRESTASSIGNBLOCK;
oracle日志:
logs
ORA-12012: error on auto execute of job "JOB_BLK_20022019_19022008020"
ORA-06550: line 1, column 799:
PLS-00103: Encountered the symbol "{" when expecting one of the following:
( ) - + case mod new not null <an identifier>
<a double-quoted delimited-identifier> <a bind variable>
table continue avg count current exists max min prior sql
stddev sum variance execute multiset the both leading
trailing forall merge year month day hour minute second
timezone_hour timezone_minute timezone_region timezone_abbr
time timestamp interval date
<a string literal with character set specification>
Wed Feb 20 20:55:03 2019
Errors in file path/trace/CMM_j002_30847.trc:
ORA-12012: error on auto execute of job ""JOB_BLK_20022019_19022008020"
ORA-06550: line 1, column 756:
PLS-00306: wrong number or types of arguments in call to 'ASSIGNBLOCK'
ORA-06550: line 1, column 756:
PL/SQL: Statement ignored
答案 0 :(得分:0)
好吧,我认为您可能会遇到问题,因为job_action
是VARCHAR2
。我不确定是否将其限制为4000或32767个字符,但是如果您的JSON较长,无论哪种方式都可能破坏它。
但是,您的主要问题是您没有引用字符串。尝试更改此行:
job_action => 'pkgrestassignblock.assignblock('''|| request || ''', ''' || requestID || ''', '|| type||');',
我还删除了begin..end;
,因为该作业还是将动作包装在其自己的begin / end块中。