我在oracle' official document中找到了这个:
只有ASCII等效的下划线(_)和百分号(%)字符 被识别为模式匹配字符。他们的全宽变种, 出现在东亚字符集和Unicode中,被视为 普通人物。
但奇怪的是,我的全宽百分比符号%的作用就像半宽%,下面是我的java代码:
Class.forName( "oracle.jdbc.driver.OracleDriver" );
Connection conn = DriverManager.getConnection( "jdbc:oracle:thin:@******", "***", "***" );
Statement stmt = conn.createStatement();
stmt.execute("select * from v$nls_parameters");
ResultSet rs = stmt.getResultSet();
while(rs.next()) {
System.out.println(rs.getString(1) + ": " + rs.getString(2));
}
stmt.execute("select * from dual where '123' like '12%'");
rs = stmt.getResultSet();
while(rs.next()) {
System.out.println(rs.getString(1));
}
输出结果为:
NLS_LANGUAGE: JAPANESE
NLS_TERRITORY: JAPAN
NLS_CURRENCY: ¥
NLS_ISO_CURRENCY: JAPAN
NLS_NUMERIC_CHARACTERS: .,
NLS_CALENDAR: GREGORIAN
NLS_DATE_FORMAT: RR-MM-DD
NLS_DATE_LANGUAGE: JAPANESE
NLS_CHARACTERSET: AL32UTF8
NLS_SORT: BINARY
NLS_TIME_FORMAT: HH24:MI:SSXFF
NLS_TIMESTAMP_FORMAT: RR-MM-DD HH24:MI:SSXFF
NLS_TIME_TZ_FORMAT: HH24:MI:SSXFF TZR
NLS_TIMESTAMP_TZ_FORMAT: RR-MM-DD HH24:MI:SSXFF TZR
NLS_DUAL_CURRENCY: \
NLS_NCHAR_CHARACTERSET: UTF8
NLS_COMP: BINARY
NLS_LENGTH_SEMANTICS: BYTE
NLS_NCHAR_CONV_EXCP: FALSE
X
但奇怪的是,在sqlplus中:
SQL> select * from dual where '123' like '12%';
no rows selected
而且,会话的nls参数现在不同了:
SQL> select * from v$nls_parameters;
PARAMETER VALUE
------------------------------------- ----------------------------------------------------------------
NLS_LANGUAGE AMERICAN
NLS_TERRITORY AMERICA
NLS_CURRENCY $
NLS_ISO_CURRENCY AMERICA
NLS_NUMERIC_CHARACTERS .,
NLS_CALENDAR GREGORIAN
NLS_DATE_FORMAT DD-MON-RR
NLS_DATE_LANGUAGE AMERICAN
NLS_CHARACTERSET AL32UTF8
NLS_SORT BINARY
NLS_TIME_FORMAT HH.MI.SSXFF AM
NLS_TIMESTAMP_FORMAT DD-MON-RR HH.MI.SSXFF AM
NLS_TIME_TZ_FORMAT HH.MI.SSXFF AM TZR
NLS_TIMESTAMP_TZ_FORMAT DD-MON-RR HH.MI.SSXFF AM TZR
NLS_DUAL_CURRENCY $
NLS_NCHAR_CHARACTERSET UTF8
NLS_COMP BINARY
NLS_LENGTH_SEMANTICS BYTE
NLS_NCHAR_CONV_EXCP FALSE
19 rows selected.
非常感谢任何帮助。
答案 0 :(得分:0)
我建议转义特殊字符%_(加上转义字符本身),比如
从*中选择*,其中'123'喜欢'12 \%'逃脱'\'