×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Insert data from Table A into Table B how can I do that?

Insert data from Table A into Table B how can I do that?

Insert data from Table A into Table B how can I do that?

(OP)
I have table A with my account balance and i would like to use this data to insert them into my new table B. In this table I would like to see my account balance per day.

Is this possible with Oracle sql? Is there a insert statement or a function which i can use?

I would be very happy if someone can help me.

Table A

Date from Date until Balance
1-1-2018 5-1-2018 125

Table B
Date Balance
1-1-2018 125
2-1-2018 125
3-1-2018 125
4-1-2018 125
5-1-2018 125


RE: Insert data from Table A into Table B how can I do that?

This is a bit klugey, but it should work:

1. Create table B:

CODE

CREATE tableB AS SELECT * FROM tableA; 

Then add the rest of the records:

CODE

DECLARE
   l_date DATE := '1-JAN-2018';
BEGIN
   FOR i IN 1..364 LOOP
      l_date := l_date + 1;
      INSERT INTO tableB VALUES(l_date, 125);
   END LOOP;
   COMMIT;
END; 

This should at least get you within striking distance of where you want to be.

RE: Insert data from Table A into Table B how can I do that?

CODE

CREATE TABLE Tableb
AS
    SELECT B.Date_from + (A.Rnum - 1), Balance
    FROM (SELECT ROWNUM Rnum
          FROM (SELECT 1
                FROM DUAL
                CONNECT BY LEVEL <=
                           (SELECT (Date_to - Date_from) + 1 FROM Tablea))) A,
         Tablea B; 

Bill
Lead Application Developer
New York State, USA

RE: Insert data from Table A into Table B how can I do that?

My apologies - I didn't read your post carefully and was responding to the one you put up in a different forum. This is moot, however, since Bill has provided us with a very elegant solution. One note though - you will need to provide a column name for the expression "B.Date_from + (A.Rnum - 1)" before this will work (at least, that was my experience).

Nicely done, Bill! Thank you.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close