我有一個EMPLOYEE
表列(主鍵)EMPLOYEE_ID NUMBER(6)
爲什麼我得到ORA-01438錯誤
而下面的方法來檢查表中是否存在員工記錄
public boolean exists(int employeeId) {
Connection con = ConnectionManager.getConnection();
boolean exists = false;
String stmt = "select EMPLOYEE_ID , FIRST_NAME , LAST_NAME , EMAIL , PHONE_NUMBER ,"
+ "HIRE_DATE , JOB_ID , SALARY , COMMISSION_PCT , MANAGER_ID , DEPARTMENT_ID "
+ " FROM EMPLOYEES where cast (EMPLOYEE_ID as Number(2)) = ?";
PreparedStatement pstmt = null;
try {
pstmt = con.prepareStatement(stmt);
pstmt.setInt(1, employeeId);
pstmt.execute(); //Returns true if the first object that the query returns is a ResultSet object
exists = pstmt.getResultSet().next();
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
pstmt.close();
con.close();
} catch (Exception e) {
e.printStackTrace();
}
}
return exists;
}
現在,在SQL
語句時,我使用cast (EMPLOYEE_ID as Number(2)) = ?
並調用exists
方法與輸入2 employeeOperations.exists(2);
我收到以下錯誤
ORA-01438: value larger than specified precision allowed for this column
即使列的大小足夠大,爲什麼會發生此錯誤?
它適用於輸入4位或更多(表中employee_id的最大長度爲4),即cast (EMPLOYEE_ID as Number(4)) = ?
的作品。
爲什麼你鑄造號碼(2)?如果employee_id最多可以達到6,但爲什麼要施展? – tbone