如何判断一个字符串是否含有汉字?
利用LENGTH、LENGTHB和TO_SINGLE_BYTE函数来解决这个问题。
SYS@lhrdb> CREATE TABLE AA (COL VARCHAR2(255));
Table created.
SYS@lhrdb> INSERT INTO AA (COL) VALUES ('1');
1 row created.
SYS@lhrdb> INSERT INTO AA (COL) VALUES ('2');
1 row created.
SYS@lhrdb> INSERT INTO AA (COL) VALUES ('小麦苗');
1 row created.
SYS@lhrdb> COMMIT;
Commit complete.
SYS@lhrdb> SELECT * FROM AA;
COL
----------
1
2
小麦苗
SYS@lhrdb> COL COL FORMAT A10
SYS@lhrdb> COL SINGLE_COL FORMAT A10
SYS@lhrdb> SELECT A.COL COL,
2 TO_SINGLE_BYTE(A.COL) SINGLE_COL,
3 LENGTH(A.COL) LENGTH_COL,
4 LENGTHB(A.COL) LENGTHB_COL,
5 LENGTH(TO_SINGLE_BYTE(A.COL)) SINGLE_LENGTH_COL,
6 LENGTHB(TO_SINGLE_BYTE(A.COL)) SINGLE_LENGTHB_COL
7 FROM AA A
8 WHERE LENGTHB(A.COL) <> LENGTH(A.COL)
9 AND LENGTHB(TO_SINGLE_BYTE(A.COL)) <> LENGTH(TO_SINGLE_BYTE(A.COL));
COL SINGLE_COL LENGTH_COL LENGTHB_COL SINGLE_LENGTH_COL SINGLE_LENGTHB_COL
---------- ---------- ---------- ----------- ----------------- ------------------
小麦苗 小麦苗 3 6 3 6