[20260309]使用oracle正则表达式问题.txt
--//tpt以及包括自己写的sql工具脚本使用oracle正则表达式,在使用中还是遇到一些细节问题,做一些概况总结,避免以后遇到时在这
--//方面浪费时间。
--//首先使用oracle正则表达式比较灵活方便,虽然执行效率不高,一般这类查询不必考虑这方面因素。
1.环境:
SYS@book> @ ver2
==============================
PORT_STRING : x86_64/Linux 2.4.xx
VERSION : 21.0.0.0.0
BANNER : Oracle Database 21c Enterprise Edition Release 21.0.0.0.0 - Production
BANNER_FULL : Oracle Database 21c Enterprise Edition Release 21.0.0.0.0 - Production
Version 21.3.0.0.0
BANNER_LEGACY : Oracle Database 21c Enterprise Edition Release 21.0.0.0.0 - Production
CON_ID : 0
PL/SQL procedure successfully completed.
2.问题1:
SYS@book> @ hidez filesystemio_op|^_small_table_threshold$|
NUM N_HEX CON_ID NAME DESCRIPTION DEFAULT_VALUE SESSION_VALUE SYSTEM_VALUE ISSES ISSYS_MOD
---- ----- ------ ---------------------- ---------------------------------------------------- ------------- ------------- ------------ ----- ---------
1867 74B 0 _small_table_threshold lower threshold level of table size for direct reads TRUE 1018 1018 TRUE DEFERRED
--//本来想查询2个参数值,实际上仅仅显示1个,主要问题参数最后多了1个| ,删除最后的|正常。
SYS@book> @ hidez filesystemio_op|^_small_table_threshold$
NUM N_HEX CON_ID NAME DESCRIPTION DEFAULT_VALUE SESSION_VALUE SYSTEM_VALUE ISSES ISSYS_MOD
---- ----- ------ ---------------------- ---------------------------------------------------- ------------- ------------- ------------ ----- ---------
431 1AF 0 filesystemio_options IO operations on filesystem files FALSE NONE NONE FALSE FALSE
1867 74B 0 _small_table_threshold lower threshold level of table size for direct reads TRUE 1018 1018 TRUE DEFERRED
--//说句真心话,这个错误很不好理解,我开始以为这样应该是像*那样全部输出。如果在结尾加入空格+双引号:
SYS@book> @ hidez "filesystemio_op|^_small_table_threshold| "
NUM N_HEX CON_ID NAME DESCRIPTION DEFAULT_VALUE SESSION_VALUE SYSTEM_VALUE ISSES ISSYS_MOD
---- ----- ------ ---------------------- ---------------------------------------------------- ------------- ------------- ------------ ----- ---------
431 1AF 0 filesystemio_options IO operations on filesystem files FALSE NONE NONE FALSE FALSE
1867 74B 0 _small_table_threshold lower threshold level of table size for direct reads TRUE 1018 1018 TRUE DEFERRED
--//这样相当于多查询匹配空格的情况。
--//看看grep的情况:
$ cat m8.txt
set serveroutput on
DECLARE
L_TRSH NUMBER;
BEGIN
L_TRSH := GET_ADR_TRSH(10, &&1, &&2);
DBMS_OUTPUT.PUT_LINE(L_TRSH);
END;
/
$ grep -E "L_|PUT|" m8.txt
set serveroutput on
DECLARE
L_TRSH NUMBER;
BEGIN
L_TRSH := GET_ADR_TRSH(10, &&1, &&2);
DBMS_OUTPUT.PUT_LINE(L_TRSH);
END;
/
--//原样输出,相当于执行:
$ grep "" m8.txt
set serveroutput on
DECLARE
L_TRSH NUMBER;
BEGIN
L_TRSH := GET_ADR_TRSH(10, &&1, &&2);
DBMS_OUTPUT.PUT_LINE(L_TRSH);
END;
/
$ grep -E "L_|PUT" m8.txt
L_TRSH NUMBER;
L_TRSH := GET_ADR_TRSH(10, &&1, &&2);
DBMS_OUTPUT.PUT_LINE(L_TRSH);
$ egrep "L_|PUT|" m8.txt
set serveroutput on
DECLARE
L_TRSH NUMBER;
BEGIN
L_TRSH := GET_ADR_TRSH(10, &&1, &&2);
DBMS_OUTPUT.PUT_LINE(L_TRSH);
END;
/
$ egrep "L_|PUT" m8.txt
L_TRSH NUMBER;
L_TRSH := GET_ADR_TRSH(10, &&1, &&2);
DBMS_OUTPUT.PUT_LINE(L_TRSH);
3.问题2:
--//注意一些特殊字符的转义,特别是$.
SYS@book> @ tab2z ^source$
Show tables matching condition "^source$" (if schema is not specified then current user's tables only are shown)...
no rows selected
--//这样相当于查询source表,不是source$表。
--//转义一下就可以了。
SYS@book> @ tab2z ^source\$$
Show tables matching condition "^source\$$" (if schema is not specified then current user's tables only are shown)...
OWNER TABLE_NAME TYPE NUM_ROWS BLOCKS EMPTY AVGSPC ROWLEN TAB_LAST_ANALYZED DEGREE COMPRESS
----- ---------- ---- ------------ ------------- --------- ------ ------ ------------------- ---------- --------
SYS SOURCE$ TAB 315753 5096 0 0 88 2024-09-01 08:50:17 1 DISABLED
--//还有的情况如下:
SYS@book> @ ses2z 219 "physical reads direct|table scans (direct read)"
SID NAME VALUE
---------- ---------------------------------------- ----------
219 physical reads direct 8000
--//这样仅仅查询到1个。实际上单括号也要转义。
SYS@book> @ ses2z 219 "physical reads direct|table scans \(direct read\)"
SID NAME VALUE
---------- ---------------------------------------- ----------
219 physical reads direct 8000
219 table scans (direct read) 1
--//目前遇到的问题就是这些,加以注意就可以了。