Oracle 错误:ORA-00905:缺少关键字

发布于 2024-07-09 01:34:28 字数 167 浏览 8 评论 0原文

对 oracle 中的数据库执行 SQL

SELECT * 
  INTO assignment_20081120 
  FROM assignment ;

行来备份名为分配的表会出现以下 ORACLE 错误: ORA-00905: 缺少关键字

Excuting the line of 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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

明天过后 2024-07-16 01:34:28

除非 ASSIGNMENT 表中只有一行,并且 ASSIGNMENT_20081120ASSIGNMENT%ROWTYPE 类型的本地 PL/SQL 变量,否则这不是什么你要。

假设您正在尝试创建一个新表并将现有数据复制到该新表

CREATE TABLE assignment_20081120
AS
SELECT *
  FROM assignment

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.

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
醉梦枕江山 2024-07-16 01:34:28

首先,我想:

“...在 Microsoft SQL Server 中
SELECT...INTO 自动创建
新表,而 Oracle 似乎
需要您手动创建它
在执行SELECT...INTO之前
声明...”

但是手动生成表后还是不行,仍然显示“缺少关键字”的错误。

所以我这次放弃了,通过先手动创建表,然后使用“经典”< code>SELECT 语句:

INSERT INTO assignment_20081120 SELECT * FROM assignment;

如果有人能解释如何以正确的方式使用 SELECT...INTO,我会很高兴!

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 the SELECT...INTO
statement..."

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:

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!

情栀口红 2024-07-16 01:34:28

您可以在 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;

此代码仅在分配中恰好有 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;

You can use select into inside of a PLSQL block such as below.

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.

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;
寻找我们的幸福 2024-07-16 01:34:28

虽然这与OP的确切问题没有直接关系,但我刚刚发现在查询中使用Oracle保留字(在我的例子中是别名IN)可能会导致相同的错误。

示例:

SELECT * FROM TBL_INDEPENTS IN
JOIN TBL_VOTERS VO on IN.VOTERID = VO.VOTERID

或者如果它在查询本身中作为字段名称

 SELECT ..., ...., IN, ..., .... FROM SOMETABLE

,也会引发该错误。 我希望这可以帮助别人。

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.

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.

青春有你 2024-07-16 01:34:28

如果您备份 Oracle 数据库中的表。 你试试下面的说法。

CREATE TABLE name_table_bk
AS
SELECT *
  FROM name_table;

我正在使用 Oracle 数据库 12c。

If you backup a table in Oracle Database. You try the statement below.

CREATE TABLE name_table_bk
AS
SELECT *
  FROM name_table;

I am using Oracle Database 12c.

天邊彩虹 2024-07-16 01:34:28

迟到的回答,但我今天才出现在这个名单上!

CREATE TABLE assignment_20101120 AS SELECT * FROM assignment;

做同样的事。

Late answer, but I just came on this list today!

CREATE TABLE assignment_20101120 AS SELECT * FROM assignment;

Does the same.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文