错误:
ORA-00932:不一致的数据类型:预期NUMBER得到CHAR
SQL:
SELECT CASE WHEN
(
SELECT COUNT(COMP_CODE) FROM COMPANY_MASTER
)=0 THEN 1
ELSE
(
SELECT LPAD((SELECT MAX(COMP_CODE)+1 FROM COMPANY_MASTER),3, 0) NOS FROM DUAL
)
END AS DOCNO FROM DUAL;
答案 0 :(得分:3)
if-else的两个分支都应该返回相同的类型。如果else
分支返回一个字符串(这是lpad
的返回值),那么if
分支也应如此。 E.g:
SELECT CASE WHEN
(
SELECT COUNT(COMP_CODE) FROM COMPANY_MASTER
)=0 THEN '1' -- '1' is a string literal
ELSE
(
SELECT LPAD((SELECT MAX(COMP_CODE)+1 FROM COMPANY_MASTER),3, 0) NOS FROM DUAL
)
END AS DOCNO FROM DUAL;