Insert and add data to the table to a batch file

Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 - Production
PL/SQL Release 11.1.0.7.0 - Production
CORE Production 11.1.0.7.0
AMT for 32-bit Windows: Version 11.1.0.7.0 - Production
NLSRTL Version 11.1.0.7.0 - Production


My patch to input file looks like this:

A0397990002000001
A0459380377000075
A1291115796000002
C0483110026000080
D0491114923000004
A0348400660000000
G0209111373-

Separate columns look like this:

A0397 990002 000001

account amount of IDN


I'm new to PL/SQL and having a problem changing or adding a record in a table. Don't know how to check if a record exists in the table change if not
Insert the record.

If the quantity is 000000 or - the record should be deleted. I have code in place to do this however, don't know how to handle change or add the part.

Here is the code I have so far and thanks for looking:

Set serveroutput on
create or replace directory user_dir as 'c:\dataformats\incoming\ ';


DECLARE


v_filename VARCHAR2 (100); -The name of the data file
v_file_exists boolean;
number of v_file_length;
number of v_block_size;
f utl_file.file_type;
s varchar2 (200);
lineString varchar (200);

-not used c_ *.
c_account ID_REQ_STG.account%TYPE;
c_IDN ID_REQ_STG. IDN % TYPE;
c_quantity ID_REQ_STG.quantity%TYPE;

ID_REQ_TUPLE ID_REQ_STG % ROWTYPE;

v_account varchar (5);
v_IDN varchar (6);
V_quantity varchar (6);

BEGIN
v_filename: = ' PTCLICK. MANUAL.12SERIES.TXT';


DBMS_OUTPUT. Put_line (v_filename); -the name of the file


UTL_FILE.fgetattr ("USER_DIR", v_filename, v_file_exists, v_file_length, v_block_size);

IF v_file_exists THEN

dbms_output.put_line ("'File Exists");

f: = utl_file.fopen ("USER_DIR", v_filename, "R");

IF utl_file.is_open (f) THEN

LOOP
BEGIN
UTL_FILE.get_line (f, s);
lineString: = s;

dbms_output.put_line (lineString);

v_account: = substr (lineString, 1, 5);
v_IDN: = substr (lineString, 6, 6);
V_quantity: = substr (lineString, 12.6);


dbms_output.put_line (v_account);
dbms_output.put_line (v_IDN);
dbms_output.put_line (V_quantity);

-REMOVE

IF v_quantity = '000000' GOLD v_quantity = '-'
THEN
REMOVE FROM ID_REQ_STG
WHERE account = v_account and
IDN = v_IDN;
commit;
dbms_output.put_line ('Deleted the folder' | v_account |) «and» | v_IDN);
END IF;


-CHANGE



-ADD



EXCEPTION
WHEN NO_DATA_FOUND THEN
dbms_output.put_line ("' no data found");
EXIT;
END;

END LOOP;

END IF; -is open

UTL_FILE.fclose (f);


ON THE OTHER

dbms_output.put_line ('file does not exist');

END IF; -file exists

EXCEPTION

WHEN UTL_FILE. THEN ACCESS_DENIED
DBMS_OUTPUT. Put_line ("' no access!");
WHEN UTL_FILE. INVALID_PATH THEN
DBMS_OUTPUT. PUT_LINE ('PATH DOES NOT EXIST');
WHILE others THEN
DBMS_OUTPUT. PUT_LINE ("SQLERRM: ' |") SQLERRM);



END;
/

Hello

Looks like a good candidate for a MERGER with an external table.

The external table:

create table ext_table (
 account varchar2(5),
 idn number(6),
 quantity varchar2(6)
)
organization external (
  type oracle_loader
  default directory user_dir
  access parameters (
    records delimited by newline
    fields (
      account position(1:5) char(5),
      idn position(6:11) char(6),
      quantity position(12:17) char(6)
    )
  )
  location ('test.txt')
)
reject limit unlimited;

Then a simple MERGER should perform all your needs:

MERGE INTO id_req_stg t
USING (
 SELECT account,
        idn,
        decode(quantity, '-', 0, to_number(quantity)) as quantity
 FROM ext_table
) v
ON ( t.account = v.account AND t.idn = v.idn )
WHEN MATCHED THEN
  UPDATE SET t.quantity = v.quantity
  DELETE WHERE t.quantity = 0
WHEN NOT MATCHED THEN
  INSERT (account, idn, quantity)
  VALUES (v.account, v.idn, v.quantity);

Documentation related to the MERGER: http://download.oracle.com/docs/cd/E11882_01/server.112/e10592/statements_9016.htm#SQLRF01606
and on the outdoor tables: http://download.oracle.com/docs/cd/E11882_01/server.112/e10595/tables013.htm#ADMIN12896

Published by: odie_63 on June 10, 2010 14:26 (added docs)

Tags: Database

Similar Questions

  • Add data in the header of a .wav file

    Hello guys,.

    I seek your help for a small problem that I can't spend during my internship.

    Here's what I want to do: I acquire signals that I write a .wav file. What I would do then is to reopen this .wav file and add data in the header, such as the sensitivity of the microphone for example. I am doing this is because it's one of our program of works, it can resume the pressure vs time signal using this information. I already have the hex code I need to add, but I was not able to determine if such a thing is possible or not after a day of research ideas would be greatly appreciated. I wonder if Matlab might do the trick but I prefer to stay with the 'normal '... screws

    Thank you very much for your help.

    To insert data into the middle of a file, you will need to rewrite the entire file after that point, as Gerd said in the linked post.  I would do the following:

    1. Search for the location you want to put your new piece
    2. Read 65 000 bytes from forward and store in a local cache (shift registers work well for this, or just a wire at this point).
    3. Write your new piece, taking note of how long it is
    4. Give your data buffered less the length of your new song
    5. Read a 65 000 other bytes and put it in a new buffer
    6. Write the end of the old buffer and a part of the new buffer until you get to 65 000 bytes
    7. Repeat 4 to 6 until you reach the end of the file
    8. Update the offsets in the header to match the new locations of piece, since you have moved things

    You can probably do it with both data pads in a pair of registers at offset in a loop.  The 65 000 bytes is chosen for best performance.  You can use other sizes, but your speed can suffer.  Let us know if you encounter any problems.

  • How to add data to the table changed in sql developer at Apex and vice versa

    Hello

    I had tables of database with sql developer. But now, I have modified the database (new tables added + changed the data in the tables). However, in the Apex, I the old database. Is it possible to get the new Apex database with the data of the table changed so this database in both places (sql and apex developer) is exactly the same... Also the other way around.

    Thank you

    The database schema that contains the tables, is it associated with the workspace even you are searching through the APEX product t development?  Why I'm asking is, if they are the same schema, the tables that you MODIFIED should be appear in the sql for APEX workshop part.  Now reports and forms will NOT see the changes (unless you have actually added or updated definitions for column).

    Can you explain what exactly you were doing the SQL Developer to the tables in your schema?

    Thank you

    Tony Miller
    Los Alamos, NM

  • How to add data to the table using Manager POST for restful Apex application

    Hi all

    I managed to create a service application web Manager restful using GET for the Restful service module. I am able to get the data in row on the presentation of a table row id in the application. But I can't find an appropriate example, how the new data in the table can be posted or deleted. I created a POST handler for a URI scheme and look forward on how to proceed. Any help would be really appreciated.

    Source for the POST Manager:

    Start

    insert into ALL_BOOKS values(:id,:book);

    end;

    Also created 2 parameters id and the book.

    Hi jerry2134,

    jerry2134 wrote:

    I managed to create a service application web Manager restful using GET for the Restful service module. I am able to get the data in row on the presentation of a table row id in the application. But I can't find an appropriate example, how the new data in the table can be posted or deleted. I created a POST handler for a URI scheme and look forward on how to proceed. Any help would be really appreciated.

    Source for the POST Manager:

    Start

    insert into ALL_BOOKS values(:id,:book);

    end;

    Also created 2 parameters id and the book.

    Check out the following tutorials OBE, that explains the creation of GET and POST RESTful Web Services and how to use them in the APEX.

    Also what yo mean "looking forward on how to proceed? Do you want to or created for use/consume in your Oracle APEX application hosted RESTful web services?

    If Yes, in your Application, you must create a RESTful Web Service reference -> shared components. Then, create a form/report based on Web Service reference.

    Kind regards

    Kiran

  • Is it possible to see/get the data from the table to a dump file

    I have files dmp generated using expdp on oracle 11 g...

    expdp_schemas_18MAY2013_1.dmp

    expdp_schemas_18MAY2013_2.dmp

    expdp_schemas_18MAY2013_3.dmp

    Can I use a settings file given below to get the data from the table in the file sql or impdp the only option to load the data of table in database.

    VI test1.par

    USERID = "/ as sysdba".

    DIRECTORY = DATA

    dumpfile=expdp_schemas_18MAY2013%S.dmp

    SCHEMAS = USER1, USER2

    LOGFILE = user_dump_data.log

    SQLFILE = user_dump_data. SQL

    and impdp parfile = test1.par.

    No,

    DataPump cannot retrieve a dumpfile data in a flat file.

    Dean

  • Add new data to the table in a log file

    Hi all. I am new to Oracle and I need to also write new data table in a logfile on Linux in order to live in the display screen. My first thought was to write a trigger, and after some research on googled around, I finally came to this:

    create or replace trigger foo_insert
    After Insert on foo
    for each line
    declare
    f utl_file.file_type;
    s VARCHAR2 (255);
    Start
    s: =: new.udate | '-' || : new.time | ' ' || : new.foo | ' ' || : new.bar | ' ' || : new.xyzzy | ' ' || : new.frobozz | ' ' || : new.quux | ' ' || : new.wombat;
    f: = utl_file.fopen ('BLAH_BLAH', 'current.log', ' a');
    UTL_FILE.put_line (f, s);
    UTL_FILE.fclose (f);
    end foo_insert;

    It seems properly to add new data in the log file as new inserts occur, but open and close the file each time are of course not optimal.
    In the app real new lines could have inserted every second or two. How can I optimize it? In addition, the log file will be archived and turned every day, so there must be a way to effectively report the relaxation of the oracle to reopen the case.


    Thank you!

    >
    I would like to pursue the optimization of the trigger
    >
    As Ed suggested you need to think this through a few others and refine the requirements.

    You said "I am new to Oracle. So you may not realize that anything a trigger didn't REALLY EVEN HAPPEN! The transaction can still be restored by Oracle or by the appellant. Want that all the 'hiccups' look too? If this isn't the case, then you can not use a trigger to do this. You need the process that translates the trigger being called to do logging after the data is stored.

    It should be noted that this requirement is before we can offer solutions to a problem.

    Assuming you want the trigger record all attempts change the data, then the best way I know to do that is to minimize the work does the trigger.
    Another fundamental principle is to follow the advice of the Ed and have a clear separation and distinction between "what" should be done and 'how' to do it.

    To minimize the trigger work change proposed Nicosa approach. Create an AUTONOMOUS_TRANSACTION stored procedure that handles the 'how' and just have the trigger to transfer data to the stored procedure values. The trigger provides data; He doesn't know, or care, what is done with the data.

    The stored procedure is then free to use the files, a table, write to a file or any other method is proving to be the best. You can change the methods without affecting the trigger.

    A queue or table may contain data, but again once you need to think about the obligation. Do you need fair access to data only once? Now, you want a "tail". But what happens if this requirement change tomorrow? You won't have to redesign the architecture.

    With a queue once you delete the queue data it won't here later if you want to get it again. With a table you can take as long as you want.

    I would like to start by using a table to store the data. If you use a sequence number or "insert_date" value, you can always query the data of interest. The table just collects data. He does not care how to use data.

    So, by using proven design principles and knowing that the requirements are for the most part unknown and may change unexpectedly, I would be:

    1. create an AUTONOMOUS_TRANSACTION stored procedure that accepts the parameter data and the thicket in a simple logging table.
    2. change your trigger to call the procedure to step #1
    3. create another procedure that performs a query of 'tail' for you will depend on 'insert_date' number or sequence. This query can write data to a file or return a cursor ref that your script can use to provide data for display.

    The approach described above takes each step in the process relatively independent of the other stages.

    Until put you the finishing touches to the requirements that you do not want to lock up your initial design.

  • Reading file from the ftp server and importing data into the table

    Hi experts,

    Well, basically, I text with different layout files have been uploaded to an ftp server. Now, I must write a procedure to recover these files, read and insert data into a table... what to do?

    your help would be greatly helpful.

    Thank you

    user9004152 wrote:
    http://it.Toolbox.com/wiki/index.php/Load_data_from_a_flat_file_into_an_Oracle_table

    See the link, hope it will work.

    It is an old method, using the utl_file_dir parameter that is now obsolete and which is frankly a waste of space when external tables can do exactly the same thing much more easily.

  • Need to add data to the tables in the target

    Oracle Database 11g Express Edition Release 11.2.0.2.0 - Production

    Hi gurus

    Need your help again, I have the following data.

    Sample data

    create the table parent_mst

    (

    GRP number (3).

    nel number 4

    );

    create the table parent_dtl

    (

    GRP number (3).

    by number 4

    );

    Query

    with pp as

    (

    Select double union 100 grp, nel 8000

    Select grp 200, nel 7000 double

    ),

    As CC

    (

    Select grp 100, 200 per Union double all the

    Select grp 100, 300 per Union double all the

    Select grp 100, 400 per Union double all the

    Select grp 200, 400 by double

    )

    Select *.

    pp p, cc c

    where p.grp = c.grp;

    -Result of the query

    GRP, NEL, GRP_1, BY

    1008000100200
    1008000100300
    1008000100400
    2007000200400

    Now, I want to insert the following data into the parent_mst table.

    Need to insert the following data in parent_mst using all of the above data

    GRP nel

    100 8000

    200 7000

    Need to insert the following data in parent_dtl using all of the above data

    GRP BY

    100 200

    100 300

    100 400

    200 400

    Please guide. Thank you

    Concerning

    Shu

    Check if it works:

    INSERT INTO parent_mst
       (SELECT p.grp, p.nel, p_seq.NEXTVAL
          FROM parents p
         WHERE p.grp IN (SELECT grp FROM childs));
    
    INSERT INTO parent_dtl
       (SELECT c.grp, c.per, DENSE_RANK () OVER (PARTITION BY 1 ORDER BY c.grp)
          FROM childs c
         WHERE c.grp IN (SELECT grp FROM parents));
    
    COMMIT;
    

    See you soon,.

    Manik.

  • How to add data to the table?

    Hello

    As it is in question. Can I add data (new items) in table dynamically? I say my table 1 d is size 3, but I would like to add three items. Should I change size table first?

    See you soon,.

    K

    Hi K,

    Ray is right!

    Maybe this thread will also help you because there are examples of smal

    http://forums.NI.com/NI/board/message?board.ID=330&message.ID=18421&query.ID=288653#M18421

    Concerning

    Jürgen

  • How can insert different types of data in the table?

    Hello
    How can I insert different types of data in the table, (e.g., numeric and string) in the same index of a table.

    example:
    index0 car 10 green

    car red 11 index1
    Index2 car Blue 12

    where green car red and blue car as string and 10, 11 and 12 in the numeric form.
    then I extracted 10, 11 and 12 a digital table

    and, the green car, red car, blue car in a string array

    Help!

    Use 'Analysis of the chain' as in the picture as an attachment.  This will extract the number and color that you can add tables later.

  • inserting data into the table

    Hi all
    I use forms [32 bit] Version 6.0.8.24.1 (Production)
    Oracle Database 10g Release 10.2.0.1.0 - Production
    I have settings such as the (optional) emp_code and the year (mandatory field - four digits).
    Based on the setting that I have to get the detail of a table and these must be inserted at the other table with columns of additions (to hardcode the additional columns).
    To achieve this, I intend to get a cursor by selecting the required fields in the table by the way the where clause of the cursor parameters.
    by making a loop through the cursor I will insert the records in the other table.
    Here, the thing is that the data is going to be huge (since the year is the parameter).
    so my approach causes the performance issue.
    I heard that there is a different method of insetions
    can anyone suggest me the best way (performance wise) other than what I mentioned (if you are aware of)...

    Thank you...

    user13329002 wrote:
    Thanks for everyone.
    I have to take the data from the table as e_name, e_code, of the table and insert it into another table with some other values such as
    e_name, e_code, as well as I add 'n', 'o'.
    its something like

    insert into e_emp(emp_name,emp_code,emp_add,emp_status,emp_type)
    select e_name,e_code,e_add,'O','N')
    from e_table
    where e_date = Parameter.
    

    in other words, the values for Emp_status, emp_type I have no values in the e_table.so table and enter in e_table I have to hard code it.
    CAL I hard code as I mentioned in my statement example

    can someone clear me of the foregoing.

    Thank you...

    Published by: user13329002 on February 15, 2011 20:11

    Yes... You can hardcode the values for Emp_status, emp_type.

    SQL> CREATE TABLE e_emp(emp_code NUMBER(10),emp_status VARCHAR2(1),emp_type VARCHAR2(1));
    
    Table created.
    
    SQL> create table e_table as (select * from e_emp);
    
    Table created.
    
    SQL> INSERT INTO e_table(emp_code) VALUES('1111');
    
    1 row created.
    
    SQL> insert into e_table(emp_code) values('2222');
    
    1 row created.
    
    SQL> select * from e_table;
    
      EMP_CODE E E
    ---------- - -
          1111
          2222
    
    SQL> insert into e_emp(emp_code,emp_status,emp_type) (select emp_code,'0','N' from e_table);
    
    2 rows created.
    
    SQL> select * from e_emp;
    
      EMP_CODE E E
    ---------- - -
          1111 0 N
          2222 0 N
    
    SQL> 
    

    I hope this helps.

    Kind regards
    Claudy

  • How to insert image from mysql into the table using php and create the checkbox in the table?

    How can I insert image from mysql into the table using php and create the checkbox for each data as a vote? Here is my code...

    WELCOME

    connect_error) {die ("connection failed:".)} $conn-> connect_error); } $sql = "SELECT no, Calon, ID, of course, the Image OF THE candidates." $result = $conn-> Query; If ($resultat-> num_rows > 0) {echo ' '; export data of each line while ($row = $result-> fetch_assoc()) {"echo"}}
    NO Candidate INFO Vote
    " . $row ["no"]. "-" . $row ["Calon"]. "
    -" . $row ['ID']. "
    -" . $row ['class']. "
    "; } ECHO ' ' ;} else {echo '0 results' ;} $conn-> close();?} >

    hope someone can help me because I am a newbie in this program... need to finish this project... Thank you.

    If you have saved the file name in the database, it's pretty simple.

    echo '' . $row['description'] . '';
    

    Is the same for the box:

    echo '';
    

    If you have saved the image file in the database, it is much more complicated. I recommend you store only the file name in the database.

  • Button insert data to the table

    Hello

    I use APEX 4.2.3 with XE, I try to insert data into the table using code below but nothing happen when I press the button, create this button like 'create a button to point to page'-> 'dynamic action'-> 'run pl/sql '.

    begin
    insert into dummy values('xx');
    commit;
    end;
    
    

    So to clarify, you have

    (1) created a button that "action" is "defined by the dynamic action.

    (2) created a dynamic action that executes pl/sql at the click on the button and you are pl/sql?

  • What trigger to use to insert data into the table db forms

    Hello

    My form is current having a block of database with the table reference. When you enter data into the form field and click Save. Automatically record is inserted in the database table.
    I want to do this under manual insert. I changed the block of data to a data non-base. Where should I write the insert statement to insert data into the table.
    Is - shutter release key of the form-level validation?

    Please notify.

    Thank you
    Didi.

    You can guide me how to remove the message FRM-40401 no changes to save and instead, I wanted to put 1 transaction record successful... some like it like that.

    Hi didi.
    And this is my last post I'll sleep. ;)
    Take form level trigger named preform
    and write on it

    :SYSTEM.MESSAGE_LEVEL := 5;
    

    I hope this works...

    Hamid

    Mark correct/good to help others to get the right answers. *

  • Insert XML data from the Table-> back to null

    Dear Experts,

    -I have table xml as below:

    Example of CREATE TABLE (XML_spec XMLTYPE);

    Insert in the example
    Select ' < name of Message = "dataStaticInvestor" type = "IncomingMessage" >
    < name of field = "batchReference" > OPENINGBATCH000000 < / field > < List name = "data" >
    < = record name "data" >
    < name of field = "externalReference" > 01234567890aaaaaaa < / field >
    < name of field = "participantID" > OD001 < / field >
    < name of field = "participantName" > EQUITY SECURITIES INDONESIA, PT < / field >
    < / recording >
    < = record name "data" >
    < name of field = "externalReference" > 01234567890aaaaaaa < / field >
    < name of field = "participantID" > OD001 < / field >
    < name of field = "participantName" > EQUITY SECURITIES INDONESIA, PT < / field >
    < / recording >
    < = record name "data" >
    < name of field = "externalReference" > 01234567890aaaaaaa < / field >
    < name of field = "participantID" > OD001 < / field >
    < name of field = "participantName" > EQUITY SECURITIES INDONESIA, PT < / field >
    < / recording >
    < / list >
    < / message > ' double.

    Select * example;

    create table hasil1 (c1 varchar2 (500), c2 varchar2 (500), c3 varchar2 (500));

    -This step I create the procedure to insert xml data into the table as the batch.

    DECLARE
    x XmlType;
    BEGIN
    Select XML_SPEC in x for example;

    insert into hasil1
    SELECT
    p.Extract('/Record/Field/@externalReference').getstringval (C1),
    p.Extract('/Record/Field/@participantID').getstringval (C2),
    p.Extract('/Record/Field/@participantName').getstringval () as c3
    TABLE (XMLSequence (Extract(x,'Message/List/Record'))) p;
    commit;
    END;
    /

    -when the result of select hasil1, the output is back 3 rows and 3 columns, but all data is a null *.

    Best regards
    Sigcle

    You don't explain what output you need, but I guess something like this:

    SQL> insert into hasil1 (c1, c2, c3)
      2  select x.c1, x.c2, x.c3
      3  from example t
      4     , xmltable(
      5         'Message/List/Record'
      6         passing t.xml_spec
      7         columns c1 varchar2(500) path 'Field[@name="externalReference"]'
      8               , c2 varchar2(500) path 'Field[@name="participantID"]'
      9               , c3 varchar2(500) path 'Field[@name="participantName"]'
     10       ) x
     11  ;
    
    3 rows inserted
    
    SQL> select * from hasil1;
    
    C1                     C2        C3
    ---------------------- --------- --------------------------------
    01234567890aaaaaaa     OD001     EQUITY SECURITIES INDONESIA,PT
    01234567890aaaaaaa     OD001     EQUITY SECURITIES INDONESIA,PT
    01234567890aaaaaaa     OD001     EQUITY SECURITIES INDONESIA,PT
     
    

Maybe you are looking for