• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 405
  • Last Modified:

SQL Plus - Insert statement

I need to write insert statement but one values will be calculate from other fields and records

any example for that ?
2 Solutions
- maybe something like this?:

INSERT INTO table1 (field1, field2) SELECT field1, (field2 + 1) FROM table2
- if you can provide sample data, and how its being caculated it will much clearer. does the value came from a field in different table or the same table?
See attached.
Transaction-level recovery for Oracle database

Veeam Explore for Oracle delivers low RTOs and RPOs with agentless transaction log backup and transaction-level recovery of Oracle databases. You can restore the database to a precise point in time, even to a specific transaction.

QlemoC++ DeveloperCommented:
The traditional approach is to construct the necessary SELECT step by step, and then just stuff that into an INSERT. Something complicated like this:
insert into tbl1 (keyfield, data1, data2, data3)
select t.keyfield+1, o.data1, o.data2, o.data1+o.data2
from (select max(keyfield) as keyfield from tbl) t,
othertbl o where o.data3 > 1000

Open in new window

This will determine the maximum of an (integer) key field, increment it, and insert a record. This will, of course, only work correctly for a single record, but it is just an example.
I wish it were true that there is no reason to post my responses as an attachment, and that's precisely how I always initially respond. However, I don't know whether it's due to the extremely restrictive firewall under which I work, but I would say about 90% of the time I try to submit a direct response, it gets timed out, but an attachment will go through. This has been extremely frustrating to me as I have tried to submit solutions that were correct only to have to copy them to a file, save them and re-submit as an attachment only to have someone else get credit for submitting the same solution minutes earlier than my attachment. I expressed my displeasure with this a long time ago when EE made some substantial changes to the site causing my need to use the attachment method. I am trying to submit this comment directly now. Hopefully, it will go through.
egovernmentAuthor Commented:
I will return all answers and come back

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now