New column in Oracle adding data to exsisting fields (1561 of them) Code Answer

Hello Developer, Hope you guys are doing great. Today at Tutorial Guruji Official website, we are sharing the answer of New column in Oracle adding data to exsisting fields (1561 of them) without wasting too much if your time.

The question is published on by Tutorial Guruji team.

I have created a new column in Oracle but I need to append the new data to the already existing records is there a simple method for this.

I have tried the insert method but this only applies the data after the already created data.

INSERT INTO BOOKINGS (DATE_BOOKED) VALUES (to_date ('01/01/2012 6:49 PM','DD/MM/YYYY HH.MIPM'));

I am just unsure of how to append 1561 rows of data the table headers are as such

BOOKINGS_ID, GUEST_ID, ROOM_NO, OCCUPANTS, NIGHTS, RATE, ROOM_TYPE, DATE_BOOKED

any help is greatfully appreciated

Answer

If I understand you correctly, you don’t want to insert new rows, but you want to update (change) the existing ones. This is done using the UPDATE statement, not INSERT:

UPDATE bookings
  SET date_booked = to_date ('01/01/2012 6:49 PM','DD/MM/YYYY HH.MIPM');
COMMIT;

This will set the value for the column date_booked to the same value for all existing rows.

You might want to consider going back to your SQL tutorial to understand the difference between UPDATE, INSERT and DELETE

To update only a single row, you need to add a WHERE clause that will limit the update to one row:

UPDATE bookings
  SET date_booked ....
WHERE bookings_id = 1;

UPDATE bookings
  SET date_booked = ....
WHERE bookings_id = 42;

(assuming bookings_id is the primary key of the table)

We are here to answer your question about New column in Oracle adding data to exsisting fields (1561 of them) - If you find the proper solution, please don't forgot to share this with your team members.

Related Posts

Tutorial Guruji