-2

请帮助我使用 Oracle 数据库解决以下 SQL 问题

PROMPT:按PK升序列出仓库表的所有列。• 仅列出地址以 RD 或 ST 结尾的行

SELECT *
FROM warehouse 
WHERE address ='% rd' 
OR WHERE address ='% st',
ORDER BY whid ASC;

错误信息:

OR WHERE 地址='%st', *

第 4 行出错:ORA-00936:缺少表达式

4

4 回答 4

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;
于 2013-04-24T00:12:28.953 回答
1

摆脱第二个WHERE语句,并将您的等价语句更改为LIKE.

SELECT *
FROM warehouse 
WHERE address LIKE '% rd' 
OR address LIKE '% st'
ORDER BY whid ASC;

如果那里有等价语句,您将只匹配完全等于% rdor的字符串% st

于 2013-04-24T00:12:58.203 回答
0

摆脱第二个WHERE,使用LIKE代替=并尝试删除%字符后的空格。

SELECT *
FROM warehouse 
WHERE address LIKE '%rd' 
OR address LIKE '%st'
ORDER BY whid ASC;
于 2013-04-24T00:11:31.040 回答
0

使用 LIKE 关键字:

SELECT * FROM warehouse WHERE address LIKE '%RD' OR address LIKE '%ST' ORDER BY whid ASC;
于 2013-04-24T00:15:31.107 回答