在 IF 语句中使用 'LIKE'
Using 'LIKE' inside IF statement
我需要使用条件对 table 进行排序。我使用了下面的语句,
select * from table1 order by if (col1 like '%Cochin%', substr(col1,1,4), col1)
但是我得到一个错误,"missing right parenthesis"。
使用这样的 CASE 语句:
SELECT *
FROM table1
ORDER BY CASE WHEN col1 LIKE '%Cochin%' THEN SUBSTR(col1,1,4)
ELSE col1 END
如果您使用的是 Oracle,
试试这个:
IF NOT REGEXP_LIKE(string, pattern) THEN
....
END IF;
我需要使用条件对 table 进行排序。我使用了下面的语句,
select * from table1 order by if (col1 like '%Cochin%', substr(col1,1,4), col1)
但是我得到一个错误,"missing right parenthesis"。
使用这样的 CASE 语句:
SELECT *
FROM table1
ORDER BY CASE WHEN col1 LIKE '%Cochin%' THEN SUBSTR(col1,1,4)
ELSE col1 END
如果您使用的是 Oracle,
试试这个:
IF NOT REGEXP_LIKE(string, pattern) THEN
....
END IF;