Shades
Shades

Reputation: 285

Need to add values into existing rows and columns

I have a table called CUSTOMERS with 5 columns and 3 rows: LAST_NAME, FIRST_NAME, ADDRESS, CITY, ORDER_PRICE and I keep screwing it up and having to delete new rows I create because I'm unsure how to insert into the ORDER_PRICE column, values for rows 1 2 and 3.

i've tried insert into, update table clauses but i'm doing something wrong. Can anyone tell me how to insert values into rows 1, 2, & 3 or column ORDER_PRICE? ORDER_PRICE is of sata type NUMBER

Thanks

Upvotes: 5

Views: 95510

Answers (2)

To change the value of a column or columns in an existing row you should use an UPDATE statement, as in

UPDATE CUSTOMERS
  SET ORDER_PRICE = 123.45,
      CITY = 'San Luis Obispo'
  WHERE FIRST_NAME = 'Bob' AND
        LAST_NAME = 'Jarvis';

If you want to create a NEW row you'll want to use an INSERT statement:

INSERT INTO CUSTOMERS
  (LAST_NAME, FIRST_NAME, ADDRESS, CITY, ORDER_PRICE)
VALUES
  ('Jarvis', 'Bob', '12345 Sixth St', 'Cucamonga', '123.45');

Share and enjoy.

Upvotes: 4

Andomar
Andomar

Reputation: 238048

Assuming firstname+lastname is unique:

update  CUSTOMERS
set     ORDER_PRICE = 4.7
where   FIRST_NAME = 'The' and LAST_NAME = 'Dude'

update  CUSTOMERS
set     ORDER_PRICE = 4.2
where   FIRST_NAME = 'Big' and LAST_NAME = 'Lebowsky'

...

Upvotes: 14

Related Questions