SQL Oracle 错误:ORA-00905:缺少关键字
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/305568/
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
Oracle error : ORA-00905: Missing keyword
提问by Justin Cave
Excuting the line of SQL:
执行SQL行:
SELECT *
INTO assignment_20081120
FROM assignment ;
against a database in oracle to back up a table called assignment gives me the following ORACLE error: ORA-00905: Missing keyword
针对 oracle 中的数据库备份名为 assignment 的表给了我以下 ORACLE 错误:ORA-00905:缺少关键字
回答by Justin Cave
Unless there is a single row in the ASSIGNMENT
table and ASSIGNMENT_20081120
is a local PL/SQL variable of type ASSIGNMENT%ROWTYPE
, this is not what you want.
除非ASSIGNMENT
表中ASSIGNMENT_20081120
只有一行并且是类型为 的本地 PL/SQL 变量,ASSIGNMENT%ROWTYPE
否则这不是您想要的。
Assuming you are trying to create a new table and copy the existing data to that new table
假设您正在尝试创建一个新表并将现有数据复制到该新表
CREATE TABLE assignment_20081120
AS
SELECT *
FROM assignment
回答by Uwe Keim
First, I thought:
首先,我想:
"...In Microsoft SQL Server the
SELECT...INTO
automatically creates the new table whereas Oracle seems to require you to manually create it before executing theSELECT...INTO
statement..."
“......在 Microsoft SQL Server 中,
SELECT...INTO
自动创建新表,而 Oracle 似乎要求您在执行SELECT...INTO
语句之前手动创建它......”
But after manually generating a table, it still did not work, still showing the "missing keyword" error.
但是手动生成表后,还是不行,依然显示“缺少关键字”的错误。
So I gave up this time and solved it by first manually creating the table, then using the "classic" SELECT
statement:
所以这次就放弃了,先手动建表,然后用“经典”SELECT
语句解决:
INSERT INTO assignment_20081120 SELECT * FROM assignment;
Which worked as expected. If anyone come up with an explanaition on how to use the SELECT...INTO
in a correct way, I would be happy!
这按预期工作。如果有人对如何以SELECT...INTO
正确的方式使用 提出解释,我会很高兴!
回答by Rene
You can use select into inside of a PLSQL block such as below.
您可以在 PLSQL 块中使用 select into ,如下所示。
Declare
l_variable assignment%rowtype
begin
select *
into l_variable
from assignment;
exception
when no_data_found then
dbms_output.put_line('No record avialable')
when too_many_rows then
dbms_output.put_line('Too many rows')
end;
This code will only work when there is exactly 1 row in assignment. Usually you will use this kind of code to select a specific row identified by a key number.
此代码仅在分配中正好有 1 行时才有效。通常您会使用这种代码来选择由键号标识的特定行。
Declare
l_variable assignment%rowtype
begin
select *
into l_variable
from assignment
where ID=<my id number>;
exception
when no_data_found then
dbms_output.put_line('No record avialable')
when too_many_rows then
dbms_output.put_line('Too many rows')
end;
回答by David
Late answer, but I just came on this list today!
迟到的答案,但我今天刚进入这个名单!
CREATE TABLE assignment_20101120 AS SELECT * FROM assignment;
CREATE TABLE assignment_20101120 AS SELECT * FROM assignment;
Does the same.
做同样的事。
回答by logixologist
Though this is not directly related to the OP's exact question but I just found out that using a Oracle reserved word in your query (in my case the alias IN
) can cause the same error.
虽然这与 OP 的确切问题没有直接关系,但我刚刚发现在查询中使用 Oracle 保留字(在我的情况下是 alias IN
)会导致相同的错误。
Example:
例子:
SELECT * FROM TBL_INDEPENTS IN
JOIN TBL_VOTERS VO on IN.VOTERID = VO.VOTERID
Or if its in the query itself as a field name
或者如果它在查询本身中作为字段名称
SELECT ..., ...., IN, ..., .... FROM SOMETABLE
That would also throw that error. I hope this helps someone.
那也会抛出那个错误。我希望这可以帮助别人。