Home > Database > Mysql Tutorial > How to Resolve 'ORA-00936: missing expression' in Oracle 11g INSERT SELECT Statements?

How to Resolve 'ORA-00936: missing expression' in Oracle 11g INSERT SELECT Statements?

DDD
Release: 2024-12-29 19:24:16
Original
441 people have browsed it

How to Resolve

Troubleshooting an "ORA-00936" Error with an INSERT SELECT Statement in Oracle 11G

An "ORA-00936: missing expression" error can arise when executing an INSERT SELECT statement in Oracle 11G. Let's analyze a specific case to resolve this issue.

Problem:

A SQL statement attempts to insert data from a subquery into a table:

insert into table1 (col1, col2) values (select t1.col1, t2.col2 from oldtable1 t1, oldtable2 t2);
Copy after login

The subquery, when executed separately, operates correctly, retrieving rows from two tables, oldtable1 and oldtable2. However, when executed as the data source for the INSERT statement, the "ORA-00936: missing expression" error is encountered.

Solution:

The error stems from an incorrect syntax in the INSERT statement. The VALUES keyword is not necessary when utilizing a SELECT statement to populate the target table. The correct syntax should be:

insert into table1 (col1, col2)
select t1.col1, t2.col2 
from oldtable1 t1, oldtable2 t2
Copy after login

By omitting the VALUES portion, the INSERT statement correctly executes the subquery and populates table1 with the selected data.

The above is the detailed content of How to Resolve 'ORA-00936: missing expression' in Oracle 11g INSERT SELECT Statements?. For more information, please follow other related articles on the PHP Chinese website!

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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template