oracle 从 ABCD 中选择名称,其中名称为“+aero+%”AND ROWNUM <= 10

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2378233/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 20:07:11  来源:igfitidea点击:

SELECT NAME FROM ABCD WHERE NAME LIKE "+aero+%"AND ROWNUM <= 10

sqloracle

提问by murali

SELECT NAME FROM ABCD WHERE NAME LIKE "+aero+%"AND ROWNUM <= 10

从 ABCD 中选择名称,其中名称为“+aero+%”AND ROWNUM <= 10

what is the syntax error in this line......SELECT NAME FROM ABCD this is working

这行的语法错误是什么......SELECT NAME FROM ABCD 这是有效的

回答by b.roth

You need singlequotes:

你需要引号:

SELECT NAME FROM ABCD WHERE NAME LIKE '+aero+%' AND ROWNUM <= 10

And also a space before AND.

AND 前还有一个空格。

UPDATE

更新

It's not clear in your question what exactly you're searching for. You may need one of the following instead:

在您的问题中不清楚您正在寻找什么。您可能需要以下其中一项:

SELECT NAME FROM ABCD WHERE NAME LIKE '"+aero+%"' AND ROWNUM <= 10

SELECT NAME FROM ABCD WHERE NAME LIKE '%"+aero+"%' AND ROWNUM <= 10

SELECT NAME FROM ABCD WHERE NAME LIKE '"%+aero+%"' AND ROWNUM <= 10

... or some other variation. But the important thing is that you should surrond literals with single quotes and not double quotes.

...或其他一些变化。但重要的是你应该用单引号而不是双引号来包围文字。

回答by Peter Lang

EDIT:

编辑:

con.prepareStatement(
    "SELECT name FROM abcd WHERE name LIKE '" + aero + "%' AND ROWNUM <= 10");

Will find all strings starting with your variable aero.

将查找以您的变量开头的所有字符串aero

To get all strings containing the String of your variable aerouse

要获取包含变量aero使用的字符串的所有字符串

con.prepareStatement(
    "SELECT name FROM abcd WHERE name LIKE '%" + aero + "%' AND ROWNUM <= 10");


You need to use single-quotes instead of double-quotes:

您需要使用单引号而不是双引号:

SELECT name
FROM abcd
WHERE name LIKE '+aero+%'
  AND ROWNUM <= 10;

If the double-quotes are in the string you search use '"+aero+%"'.

如果双引号在您搜索的字符串中,请使用'"+aero+%"'.

If you only want to search for strings containing aero, use '%aero%'.

如果您只想搜索包含 的字符串aero,请使用'%aero%'.

回答by GSerg

Double quotes around the literal?

文字周围的双引号?

No space between the literal and AND?

文字和 AND 之间没有空格?

回答by Pavunkumar

You need to give the character between the expression and AND operator . And give single quotes for your regular expression

您需要在表达式和 AND 运算符之间给出字符。并为您的正则表达式提供单引号

回答by YOU

If you called that from some program codes, following is more likely, where aerois the variable, and % would be acts as wildcard. When aero is ab, it will search for 'ab','abc', 'abcd', .......

如果您从某些程序代码中调用它,则更有可能出现以下情况,aero变量在哪里,% 将用作通配符。当 aero is 时ab,它会搜索'ab','abc', 'abcd', .......

"SELECT NAME FROM ABCD WHERE NAME LIKE '"+aero+"%' AND ROWNUM <= 10;"

回答by Tony Andrews

It isn't clear to me whether your aerois a literal string 'aero' or the name of a variable in your program. If it is a literal then do this:

我不清楚您的aero是文字字符串“aero”还是程序中变量的名称。如果它是文字,则执行以下操作:

pr = con.prepareStatement
         ("SELECT NAME FROM ABCD WHERE NAME LIKE 'aero%' AND ROWNUM <= 10");

If it is a variable then you should use a bind variable. Not only is the syntax much less confusing, it also prevents SQL injection attacks. I'm no ASP expert, but the syntax is something like:

如果它是一个变量,那么你应该使用一个绑定变量。不仅语法不那么混乱,它还可以防止 SQL 注入攻击。我不是 ASP 专家,但语法类似于:

pr = con.prepareStatement
         ("SELECT NAME FROM ABCD WHERE NAME LIKE ?||'%' AND ROWNUM <= 10");
con.setString(1,aero);