?
Solved

ORA-00947 Not Enough Values

Posted on 2007-07-28
6
Medium Priority
?
3,211 Views
Last Modified: 2008-02-20
Hey Dudes,

I have a Table which contains 19 fields. Now i have some values that i want to insert BUT the total number of values equal exactly 13. Now my question is, is there a way that i can still get the values into the necessary fields and for those fields that dont have any values they just gets overlooked?

e.g
First_name
Last_name
Street
Zip_code
State
Home_Phone
Mobile_Phone
Other_phone

Now for instance i have fields 1 - 6 but not 7 and 8. is there a way i can still get to insert the values from 1 - 6 and since i dont have anything for 7 & 8 they get skipped?

Thx

0
Comment
Question by:Eaddy Barnes
6 Comments
 
LVL 23

Accepted Solution

by:
paquicuba earned 1000 total points
ID: 19587048
It depends...

Do the columns you're trying to skip accept NULL values?
      --"NOT NULL" constraints DON'T exist on them.

Do the columns you're trying to skip have a default value?


There are two basic type of inserts:

1. By positition --You don't need to list the column names, but you must provide a valid value
                           for all the existing columns.
                         --Skipped columns must be assigned a NULL value.

   Insert into <Table_Name> values(<Value_1>,<value_2>,...);


2. By Name   --You list the column names, and provide a valid value for the listed columns.
                    --Skipped columns cannot have the "NOT NULL" constraint or must have a default value.            

   Insert into <Table_Name>(<col_1>,<col_3>,...) values(<Value_1>,<value_3>,...);



e.g.

SQL> CREATE TABLE TAB1( COL1 NUMBER, COL2 NUMBER, COL3 NUMBER);

Table created.


SQL> --By positition
SQL> INSERT INTO TAB1 VALUES( 1,2,NULL);

1 row created.

SQL> SELECT * FROM TAB1;

      COL1       COL2       COL3
---------- ---------- ----------
         1          2

SQL> INSERT INTO TAB1 VALUES( 1,NULL,3);

1 row created.

SQL> SELECT * FROM TAB1;

      COL1       COL2       COL3
---------- ---------- ----------
         1          2
         1                     3


SQL> DELETE FROM TAB1;

2 rows deleted.

SQL> ALTER TABLE TAB1 MODIFY(COL3 NOT NULL);

Table altered.

SQL> INSERT INTO TAB1 VALUES( 1,2,NULL);
INSERT INTO TAB1 VALUES( 1,2,NULL)
                             *
ERROR at line 1:
ORA-01400: cannot insert NULL into ("PAQUI"."TAB1"."COL3")


SQL> --End By positition





SQL> --By Name

SQL> ALTER TABLE TAB1 MODIFY(COL2 DEFAULT 2);

Table altered.


SQL> INSERT INTO TAB1(COL1, COL3) VALUES( 1,3);

1 row created.

SQL> SELECT * FROM TAB1;

      COL1       COL2       COL3
---------- ---------- ----------
         1          2          3

SQL> ALTER TABLE TAB1 MODIFY(COL3 NULL);

Table altered.

SQL> INSERT INTO TAB1(COL1) VALUES(1);

1 row created.

SQL> select * from tab1;

      COL1       COL2       COL3
---------- ---------- ----------
         1          2          3
         1          2
0
 
LVL 11

Author Comment

by:Eaddy Barnes
ID: 19587100
WOW, you are a scary fellow, lol
The columns are null theres no "NOT NULL" constraints implemented.
0
 
LVL 14

Expert Comment

by:sathyagiri
ID: 19587139
You could just insert nulls for the cols that dont have values

insert into table values(col1,col2,col3,col4,col5,col6,null,null)
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 23

Expert Comment

by:paquicuba
ID: 19587242
Then, follow the examples, either put NULLs or list the columns.

INSERT INTO <YOUR TABLE NAME> VALUES( <VALUE1>, <VALUE2>, <VALUE3>, <VALUE4>, <VALUE5>, <VALUE6>, NULL,NULL);

OR

INSERT INTO <YOUR TABLE NAME>(<COL1>,<COL2>,<COL3>,<COL4>,<COL5>,<COL6>) VALUES( <VALUE1>, <VALUE2>, <VALUE3>, <VALUE4>, <VALUE5>, <VALUE6>);
0
 
LVL 32

Expert Comment

by:awking00
ID: 19592704
insert into yourtable
(First_name,
Last_name,
Street,
Zip_code,
State,
Home_Phone)
values
('John', 'Doe', '123 Main St.','20000','NY','555-1212');
OR -
insert into yourtable values
('John', 'Doe', '123 Main St.','20000','NY','555-1212',null,null);


0
 
LVL 5

Expert Comment

by:fmonroy
ID: 19610675
you can set default values for those columns too
0

Featured Post

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever had to make fundamental changes to a table in Oracle, but haven't been able to get any downtime?  I'm talking things like: * Dropping columns * Shrinking allocated space * Removing chained blocks and restoring the PCTFREE * Re-or…
Shell script to create broker configuration file using current broker Configuration, solely for purpose of backup on Linux. Script may need to be modified depending on OS-installation. Please deploy and verify the script in a test environment.
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
This video shows how to copy an entire tablespace from one database to another database using Transportable Tablespace functionality.
Suggested Courses
Course of the Month15 days, 16 hours left to enroll

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question