SQL Error: ORA-00913: too many values - sql

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:

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.

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.

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;

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

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.

Related

Insert table from one database into another database

I want to copy a table to another database server in SQL developer.
I use this method to solve this problem.
INSERT INTO mahdi-jiradb..empier SELECT * FROM tamindb..users;
but i get an error:
Error starting at line : 8 in command -
INSERT INTO mahdi-jiradb..empier
SELECT * FROM tamindb..users
Error at Command Line : 8 Column : 18
Error report -
SQL Error: ORA-00926: missing VALUES keyword
00926. 00000 - "missing VALUES keyword"
*Cause:
*Action:
What should i do?
As you commented, it looks as if you use Oracle.
In that case, schema name can't contain a "minus" sign (mahdi-jiradb) so that's probably underline (mahdi_jiradb) instead.
SQL> create user mahdi-jiradb identified by test;
create user mahdi-jiradb identified by test
*
ERROR at line 1:
ORA-00922: missing or invalid option
Unless, of course, you enclosed username into double quotes (but now you have to use it always, everywhere):
SQL> create user "mahdi-jiradb" identified by test;
User created.
Presuming that that's not the case, schema name is wrong. Check it.
Also, use one dot to separate schema name from table name.
Something like this might work:
INSERT INTO mahdi_jiradb.empier SELECT * FROM tamindb.users;
presuming that both tables share the same description. That's why it is better to explicitly name all columns involved, e.g.
INSERT INTO mahdi_jiradb.empier (user_id, user_name)
SELECT uid, uname FROM tamindb.users;

Using dot notation with sum() to query the same, but multiple columns, in multiple databases

SQLite
There are multiple databases, one database for each time period (i.e. quarter). The column headers in each table are the same. Some of the columns. The data is identical between databases (e.g. ID, Name, Address, State, Website, etc). Some of the columns, the column header is the same but the
data in the column is different between databases.
The goal is to:
Select multiple columns from multiple databases, sum each column, convert the output from 000000000 to $000,000,000,000, adding three zero's to the output
(currently the data is represented in 000's).
Following is an iteration of queries that work, ending in the queries that fail.
Selecting one column from one database. This query works.
select dep
From AllReports19921231AssetsAndLiabilities;
output
"11005"
"34396"
"42244"
Adding a sum(columnName) method to this same query works.
select sum(dep)
From AllReports19921231AssetsAndLiabilities;
results: 3562807353
Attempting to sum(columnName) from multiple databases causes an error.
select sum(dep)
From AllReports19921231AssetsAndLiabilities,
AllReports19930331AssetsAndLiabilities;
error:
ambiguous column name: dep: select sum(dep)
From AllReports19921231AssetsAndLiabilities,
AllReports19930331AssetsAndLiabilities;
Using dot notation to attach a database to a column. Query works.
select AllReports19921231AssetsAndLiabilities.dep
From AllReports19921231AssetsAndLiabilities;
Output:
"11005"
"34396"
"42244"
However when I attempt to include dot notation and add sum(columnName) to the query, it fails.
select AllReports19921231AssetsAndLiabilities.sum(dep)
From AllReports19921231AssetsAndLiabilities;
I receive this error:
near "(": syntax error: select AllReports19921231AssetsAndLiabilities.sum(
What are correct ways to write this query?
The end goal is to select the same columns (e.g. col1, col2, col3, etc) from multiple databases (Q1, Q2, Q3, Q4).
Sum each column, add three zero's the output, then convert from 000000000 to $000,000,000,000
Note: There are 103 databases (i.e. one for each time period/quarter).
select AllReports19921231AssetsAndLiabilities.sum(dep),
AllReports19930331AssetsAndLiabilities.sum(dep),
AllReports19930630AssetsAndLiabilities.sum(dep)
From AllReports19921231AssetsAndLiabilities,
AllReports19930331AssetsAndLiabilities,
AllReports19930630AssetsAndLiabilities;
The above query outputs an error:
near "(": syntax error: select AllReports19921231AssetsAndLiabilities.sum(
Your syntax is wrong :
select sum(AllReports19921231AssetsAndLiabilities.dep)
From AllReports19921231AssetsAndLiabilities
Learn to use aliases!
select sum(aal.dep)
From AllReports19921231AssetsAndLiabilities aal;
The query is much easier to write and to read. The table alias (whether the full table name or an abbreviation) is attached to the column name. In SQL, this results in a qualified column reference. The qualification specifies what table it is coming from.
The table alias is not attached to a function, because SQL does not currently allow tables to contain functions.

Using values from two tables to run query in Hive

I would like to run a hive query to be able to divide a column from one table by the total sum of a column from another table.
Do I have to join the tables?
The code below generates errors:
Select 100*(Num_files/total_Num_files) from jvros_p2, jvros_p3;
FAILED: Parse Error: line 1:75 mismatched input ',' expecting EOF near 'jvros_p2'
Yes, jvros_p3 is a single row single column table
Num_files is a column in jvros_p2 and total_Num_files is a single value in jvros_p3.
Your older version may be why your notation isn't working. Try this:
SELECT 100 * (Num_files / total_Num_files) FROM jvros_p2 JOIN jvros_p3;
I suspect that if you are eventually able to upgrade to at least 0.13, implicit join notation via comma-separated tables will be supported per HIVE-5558.

How to find the name of a table based upon a column name and then access said table

I have a column name "CustomerIDClass" and I need to find the table it's associated with within an entire Oracle database.
I've run this to determine the owner and name of the table where this column name appears:
select * from DBA_TAB_COLUMNS
where COLUMN_NAME LIKE '%CustomerIDClass%';
and I'm getting this response:
I don't have enough reputation to post the image, so here's the link: http://i.imgur.com/a7rcKoA.png
I have no idea how to access this (BIN$Csew==) table. When I try to use it as a table name I get errors or messages saying that no rows were returned.
My main goal here is to write a simple statement that lets me search the database for the "CustomerIDClass" and view the table that contains this column name.
This table is in the recycle bin. You have to issue FLASHBACK TABLE "Customer1"."BIN$Csew==$0" TO BEFORE DROP command, given you have the appropriate privileges.
Doc: http://docs.oracle.com/cd/B19306_01/server.102/b14200/statements_9012.htm
Do note that in oracle the column names are stored in capital but you are using mixed case in your like statement therefore the select clause will not return any result
Try the below
select * from DBA_TAB_COLUMNS
where COLUMN_NAME LIKE '%CUSTOMERIDCLASS%';

Get ORA 01722 invalid number when try to copy data from one table to another

I have to admin there is slight difference between the columns from both tables. But I thought that was minor.
The table Source has three attributes
Amount NUMBER(10,2)
SHORTNAME VARCHAR2(3)
NAME VARCHAR2(40)
The table Target has the same set of attributes but slightly different constraints on their type
Amount NUMBER
SHORTNAME VARCHAR2(255)
NAME VARCHAR2(255)
I thought table Target should have more tolerance on its capacity, but when I run the query
insert into DB_B.Target select * from DB_A.Source ;
Unfortunately I get the popular 01722 error:
SQL Error: ORA-01722: invalid number -- 01722. 00000 - "invalid number"
So when we say when copying data from two tables with the same schema, are we talking about 100% IDENTICAL even on the TYPE CONSTRAINT?
Please help.
Update
Before thunder storm hit the office, I have to mention that the column order on both tables are different. Thanks to #a_horse_with_no_name help me think out this issue and give the perfect answer.
Maybe the order of the columns is not identical in the two tables.
Try to explicitely list the columns to make sure they aren't mixed up for some reason:
insert into db_b.target
(amount, shortname, name)
select amount, shortname, name
from db_a.source;
Note that it's generally considered bad style to not list the columns in the insert clause and to use select * in that way (even if that isn't the cause of your problem)