日期:2014-05-16  浏览次数:20898 次

为什么like里面用[]和^不起作用
前提:我程序里面写死了用like来查询,不能用“not like”。
我查数据库的时候,我想查不是以“a”开头的那些数据。
用like怎么实现?(不用not like)

表头 column1 column2 column3
2 e e e
3 1
4 3
5 4
6 %a
7 b%
8 %b
9 a%
10 a*a
11 ^a ^b
12 abc eee ccc
我的oracle版本是10g,
查询语句是:
select * from ring_test t
where 1=1
and t.column1 like ('[^a]')
可是一条数据都查不出来,试了很多种形式,好像[]和^都用不了的样子。
请问高手问题出在哪里?

------解决方案--------------------
是不是你要的。楼主.希望能帮助你.
SQL code

WITH TEST AS (
SELECT 'e' AS column1,'e' AS column2,'e' AS column3 FROM DUAL
UNION
SELECT '1' AS column1,' ' AS column2,' ' AS column3 FROM DUAL
UNION
SELECT '3' AS column1,' ' AS column2,' ' AS column3 FROM DUAL
UNION
SELECT '4' AS column1,' ' AS column2,' ' AS column3 FROM DUAL
UNION
SELECT '%a' AS column1,' ' AS column2,' ' AS column3 FROM DUAL
UNION
SELECT 'b%' AS column1,' ' AS column2,' ' AS column3 FROM DUAL
UNION
SELECT '%b' AS column1,' ' AS column2,' ' AS column3 FROM DUAL
UNION
SELECT 'a%' AS column1,' ' AS column2,' ' AS column3 FROM DUAL
UNION
SELECT 'a*a' AS column1,' ' AS column2,' ' AS column3 FROM DUAL
UNION
SELECT '^a ^b' AS column1,' ' AS column2,' ' AS column3 FROM DUAL
UNION
SELECT 'abc' AS column1,'eee' AS column2,'ccc' AS column3 FROM DUAL
)

SELECT * FROM TEST WHERE   '1' = '1' and column1 not like 'a%' or 'xxxx' LIKE column1