當前位置:成語大全網 - 八字成語 - 如何在數據庫裏用like語句查詢成語?

如何在數據庫裏用like語句查詢成語?

模式匹配符 LIKE,模式匹配符[NOT] LIKE 常用於模糊查詢,它判斷列值是否與指定的字符串格式匹配:

ASCII pattern matching with char column

CREATE TABLE t (col1 char(30))

INSERT INTO t VALUES ('Robert King')

SELECT *?

FROM t?

WHERE col1 LIKE '% King' ? -- returns 1 row

-- Unicode pattern matching with nchar column

CREATE TABLE t (col1 nchar(30))

INSERT INTO t VALUES ('Robert King')

SELECT *?

FROM t?

WHERE col1 LIKE '% King' ? -- no rows returned

-- Unicode pattern matching with nchar column and RTRIM

CREATE TABLE t (col1 nchar (30))

INSERT INTO t VALUES ('Robert King')

SELECT *?

FROM t?

WHERE RTRIM(col1) LIKE '% King' ? -- returns 1 row