SQL 错误:ORA-00933:SQL 命令未正确结束

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8940471/
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-01 14:05:02  来源:igfitidea点击:

SQL Error: ORA-00933: SQL command not properly ended

sqloracle

提问by Microsoft DN

I am trying to update a record in oracle SQL developer by using Joins. Following is my query-

我正在尝试使用联接更新 oracle SQL 开发人员中的记录。以下是我的查询-

UPDATE system_info set field_value = 'NewValue' 
FROM system_users users 
JOIN system_info info ON users.role_type = info.field_desc 
where users.user_name = 'uname'

However, when I tried to execute it, I got following error-

但是,当我尝试执行它时,出现以下错误-

Error report: SQL Error: ORA-00933: SQL command not properly ended 
              00933. 00000 - "SQL command not properly ended"

I tried removing JOINS

我尝试删除 JOINS

UPDATE system_info info 
SET info.field_value = 'NewValue' 
FROM system_users users 
where users.user_name = 'uname' AND users.role_type = info.field_desc

but still having same error can anybody tell me the error reason and solution

但仍然有同样的错误谁能告诉我错误原因和解决方案

采纳答案by a_horse_with_no_name

Oracle does not allow joining tables in an UPDATE statement. You need to rewrite your statement with a co-related sub-select

Oracle 不允许在 UPDATE 语句中连接表。您需要使用相关的子选择重写您的语句

Something like this:

像这样的东西:

UPDATE system_info
SET field_value = 'NewValue' 
WHERE field_desc IN (SELECT role_type 
                     FROM system_users 
                     WHERE user_name = 'uname')

For a complete description on the (valid) syntax of the UPDATE statement, please read the manual:

有关 UPDATE 语句的(有效)语法的完整说明,请阅读手册:

http://docs.oracle.com/cd/E11882_01/server.112/e26088/statements_10008.htm#i2067715

http://docs.oracle.com/cd/E11882_01/server.112/e26088/statements_10008.htm#i2067715

回答by ronIT

Semicolon ;on the end of command had caused the same error on me.

;命令末尾的分号对我造成了同样的错误。

cmd.CommandText = "INSERT INTO U_USERS_TABLE (USERNAME, PASSWORD, FIRSTNAME, LASTNAME) VALUES ("
                + "'" + txtUsername.Text + "',"
                + "'" + txtPassword.Text + "',"
                + "'" + txtFirstname.Text + "',"
                + "'" + txtLastname.Text + "');"; <== Semicolon in "" is the cause.
                                                      Removing it will be fine.

Hope it helps.

希望能帮助到你。

回答by yurin

Not exactly the case of actual context of this question, but this exception can be reproduced by the next query:

与此问题的实际上下文不完全相同,但可以通过下一个查询重现此异常:

update users set dismissal_reason='he can't and don't want' where userid=123

Single quotes in words can'tand don'tbroke the string. In case string have only one inside quote e.g. 'he don't want' oracle throws more relevant quoted string not properly terminatederror, but in case of two SQL command not properly endedis thrown.

单词中的单引号can'tdon't破坏了字符串。如果字符串只有一个引号,例如“他不想要”,oracle 会抛出更多相关的引号字符串未正确终止错误,但如果两个SQL 命令未正确结束,则会抛出。

Summary: check your query for double single quotes.

摘要:检查您的查询是否有双单引号。

回答by Zuber Surya

Your query should look like

您的查询应如下所示

UPDATE table_name
SET column1=value, column2=value2,...
WHERE some_column=some_value

You can check the below question for help

您可以查看以下问题寻求帮助

回答by abhijit

its very true on oracle as well as sql is "users" is a reserved words just change it , it will serve u the best if u like change it to this

它在 oracle 和 sql 上非常正确,“用户”是一个保留字,只需更改它,如果你喜欢将其更改为这个,它将为你提供最好的服务

UPDATE system_info set field_value = 'NewValue' 

FROM system_users users JOIN system_info info ON users.role_type = info.field_desc where users.user_name = 'uname'

FROM system_users users JOIN system_info info ON users.role_type = info.field_desc where users.user_name = 'uname'