Ошибка ora 00913

Two tables are identical in terms of table name, column names, datatype and size. These tables are located in separate databases, but I am use to
current Log in in hr user.

insert into abc.employees select * from employees where employee_id=100; 

I can not give use original query from corporate office.

Error starting at line 1 in command:
insert into abc.employees select * from employees where employee_id=100; 

Error at Command Line:1 Column:25
Error report:
SQL Error: ORA-00913: too many values
00913. 00000 -  "too many values"
*Cause:    
*Action:

Kent Pawar's user avatar

Kent Pawar

2,3882 gold badges29 silver badges42 bronze badges

asked Sep 11, 2013 at 9:25

user2703444's user avatar

0

You should specify column names as below. It’s good practice and probably solve your problem

insert into abc.employees (col1,col2) 
select col1,col2 from employees where employee_id=100; 

EDIT:

As you said employees has 112 columns (sic!) try to run below select to compare both tables’ columns

select * 
from ALL_TAB_COLUMNS ATC1
left join ALL_TAB_COLUMNS ATC2 on ATC1.COLUMN_NAME = ATC1.COLUMN_NAME 
                               and  ATC1.owner = UPPER('2nd owner')
where ATC1.owner = UPPER('abc')
and ATC2.COLUMN_NAME is null
AND ATC1.TABLE_NAME = 'employees'

and than you should upgrade your tables to have the same structure.

answered Sep 11, 2013 at 9:26

Robert's user avatar

RobertRobert

25.4k8 gold badges67 silver badges81 bronze badges

8

The 00947 message indicates that the record which you are trying to send to Oracle lacks one or more of the columns which was included at the time the table was created.
The 00913 message indicates that the record which you are trying to send to Oracle includes more columns than were included at the time the table was created.
You just need to check the number of columns and its type in both the tables
ie the tables that are involved in the sql.

answered Sep 10, 2019 at 6:13

Anurag sinha's user avatar

0

If you are having 112 columns in one single table and you would like to insert data from source table, you could do as

create table employees as select * from source_employees where employee_id=100;

Or from sqlplus do as

copy from source_schema/password insert employees using select * from 
source_employees where employee_id=100;

answered Sep 11, 2013 at 9:40

Jacob's user avatar

JacobJacob

14.5k65 gold badges208 silver badges320 bronze badges

5

For me this works perfect

insert into oehr.employees select * from employees where employee_id=99

I am not sure why you get error. The nature of the error code you have produced is the columns didn’t match.

One good approach will be to use the answer @Parodo specified

answered Sep 11, 2013 at 10:15

Sarathi Kamaraj's user avatar

Sarathi KamarajSarathi Kamaraj

6573 gold badges9 silver badges26 bronze badges

this is a bit late.. but i have seen this problem occurs when you want to insert or delete one line from/to DB but u put/pull more than one line or more than one value ,

E.g:

you want to delete one line from DB with a specific value such as id of an item but you’ve queried a list of ids then you will encounter the same exception message.

regards.

answered May 4, 2014 at 8:49

In my case, the insert statement was missing one column, and so in select, I had one additional value. Adding the missing column in the insert statement fixed the error for me.

Hope it can help someone.

answered Sep 1 at 19:14

Arpit Jain's user avatar

Arpit JainArpit Jain

1,7569 silver badges24 bronze badges

totn Oracle Error Messages


Learn the cause and how to resolve the ORA-00913 error message in Oracle.

Description

When you encounter an ORA-00913 error, the following error message will appear:

  • ORA-00913: too many values

Cause

You tried to execute a SQL statement that required two sets of equal values, but you entered more items in the second set than was in the first set.

Resolution

The option(s) to resolve this Oracle error are:

Option #1

This error often occurs when you are performing a INSERT statement and enter more values in the VALUES clause than the number of columns that you listed.

For example, if you executed the following INSERT statement:

INSERT INTO suppliers
(supplier_id, supplier_name)
VALUES
(1000, 'Microsoft', 'Bill Gates');

In this example, you’ve chosen to insert values into 2 columns (supplier_id and supplier_name), but you’ve entered 3 values (1000, Microsoft, and Bill Gates).

You need to modify your INSERT statement so there are the same number of columns as there are values. For example:

INSERT INTO suppliers
(supplier_id, supplier_name)
VALUES
(1000, 'Microsoft');

Option #2

This error can also occur when your subquery in the WHERE clause returns too many columns.

For example, if you executed the following SQL statement:

SELECT *
FROM suppliers
WHERE supplier_id > 5000
AND supplier_id IN (SELECT * FROM products
                    WHERE product_name LIKE 'H%);

In this example, the subquery returns all columns from the products table. You need to modify the subquery to return only one column as follows:

SELECT *
FROM suppliers
WHERE supplier_id > 5000
AND supplier_id IN (SELECT product_id FROM products
                    WHERE product_name LIKE 'H%);

ORA-00913

ORA-00913: слишком много значений

Причина:

Ваш SQL оператор требует два набора значений эквивалентных по количеству, но второе множество содержит больше элементов, чем первое множество. Например, подзапрос в WHERE и HAVING предложении может возвратить слишком много колонок, или VALUES и SELECT предложение может возвратить более колонок, чем определено в INSERT.

Действие:

Проверьте число элементов в каждом множестве и измените SQL операторы для того чтобы сделать их эквивалентными.

SQL Error: ORA-00913: too many values issue appears when you enter more column values in the VALUES / SELECT clauses than the number of columns required in the insert statement. The values in the VALUES clause are more than what is needed by the insert statement. If you try to run an insert statement with too many values in the VALUES / SELECT clause, the insert statement will fail to insert the values into the table. Oracle throws the ORA-00913: too many values error in this scenario.

The SQL Error: ORA-00913: too many values error occurs in the select subqueries. If the number of columns returned by the subquery is more than the number of columns required by the outer query, the outer query will be unable to handle the data returned by the inner query. Oracle throws the error in this scenario.

The SQL statement such as insert and select requires two sets of values that are equal in number. The datatype and order of the column should be same in each sets. The second set will be in VALUES / SELECT clause. If the second set contains more items than the first set, then the oracle error SQL Error: ORA-00913: too many values occurs. If the subquery returns too many column values in the WHERE or HAVING clause, the outer query will fail to process.

When this ORA-00913 Error occur

The error SQL Error: ORA-00913: too many values occurs if the values or select clause returns more columns than the necessary columns in the insert statement. Also, if the subquery produces more column values than the main query requires, the error will occur. In the example below the employee table contains two columns id and name. The insert statement value clause contains three values. These three values could not insert into the table that contains only two columns.

create table emp (
id int,
name varchar2(100)
);
insert into EMP values(1,'emp1',1000);

Error

Error starting at line : 12 in command -
insert into EMP values(1,'emp1',1000)
Error at Command Line : 12 Column : 13
Error report -
SQL Error: ORA-00913: too many values
00913. 00000 -  "too many values"

Root Cause

This SQL Error: ORA-00913: too many values error occurs if the number of columns returned in the values or select clause exceeds the number of columns required in the insert statement. The insert statement was unable to find the extra column in the table, or the extra column is irrelevant to the table.

Solution 1

Remove the additional column in the values clause if the extra column value is provided in the insert statement. If the table needs an additional column, modify the table and add the required column. The number of column values in the values clause should be the same as the number of columns in the table. Check the table’s columns and make changes.

Problem

create table emp (
id int,
name varchar2(100)
);
insert into EMP values(1,'emp1',1000);

Error report -
SQL Error: ORA-00913: too many values
00913. 00000 -  "too many values"

Solution

insert into EMP values(1,'emp1');
1 row inserted.
create table emp (
id int,
name varchar2(100),
salary int
);
insert into EMP values(1,'emp1',1000);
1 row inserted.

Solution 2

The insert statement requires two sets of values equal in number. This SQL Error: ORA-00913: too many values occurs when the second set contains more items than the first set. The error will occur if the number of columns in the values column exceeds the number of inserted columns. The numbers of columns in the values clause should be matched by the inserted columns.

Problem

create table emp (
id int,
name varchar2(100),
salary int
);
insert into emp (id,name) values(1,'emp1',1000);

Error report -
SQL Error: ORA-00913: too many values
00913. 00000 -  "too many values"

Solution

insert into emp (id,name,salary) values(1,'emp1',1000);
1 row inserted.
insert into emp (id,name) values(1,'emp1');
1 row inserted.

Solution 3

In the insert statement, if a select statement returns too many values, the insert statement cannot add the data to the table. The select statement’s returning set must match the entered columns. The returned columns should be deleted in the select statement, or the needed columns should be specified in the insert statement.

Problem

create table emp (
id int,
name varchar2(100)
);

create table manager (
id int,
name varchar2(100),
salary int
);

insert into emp as select * from manager;

Error report -
SQL Error: ORA-00913: too many values
00913. 00000 -  "too many values"

Solution

insert into emp as select id, name from manager;
1 row inserted.

insert into emp(id, name) as select id, name from manager;
1 row inserted.
create table emp (
id int,
name varchar2(100),
salary int
);

insert into emp as select * from manager;
1 row inserted.

Solution 4

The returned set in the subqueries should match the main query in the select subqueries. This error SQL Error: ORA-00913: too many values can also occur if your subquery in the WHERE clause produces too many columns values. If the subquery returns all columns from the table, you must change it to return only one column.

Problem

create table emp (
id int,
name varchar2(100),
salary int
);

create table manager (
id int,
name varchar2(100),
salary int
);

select * from emp where id in (select * from manager);

ORA-00913: too many values
00913. 00000 -  "too many values"

Solution

The subquery returns all column values from the manager table. In the main query where clause requires only id values. As the subquery returns too many values, the error occurs. In the query below returns only id column from the manager table. where clause matches id column value from manager table to id column value from employee table.

select * from emp where id in (select id from manager);

September 17, 2020

Hi,

I got ” ORA-00913: too many values ” error in Oracle.

ORA-00913: too many values

Details of error are as follows.

ORA-00913: too many values
Cause: The SQL statement requires two sets of values equal in number. This error occurs when the second set contains more items than the first set. For example, the subquery in a WHERE or HAVING clause may return too many columns, or a VALUES or SELECT clause may return more columns than are listed in the INSERT.

Action: Check the number of items in each set and change the SQL statement to make them equal.


ORA-00913 error is related with the SQL statement that required two sets of equal values, you should enter more items in the second set than first set as follows.

INSERT INTO test_table
(name,last_name)
VALUES
('Mehmet', 'Deveci',1453);

ORA-00913: too many values

too many values

Check your Insert statement and don’t use the too many values in the VALUES clause. Fix the above Insert script as follows.

INSERT INTO test_table (name,last_name) VALUES ('Mehmet', 'Deveci');

ORA-00913

ORA-00913: too many values error is seen when subquery in the WHERE clause returns too many columns as follows.

SELECT *
FROM TEST_TABLE
WHERE id > 63
AND id IN (SELECT * FROM employee
WHERE name LIKE 'MEH%);

You should fix above SQL Statement as follows.

SELECT *
FROM TEST_TABLE
WHERE id > 63
AND id IN (SELECT id FROM employee
WHERE name LIKE 'MEH%);

Sometimes ORA-00913 is associated with the 2227755 bug, if you see this bug, upgrade your database or patch the Oracle version.

Do you want to learn Oracle SQL, then read the following articles.

Oracle SQL Tutorials For Beginners – Learn Oracle SQL from scratch with Oracle SQL Online Course

Понравилась статья? Поделить с друзьями:
  • Ошибка optifine 1282
  • Ошибка ora 00900
  • Ошибка jvcu 520428
  • Ошибка ora 00257 archiver error
  • Ошибка jsonexception no value for type что это