【Tip】解决like中无法匹配下划线的问题

本文介绍在Oracle SQL中如何正确查询包含下划线的数据。由于下划线在LIKE语句中有特殊含义,文中提供了两种有效解决方案:使用转义字符和利用INSTR函数。
如果想检索出字段中包含下划线“_”的内容,该如何书写SQL语句呢?
之所以问这个问题,是因为在Oracle中下划线在like中有着特殊的含义,它表示匹配任意一个字符。因此在查询包含下划线内容的时候需要“特殊关照”一下。
既然被问到了这个问题,简单记录一下两种规避的方法,供参考。

1.创建实验表,并初始化三条数据
sec@ora10g> create table t (x varchar2(10));

Table created.

sec@ora10g> insert into t values ('sec');

1 row created.

sec@ora10g> insert into t values ('secooler');

1 row created.

sec@ora10g> insert into t values ('sec_ooler');

1 row created.

sec@ora10g> commit;

Commit complete.

2.确认表T中的数据,其中包含两条不带下划线的内容,一条带下划线的内容。
sec@ora10g> select * from t;

X
----------
sec
secooler
sec_ooler

3.使用like语句的错误查询
sec@ora10g> select * from t where x like '%_%';

X
----------
sec
secooler
sec_ooler

为什么错误?
因为在like语句中的下划线的含义是“任意一个字符”,类似“%”代表匹配任意多个字符的。

4.正确的查询方法
能想到的有如下两种方法。
1)第一种方法使用escape转义
sec@ora10g> select * from t where x like '%\_%' escape '\';

X
----------
sec_ooler

escape的内容可以任意,只要保证前后一致即可。
sec@ora10g> select * from t where x like '%|_%' escape '|';

X
----------
sec_ooler

sec@ora10g>  select * from t where x like '%*_%' escape '*';

X
----------
sec_ooler

2)使用instr函数辅助判断
使用instr函数判断字段中是否包含“_”,如果包含返回值是非零的,如果不包含则返回值是零。
sec@ora10g> select * from t where instr(x,'_')!=0;

X
----------
sec_ooler

3)
sec@ora10g> select ascii('_') from dual;

ASCII('_')
----------
        95

5.小结
任何语言都存在需要“特殊关照”的情况,这需要具体问题具体分析,发现一个问题解决一个问题,不积跬步无以至千里。

Good luck.

secooler
09.12.07

-- The End --

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/519536/viewspace-621900/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/519536/viewspace-621900/

design a plugin for files of screen-recording's moving to different disks of Xbox Game Bar in PC. reply in Chinese.the detailed of process, and necessary profiles and their codes(C series codes is required).(rules:1.detect and find the enough and largest space between the disks and list priority sequence,they're target disk(default mode) , customized mode is alternative;2. for the recording files, if choose default mode, set a default value such as 1GB for recordings and 10MB for screenshots, they all are based on the resolution of the screen(could find the minimum size of files of different resolutions to fill the default mode),it could customize the minimun size;3.for customize mode, it should detect 2 first and then is 1 to check whether the disks are allowed to move, if not, show popup window to tell the info and cancel(but don't pop the window when running a games), if enough, run the moving as what mode you've chosen, so do as default mode;4.for different games-recording, they could also be classified when moved to different disks or even the same disks but different files;5.for different games-recording, the files' sizes are smaller the customized values but not only one file, cumulating all of them first then run the rule 2 before the disks is full(it should set another default mode different before), and it could give the alternation like games(arrange it a new sequence based the number of most repeated names of games-recording, and the first one is the first to move the another do so), size & number(arrange it from larger to smaller, but they all need to smaller than size mentioned in rule 2,and then number are adjustable,and number of each moving files from larger and smaller will follow it,and first one is the first to move,the another do so)(it should set another customized mode different before);6.screenshot are alternative in the rule, but when it run the rule 4, it need to be classified to different subfolders(screenshot and recording) where the same games-capture folds in;7.when there is a game is running, pause the moving, especially the disk where the running games in;8.to avoid the difficulty of management with the scattered files, no need to run the rule 1 when every time(but not first time you reboot the computer after you install the plugin) of computer booting or game recording until the target disk's space is about to overflow(add timer(could adjustable) to detect it), no matter what mode you've chosen and then pop up to rechoose the mode;9.if the target disk is overflow when moving a file of game-recording, cancel to move it to the new chosen disk, add number as natural sequence in the files' name;10.to avoid to frequent moving of files, it could set a threshold of system disk, pop up the tip when the threshold is about to arrive before recording, threshold setting: it could choose proportion(%) or values(the customized space threshold of system disk),no need to add timer;11.choose the unused cores of CPU as priority;12.if all the disks are fullful,stop moving and popup the warning.13.the mentioned modes are alternative(which means there are third choose that to do nothing like without installing plugin),and all numbers mentioned above(expect popup window) of customized mode could be changed in Setting of Xbox Game Bar)
最新发布
06-30
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值