0

Merge を使用する Oracle 用の SQL クエリを用意しました。ただし、Java のプリペアド ステートメントを使用しようとすると、次のエラーが発生します。

java.sql.SQLSyntaxErrorException: ORA-00923: FROM keyword not found where expected

at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:439)
at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:395)
at oracle.jdbc.driver.T4C8Oall.processError(T4C8Oall.java:802)
at oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:436)
at oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:186)
at oracle.jdbc.driver.T4C8Oall.doOALL(T4C8Oall.java:521)
at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:205)
at oracle.jdbc.driver.T4CPreparedStatement.executeForRows(T4CPreparedStatement.java:1008)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1307)
at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3449)
at oracle.jdbc.driver.OraclePreparedStatement.execute(OraclePreparedStatement.java:3550)
at oracle.jdbc.driver.OraclePreparedStatementWrapper.execute(OraclePreparedStatementWrapper.java:1374)
at ke.co.smart.MemberResponse.memberUpdater(MemberResponse.java:267)
at ke.co.smart.MemberResponse.<init>(MemberResponse.java:184)
at ke.co.smart.Switch.serviceProcessor(Switch.java:181)
at ke.co.smart.Switch.run(Switch.java:359)

以下は、実行のために準備したSQLステートメントです。

String sql = "MERGE INTO smart.tmp_switch_membership dest USING (SELECT "
                + membershipNumber + " member," + prevMembershipNumber + "," + schemeCode
                + "," + schemePlan + "," + memberPlan + "," + primaryCareProvider
                + "," + employeeNumber + "," + employerCode + "," + employerDesc
                + "," + brokerCode + "," + brokerDesc + "," + numberOfBeneficiaries.intValue()
                + " FROM DUAL) src ON (src.member = dest.membership_number) "
                + "WHEN NOT MATCHED THEN "
                + "INSERT(membership_number, prev_member_number, scheme_code,"
                + "scheme_plan, member_plan, primary_care_prov, correspondence_ind,"
                + "employee_number, employer_code, employer_desc, broker_agent_code,"
                + "broker_agent_desc, beneficiary_count) "
                + "VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
        PreparedStatement ps = con.prepareStatement(sql);
        ps.setString(1, membershipNumber);
        ps.setString(2, prevMembershipNumber);
        ps.setString(3, schemeCode);
        ps.setString(4, schemePlan);
        ps.setString(5, memberPlan);
        ps.setString(6, primaryCareProvider);
        ps.setString(7, employeeNumber);
        ps.setString(8, employerCode);
        ps.setString(9, employerDesc);
        ps.setString(10, brokerCode);
        ps.setString(11, brokerDesc);
        ps.setInt(12, numberOfBeneficiaries.intValue());
        ps.execute();
        con.commit();
        ps.close();

与えられた助けに感謝します。

4

2 に答える 2

3

SELECTキーワードの後に​​スペースはありません。スペースを確保する必要があります

"... dest USING (SELECT "
                      ^^^
于 2013-08-13T05:43:44.693 に答える
1

ここでもスペースを忘れました:

 + " FROM DUAL) src ON src.member = dest.membership_number"
            + "WHEN NOT MATCHED THEN"

に変更します

 + " FROM DUAL) src ON src.member = dest.membership_number "
            + "WHEN NOT MATCHED THEN "
于 2013-08-13T05:44:53.947 に答える