Clob errorORA-01704: string literal too long

2630 단어 Oaclesql
Clob 필드 는 SQL 구문 에서 문자열 로 처리 할 수 있 습 니 다.
그러나 문자열 의 길이 가>4000 일 때 error ORA-01704:string literal too long 오류 가 발생 합 니 다.
SQL 문 구 는 허용 되 는 길 이 를 초과 해 PL/SQL 에서 더 짧게 제 한 될 수 있 기 때문이다.
처리 방법:
자바 에 서 는 prepared Statement 을 참조 할 수 있 습 니 다.PL/SQL 에 서 는 변 수 를 사용 할 수 있 습 니 다.
tomcat 6.0 과 weblogic 9.2 테스트 통과

/**
	 * @param conn
	 *              
	 * @param table
	 *              
	 * @param idColumn
	 *                   
	 * @param idValue
	 *                  
	 * @param clobColumn
	 *            CLOB  
	 * @param clobValue
	 *            CLOB 
	 * @return
	 */
	public int updateClob(Connection conn, String table, String idColumn, String idValue, String clobColumn,
			String clobValue) {
		int se = -1;
		ResultSet rs = null;
		PreparedStatement pst = null;
		boolean defaultCommit = true;
		try {
			defaultCommit = conn.getAutoCommit();
			conn.setAutoCommit(false);


			//   Clob    
			String updateToEmptySql = "UPDATE " + table + " SET " + clobColumn + " = EMPTY_CLOB() WHERE " + idColumn
					+ "='" + idValue + "'";
			pst = conn.prepareStatement(updateToEmptySql);
			pst.executeUpdate();

			//   Clob  
			String getForUpdateSql = "select " + clobColumn + " from " + table + " where " + idColumn + " = '"
					+ idValue + "' for update";
			pst = conn.prepareStatement(getForUpdateSql);
			rs = pst.executeQuery();

			if (rs.next()) {
				oracle.sql.CLOB clob = (oracle.sql.CLOB) (rs.getClob(clobColumn));
				clob.putString(1, clobValue);
				String sql = "update " + table + " set " + clobColumn + "=? where " + idColumn + "='" + idValue + "'";
				pst = conn.prepareStatement(sql);
				pst.setClob(1, clob);
				se = pst.executeUpdate();
				conn.commit();
				conn.setAutoCommit(defaultCommit);
			}
		} catch (SQLException e) {
			se = -1;
			try {
				conn.rollback();
			} catch (SQLException e1) {
				e1.printStackTrace();
			}
			e.printStackTrace();
		} finally {
			try {
				if (rs != null) {
					rs.close();
				}
				if (pst != null) {
					pst.close();
				}
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
		return se;
	}

좋은 웹페이지 즐겨찾기