成语大全网 - 成语接龙 - 如何在数据库里用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