Header and Trailer updating the same record

Hi all
I have a requirement in SQL loader in which the header should go to a header_trailer table. ( only 5 out of 10 columns are updated by the header record).
All the data records go to a second table.( some xyz table)
The trailer record should again update the record inserted by the header record in header_trailer table(the remaining 5 columns)
How can I do this
Each record in the header_trailer record will be identified by a sequence which should be populated when the header inserts the record
Thanks
Ashwin N.

You're in luck, I'm a bit bored so I wrote a little script. This is just one way of doing it. It makes sure you can run this code in parallel as much as you want. However, you do get a lot of control and log files, but there is no escaping that. If the parallel option is not a requirement there are easier solutions (e.g. using a function called in the control file to fetch the last batch number from the lb_hf table). That way the control file can remain static.
I also experienced some problems with the nummeric value in a definition variable. I solved it by turning it into a char and later in a number again, but this must be simpler. Anyways, this works and should suffice for your learning purposes:
Create 2 files. One called 'l.dat' with the following data in it:
a,b
c,dThe other file called 'l.sql' with the following script in it:
-- script to test loading data in staging area and create/update header table
define usr=scott
define pwd=tiger
define db=oracle
whenever sqlerror exit
conn &usr/&pwd@&db
whenever sqlerror continue
create table lb_stage (-- this is the staging table in which the data will be loaded
  batch_num number,
  c1 varchar2(30),
  c2 varchar2(40));
create table lb_hf (--  this is the footer table
  batch_num number,
  load_start date,
  description varchar2(30),
  records_loaded number,
  load_end date);
create sequence lb_hf_seq;
set verify off
-- fetch new sequence for this particular load
col hf_seq_nr format a30 new_value v_hf_seq_nr
select to_char(lb_hf_seq.nextval) hf_seq_nr from dual;
-- create header record
insert into lb_hf values (to_number('&v_hf_seq_nr'), sysdate, 'Automated load', null, null);
commit;
-- create control file (needed to hardcode the sequence number in)
set feedback off
spool l_&v_hf_seq_nr..ctl
prompt load DATA
prompt INTO TABLE lb_stage
prompt FIELDS TERMINATED BY ';' OPTIONALLY ENCLOSED BY '"'
prompt TRAILING NULLCOLS
prompt (
prompt batch_num char "&v_hf_seq_nr",
prompt c1,
prompt c2
prompt )
spool off
set feedback on
-- load data (also have batchnum in log file name)
host sqlldr &usr./&pwd.@&db. data=l.dat control=l_&v_hf_seq_nr..ctl log=l_&v_hf_seq_nr..log
-- update header record with load information
update lb_hf set records_loaded = (select count(1) from lb_stage where batch_num = &v_hf_seq_nr), load_end = sysdate where batch_num = &v_hf_seq_nr;
commit;
select * from lb_stage;
select * from lb_hf;
drop table lb_stage;
drop table lb_hf;
drop sequence lb_hf_seq;
prompt End of script.Change the login at the beginning to something appropriate and run l.sql from the sql prompt.
Hope this helps,
Lennert

Similar Messages

  • Keeping heading and detail on the same page

    Hi, I have a report with a group header section and a detail section.  How can I keep the heading section and all the detail section on the same page without starting each group on a new page?
    The detail section will have either 2 or 3 records with some of the objects set to grow if the data doesn't fit on one line.  This results in several changes of group appearing on the same page which is what I want.  However, what I don't want is the header section on one page with the detail section on the next, or the header and some of the detail records on one page with the rest of the detail records on the next.  What I would like is the report to start a new page if the header and all the detail records don't fit on the same page but without starting a new page for every group change.  How can I achieve this?

    you can put the group header and details into a sub report on the old group header section.
    then hide the details section

  • Executing the sam SQL Query again and again on the same records?

    Hi currently we have a system that will compute certain charge information base on a file finance department send to us from another system
    The problem is that their file contains of Account with bank records and account with no bank records.
    for thos account with bank records it will just send to us and we will just update it..and those account will be updated...
    but for those account that have no bank records ..it will send to us again and again..and these no bank records account will accumulate
    the finance department mention that there is not much they can do on their side except sending us the file
    is there any gd solution for this people kind to share?

    Well one simple solution which i can think of is to persist Non-bank accounts in a Serializable Object and save it in a temporary cache.
    Now before running a query on them and then trying to update the database checkout the peristed cache, check whether data records exist their or not
    if they do, dont update that records in the database.
    or define your database tables in such a way that there is an indication of abt bank & non-bak records and write a query / procedure in such a way that it do not update the duplicate non-bank records.
    Hope this might help :)
    REGARDS,
    RaHuL

  • How to record you screen using quicktime with built in input line and microphone in the same recording?

    i am using th quick time record your screen option and see (when on the audio selction) that you can only either record sound from your computer or from your microphone
    is it possible to have it both on one recording?

    The usual audio-in options on a laptop are None / Built-in Input: Line in / Built-in Microphone: Internal microphone. There's not an option to record system audio unless you've installed a third-party extension such as Soundflower.
    In any event, if you're looking to combine audio inputs, check the Audio MIDI Setup help files (Applications > Utilities > Audio MIDI Setup). Search for "aggregate."

  • Multiple users updates the same data - RowInconsistentException

    Hi,
    I'm using JDeveloper 11.1.2.1
    Locking mode: optimistic
    Scenario:
    - Have 2 users (user 1 & user 2) running application x
    - Both users updates the same record
    - user 1 hits save first (and hence no error)
    - user 2 hits save after user 1, and gets RowInconsistentException
    I have managed to trap the exception in the EntityImpl class:
    public void lock() {
    try {
    super.lock();
    catch (RowInconsistentException ex) {
    this.refresh(REFRESH_UNDO_CHANGES);
    super.lock();
    But what this does is that it just refreshed the entities and removed user 2's work without notification, which isn't acceptable.
    Instead of this, is it possible to display an error message in user 2's UI (instead of the stack error) , refresh the entities, but keep user's 2 work, and possibly recommit?
    Thank You
    Regards,
    Andi

    Andi,
    , is it possible to display an error message in user 2's UI (instead of the stack error)You can customise the error handling, yes, to display a different message if you like (check out the Fusion Developer's Guide to find out how)
    refresh the entities, but keep user's 2 workNot sure what you mean there
    By default (at least it used to be this way, haven't checked recently), if you commit again after receiving the "row inconsistent" error, it will save user 2's changes (potentially overwriting user 1's changes)
    John

  • Updating the same row in different sessions

    Hi,
    I've one table application(appl_no varchar2(10), locked_user varchar2(8)) which is used to track which user is logged in at present.
    As soon as any user is logged in to the system via front end, the user ID is populated to locked_user column so that no other user cannot access the same appl_no. As soon as the user exits from the front end, the locked_user is updated to null.
    We've experiencing a strange behaviour in our system where one user exits from front end and at the same time(previous transaction is not committed) the same user ID opens the same application in another session, but the session session doesn't gets hanged(waiting for the lock to be released) and tries to update the same row which was locked by first user's session. We come to know this thing when the trigger on the table gets fired in both sessoins.
    Now I want to know if there is any locking machanism in Oracle where the same row can be updated in 2 different sessons one after another when the first session has not committed its changes?
    Thanks
    Deepak

    And obviously no two sessions can update the same record at the same time
    Yes I know that and I tried the same thing by myself on 2 different sql sessions which is not happening, but this is happening when the same is being done from front end(Power Builder based application).
    Just wanted to check is there any possibility where this can be possible?
    Thanks
    Deepak

  • Extracting body with header and trailer multiple times from a multirow file

    Hello Everyone,
    I am new to OSB and currently working on a project where I need to extract data from a flat file containing multiple rows of body and a single header and trailer in the following fashion:
    Original File:
    <Header></Header>
    <Details></Details>
    <Details></Details>
    <Trailer></Trailer>
    Desired format using OSB:
    <Header></Header>
    <Details></Details>
    <Trailer></Trailer> ... in a single file, multiple times
    Please help me in carrying out this functionality. It's really urgent and important.
    Thanks,
    Saurabh

    Some may argue this is not the right forum - database general might have been a little been than downloads - but now the thread is here I'll try an answer.
    As I see it It depends on your spooling tool.
    Lets assume you are using sqlplus.
    I that case the sql prompt command may serve your purpose
    Alternatively
    select 'header' from dual
    union all
    select field1||','||field2||','field3 .... /*must single string expression but may concatentate field */ from somtable
    union all
    select 'trailer' from dual;may suit.
    However I fear either I have not understood the question or if I have understood the question that you may have difficulties implementing this.
    Edited by: bigdelboy on 19-Apr-2009 14:32

  • Supress Header and Trailer from being generated and printed

    I am using oracle 9i Reports Builder.
    Is there a way to supress the header and trailer pages from being generated and printed.

    Increase the marigin size to zero size header and trailer in the layout editor and then run the report.

  • How to do the header and trailer validation in the input file?

    hi,
    what are the ways we can validate whether header and trailer record exists in the input file?
    how to do that?
    regards
    Ruban

    File to Proxy Validation
    https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/99593f86-0601-0010-059d-d2dd39dceaa0
    /people/swaroopa.vishwanath/blog/2005/06/24/generic-approach-for-validating-incoming-flat-file-in-sap-xi--part-1
    /people/swaroopa.vishwanath/blog/2005/06/29/generic-approach-for-validating-incoming-flat-file-in-sap-xi--part-ii
    /people/prateek.shah/blog/2005/06/14/file-to-r3-via-abap-proxy

  • Recording vocals and guitar at the same time, using the Alesis IO dock!

    Hi there!
    I have an Ipad 2 with the newest OS installed etc. And I rea the other posts in here.
    I bought an IO dock from Alesis the other day and was full of exspectations, but I got a bit disappointed -> Garageband! When I bought the Ipad dock I exspected that I would be able to record (or just play and hear the inputsound from two devices) at the same time in my headphones! But I wasn't... Now I'm wondering if this is going to be fixed in an update or not? I think it would be a shame if this issue isnt adressed, due to the huge abilities the Ipad/garageband/Ipad docks withhold.
    So anyone know anything? I went to my musicstore and spent about an hour or so with the tech dude there trying dfferent setups, but unfortunatly without luck! Just to clarify that I didt just plugged in my guitar and got mad that it wasnt apple intuative!
    Hope someone can help :)

    I am wondering if I can record audio and midi at the
    same time in Logic 7 Express. I am running my guitar
    thrugh a Roland GR 33, and a line out and using the
    GR 33 to trigger sounds in the Logic's synth section
    but cant seem to record all three tracks at once. If
    any one knows how let me know. Oh and I am running
    the GR Synth and Guitar into the Prosonus Fire Fox
    and have the GR 33 out midi to the Fire Box as well.
    So I guss the question is how do I sent up two audo
    tracks and one midi track to record in real time.
    Thanks Victor
    Try arming the audio tracks, select one of the tracks, then while holding down the shift key, select the midi track you want to record, arming the "r" on the midi track. Press "record".....
    HL

  • Open Hub Header and Trailer Record.

    Hi,
    For the Open Hub Destination
    Destination Type is File,
    Application server.
    Type of File Name: 2 Logical File name.
    How to to the get the Header and Trailer Record which will contain Creation Date, Creation Time and Total number of records.
    Header record Layput :
    Creation Date (YYYYMMDD)
    Creation Time (HHMMSS)
    Total record Count
    Trailer record Layout:
    Total number of Records in the file and
    XXXX( Key Figure ) Total.
    Thanks in advance.
    Regards,
    Adhvi.

    Hi Venkat,
    write a UDF in following way...
    pass the first parameter as the detail node (cache the whole queue) to the UDF pass the second parameter as the trailer countto the UDF
    now loop through the detail records get the count with a counter variable
    check the counter against the trailer count outside the loop
    if it doesnot match trigger the alert from the UDF itself
    Check the below link for triggering alert from an UDF
    /people/bhavesh.kantilal/blog/2006/07/25/triggering-xi-alerts-from-a-user-defined-function

  • How to handle an update of the same record from two different user  in JSP

    how to handle an update of the same record from two different user
    how do you handle an update of the same record from two different users in JSP... if one person updates the record from one drop downs should be updated as well.. is the possible.

    Usually, if two users try to update the same row at the same time, you want the first to commit to succeed, and when the second commits, they should fail with the error that the row was being concurrently updated. They you may want to show them the new row values and give them the opportunity to merge their values with the new row values...
    How can you achieve this? Google optimistic locking.

  • Recording Audio and Midi at the same time in Logic 7 Express Can it be done

    I am wondering if I can record audio and midi at the same time in Logic 7 Express. I am running my guitar thrugh a Roland GR 33, and a line out and using the GR 33 to trigger sounds in the Logic's synth section but cant seem to record all three tracks at once. If any one knows how let me know. Oh and I am running the GR Synth and Guitar into the Prosonus Fire Fox and have the GR 33 out midi to the Fire Box as well. So I guss the question is how do I sent up two audo tracks and one midi track to record in real time. Thanks Victor

    I am wondering if I can record audio and midi at the
    same time in Logic 7 Express. I am running my guitar
    thrugh a Roland GR 33, and a line out and using the
    GR 33 to trigger sounds in the Logic's synth section
    but cant seem to record all three tracks at once. If
    any one knows how let me know. Oh and I am running
    the GR Synth and Guitar into the Prosonus Fire Fox
    and have the GR 33 out midi to the Fire Box as well.
    So I guss the question is how do I sent up two audo
    tracks and one midi track to record in real time.
    Thanks Victor
    Try arming the audio tracks, select one of the tracks, then while holding down the shift key, select the midi track you want to record, arming the "r" on the midi track. Press "record".....
    HL

  • HT5624 My wife and I share the same apple id, we just updated our iphones. When we were asked if we wanted to share the same apple id for icloud we said yes, now our phones can't face time, please help?

    My wife and I share the same apple id, we just updated our iphones. When we were asked if we wanted to share the same apple id for icloud we said yes, now our phones can't face time, please help?

    Read http://macmost.com/setting-up-multiple-ios-devices-for-messages-and-facetime.htm l
    If you wish to share an Apple ID with family members then read: http://www.macstories.net/stories/ios-5-icloud-tips-sharing-an-apple-id-with-you r-family/

  • TS4268 My husband and I use the same apple ID, after the update he started getting all my texts from me to other people and from other people to me. Anyone know how to turn this off?

    My husband and I share the same apple ID for purchasing apps and what not, ever since the update he started receiving all my texts  from other people and I am not even getting them half the time. Any thoughts on trying to fix this would be appreciated. I tried turning off imessage but then he got no texts at all.

    Make sure that on each of your Settings>Messages> Send and Receive Addresses have only the appropriate phone number and email checked at the left.  If his is checked on yours click on his it will uncheck

Maybe you are looking for