Home > Database > Mysql Tutorial > How to Correctly Use 'SELECT INTO' in Oracle to Avoid ORA-00905 Errors?

How to Correctly Use 'SELECT INTO' in Oracle to Avoid ORA-00905 Errors?

Mary-Kate Olsen
Release: 2025-01-04 06:09:43
Original
788 people have browsed it

How to Correctly Use

Troubleshooting "SELECT INTO" Error in Oracle

The "SELECT INTO" statement in Oracle, which inserts the results of a SELECT query into a new or existing table, can result in an ORA-00905 "missing keyword" error. This error message indicates a discrepancy between the Oracle implementation and the expected standard behavior.

Oracle Implementation:

Unlike the standard implementation, Oracle requires a different syntax for "SELECT INTO":

  • If the target table already exists:
    Use the "INSERT INTO ... SELECT" syntax:

    INSERT INTO new_table SELECT * FROM old_table;
    Copy after login
  • If the target table doesn't exist and you want to create it:
    Use the "CREATE TABLE ... AS SELECT" syntax:

    CREATE TABLE new_table AS SELECT * FROM old_table;
    Copy after login

Other Considerations:

If the target table exists and you want to create an empty duplicate, use the following syntax:

CREATE TABLE new_table AS SELECT * FROM old_table WHERE 1 = 2;
Copy after login

Remember that the "CREATE TABLE ... AS SELECT" method only creates a table with the same column projection as the source table. To add constraints, triggers, or indexes, you must manually create them separately.

The above is the detailed content of How to Correctly Use 'SELECT INTO' in Oracle to Avoid ORA-00905 Errors?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template