As I execute this SQLstatement
1: SELECT .....(ignore)
2: CASE
3: WHEN NIGT001.TAX_CD='15'
4: THEN (SELECT NIGT007.ADTR_NM
5: FROM NIGT007
6: WHERE NIGT001.PRST_ADTR_CD = NIGT007.ADTR_STAFF_CD(+) )
7: ELSE ''
8: END AS ADTR_NM
9: FROM NIGT001,NIGT013,NIGT007, ......(ignore)
10: WHERE ......(ignore)
11: ORDER BY .....(ignore)
It showed this error message
ORA-12704: 字元設定不符合
12704. 00000 - "character set mismatch"
*Cause: One of the following
- The string operands(other than an nlsparams argument) to an
operator or built-in function do not have the same character
set.
- An nlsparams operand is not in the database character set.
- String data with character set other than the database character
set is passed to a built-in function not expecting it.
- The second argument to CHR() or CSCONVERT() is not CHAR_CS or
NCHAR_CS.
- A string expression in the VALUES clause of an INSERT statement,
or the SET clause of an UPDATE statement, does not have the
same character set as the column into which the value would
be inserted.
- A value provided in a DEFAULT clause when creating a table does
not have the same character set as declared for the column.
- An argument to a PL/SQL function does not conform to the
character set requirements of the corresponding parameter.
*Action:
第 97 行, 資料欄: 133 發生錯誤
Root Cause
The problem result from NIGT007.ADTR_NM is NVARCHAR2.
But the case-when-else statement return empty string in else statement. The empty string is VARCHAR2.
That's why it complains "character set mismatch". What we need to do is do casting.
1: SELECT .....(ignore)
2: CASE
3: WHEN NIGT001.TAX_CD='15'
4: THEN (SELECT NIGT007.ADTR_NM
5: FROM NIGT007
6: WHERE NIGT001.PRST_ADTR_CD = NIGT007.ADTR_STAFF_CD(+) )
7: ELSE CAST('' as NVARCHAR2(10)) --do cast here
8: END AS ADTR_NM
9: FROM NIGT001,NIGT013,NIGT007,, ......(ignore)
10: WHERE ......(ignore)
11: ORDER BY .....(ignore)
No comments:
Post a Comment