0

I am trying to store multiple values into a table with two columns in a single command. Here is my command,

INSERT INTO CATEGORY
VALUES('BUS','BUSINESS'), ('CHN', 'CHILDREN'), ('COK', 'COOKING'), ('COM', 
'COMPUTER'), ('FAL', 'FAMILY LIFE'), ('FIT', 'FITNESS'), ('SEH', 'SELF HELP'), 
('LIT', 'LITERATURE');

I get a red underline after my first pair of values where I have the comma. What am I doing wrong?

4
  • 3
    What is your DBMS? Commented Mar 18, 2019 at 19:13
  • Using oracle sql developer Commented Mar 18, 2019 at 19:23
  • Check this: stackoverflow.com/a/93724/2348125 Commented Mar 18, 2019 at 19:28
  • Thanks that helped! Commented Mar 18, 2019 at 19:36

2 Answers 2

1

I would start by listing columns:

INSERT INTO CATEGORY (<colname1>, <colname2)
    VALUES ('BUS','BUSINESS'), ('CHN', 'CHILDREN'), ('COK', 'COOKING'), 
           ('COM', 'COMPUTER'), ('FAL', 'FAMILY LIFE'), ('FIT', 'FITNESS'), 
           ('SEH', 'SELF HELP'), ('LIT', 'LITERATURE');

Not all databases support VALUES with multiple rows. So that could be the cause of your problem.

If you are using, say, Oracle that doesn't support this, you can use UNION ALL:

INSERT INTO CATEGORY (<colname1>, <colname2)
    SELECT 'BUS', 'BUSINESS' FROM DUAL UNION ALL
    SELECT 'CHN', 'CHILDREN' FROM DUAL UNION ALL
    . . .
    SELECT 'LIT', 'LITERATURE' FROM DUAL;
Sign up to request clarification or add additional context in comments.

Comments

0

place your column name explicitly if more column exist in your table

INSERT INTO CATEGORY(col1,col2)
VALUES('BUS,BUSINESS'),
('CHN', 'CHILDREN'), 
('COK', 'COOKING'),
('COM', 'COMPUTER'),
('FAL', 'FAMILY LIFE'),
('FIT', 'FITNESS'), ('SEH', 'SELF HELP'), 
('LIT', 'LITERATURE');

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.