请帮我解决使用Oracle数据库的以下SQL问题
提示: 按升序PK序列列出仓库表的所有列。 •仅列出地址以RD或ST结尾的行
SELECT *
FROM warehouse
WHERE address ='% rd'
OR WHERE address ='% st',
ORDER BY whid ASC;
错误消息:
OR WHERE address ='%st',*
第4行出错:ORA-00936:表达式缺失
答案 0 :(得分:1)
您不需要第二个WHERE
,也应该删除逗号。此外,您可能希望在地址之前有LIKE
,并且您可能不希望拥有空格。
我认为你的意思是:
SELECT *
FROM warehouse
WHERE address LIKE '%rd'
OR address LIKE '%st'
ORDER BY whid ASC;
或者,你可能很聪明:
-- You don't say this explicitly, but I think it a good idea to make sure that
-- you are searching for rd and st in the right tense. That is why I have 'lower'
SELECT *
FROM warehouse
WHERE lower(substr(address,-2,2)) in ('rd', 'st')
ORDER BY whid ASC;
答案 1 :(得分:1)
删除第二个WHERE
语句,并将等效语句更改为LIKE
。
SELECT *
FROM warehouse
WHERE address LIKE '% rd'
OR address LIKE '% st'
ORDER BY whid ASC;
如果您在那里有等效语句,则只会匹配完全等于% rd
或% st
的字符串。
答案 2 :(得分:0)
摆脱第二个WHERE
,使用LIKE
代替=
并尝试删除%
字符后的空格。
SELECT *
FROM warehouse
WHERE address LIKE '%rd'
OR address LIKE '%st'
ORDER BY whid ASC;
答案 3 :(得分:0)
使用LIKE关键字:
SELECT * FROM warehouse WHERE address LIKE '%RD' OR address LIKE '%ST' ORDER BY whid ASC;