SQL Loader and batch ID

Hi all

In our application, we allow the user to download data using the worksheet in the excel user interface.

We use a PHP script in the user interface and using SQL Loader to load the data of insert_table excel sheet.

The insert_table has a primary key.


Here, my question is, is it possible to put some package for each download id in the table in an automatic way?

While we can easily extract data using the code batch

We use Oracle 11 g.

What is load a constant value, in which case you may as well use 815 constant in your control file. If you want to automatically increment the value of each batch, then you must use a different method.

Please see the example below. Before each data load, he loads the next value in the sequence into a separate table and then selects this value while loading data. Note that SQL * expression of charger that uses select must appear in parentheses in the double quotes.

SCOTT@orcl_11gR2> host type test1.dat
1 Prod1
2 Prod2
3 Prod3
4 Prod4
5 Prod5

SCOTT@orcl_11gR2> host type test2.dat
6 Prod6
7 Prod7
8 Prod8

SCOTT@orcl_11gR2> host type batch.ctl
options(load=1)
load data
replace
into table batch_tab
(batch_id expression "test_seq.nextval")

SCOTT@orcl_11gR2> host type data.ctl
load data
append
into table temp_table
fields terminated by whitespace
trailing nullcols
(p_id,
p_name,
batch_id expression "(select batch_id from batch_tab)")

SCOTT@orcl_11gR2> create table temp_table
  2    (p_id      number primary key,
  3     p_name    varchar2(6),
  4     batch_id  number)
  5  /

Table created.

SCOTT@orcl_11gR2> create sequence test_seq
  2  /

Sequence created.

SCOTT@orcl_11gR2> create table batch_tab
  2    (batch_id  number)
  3  /

Table created.

SCOTT@orcl_11gR2> -- first load:
SCOTT@orcl_11gR2> host sqlldr scott/tiger control=batch.ctl log=batch1.log

SQL*Loader: Release 11.2.0.1.0 - Production on Fri Apr 19 17:16:33 2013

Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.

Commit point reached - logical record count 1

SCOTT@orcl_11gR2> host sqlldr scott/tiger control=data.ctl data=test1.dat log=test1.log

SQL*Loader: Release 11.2.0.1.0 - Production on Fri Apr 19 17:16:33 2013

Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.

Commit point reached - logical record count 5

SCOTT@orcl_11gR2> select * from batch_tab
  2  /

  BATCH_ID
----------
         1

1 row selected.

SCOTT@orcl_11gR2> select * from temp_table
  2  /

      P_ID P_NAME   BATCH_ID
---------- ------ ----------
         1 Prod1           1
         2 Prod2           1
         3 Prod3           1
         4 Prod4           1
         5 Prod5           1

5 rows selected.

SCOTT@orcl_11gR2> -- second load:
SCOTT@orcl_11gR2> host sqlldr scott/tiger control=batch.ctl log=batch2.log

SQL*Loader: Release 11.2.0.1.0 - Production on Fri Apr 19 17:16:33 2013

Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.

Commit point reached - logical record count 1

SCOTT@orcl_11gR2> host sqlldr scott/tiger control=data.ctl data=test2.dat log=test2.log

SQL*Loader: Release 11.2.0.1.0 - Production on Fri Apr 19 17:16:33 2013

Copyright (c) 1982, 2009, Oracle and/or its affiliates.  All rights reserved.

Commit point reached - logical record count 3

SCOTT@orcl_11gR2> select * from batch_tab
  2  /

  BATCH_ID
----------
         2

1 row selected.

SCOTT@orcl_11gR2> select * from temp_table
  2  /

      P_ID P_NAME   BATCH_ID
---------- ------ ----------
         1 Prod1           1
         2 Prod2           1
         3 Prod3           1
         4 Prod4           1
         5 Prod5           1
         6 Prod6           2
         7 Prod7           2
         8 Prod8           2

8 rows selected.

Tags: Database

Similar Questions

  • SQL Loader and Oracle 11g

    Hello

    IM receiving a sqlldr: not found error. IM is going to discuss with our system of administration of the situation. Before I wanted to make sure that SQL Loader (sqlldr) is an add-on available for customer Oracle 11. A colleague mentioned SQLLDR maybe isn't available as an add-on in the Oracle 11 client and that we should rather use IMPORT/EXPORT. Is that a true statement?

    Can someone please clarify these questions for me?

    Thanks a bunch!

    SQL * Loader is certainly available in 11.1 or 11.2 full client install. It may or may not be a component that is installed by default according to the type of installation you choose during installation. But you can always go back and install this component.

    If you mean the instant customer, I'm not sure that SQL * Loader or import and export work with the Instant Client.

    And just to the point, if you are using 11g, you usually would using external tables rather than SQL * Loader.

    Justin

  • SQL * loader and sdo_geometry field

    Is it possible to load coordinates longitude/latitude of a flat file directly into a field sdo_geometry with sql * loader? If so, does anyone have an example? I just want to create point functions.

    Thank you
    David

    David,
    Section 4.1.2 of the space Guide has examples for this:

    DOWNLOAD THE DATA
    INFILE *.
    TRUNCATE
    CONTINUEIF NEXT(1:1) = ' # '.
    POINT OF TABLE
    FIELDS TERMINATED BY ' |'
    TRAILING NULLCOLS)
    GID INTEGER EXTERNAL,
    GEOMETRY COLUMN OBJECT
    (
    SDO_GTYPE INTEGER EXTERNAL,
    COLUMN SDO_POINT_TYPE OBJECT
    (X FLOAT EXTERNAL,
    THERE FLOAT EXTERNAL)
    )
    )

    BEGINDATA
    1. 2001 | -122.4215 | 37.7862 |
    2. 2001 | -122.4019 | 37.8052 |
    3. 2001 | -122.426 | 37.803 |
    4. 2001 | -122.4171 | 37.8034 |
    5. 2001 | -122.416151 | 37.8027228 |

    You must add the SRID field if you want to add the SRID for geometry.
    Or you can do this with SQL when the data is loaded into the DB.

    Siva

  • SQL Loader Help in 10g

    Hello

    Is it possible to abort the sql loader with force when a value is not present? I have data like this file

    1. XXX123 | XXX | 20121121 |
    4. XXX123 | XXX |
    5. XXX123 | XXX | 1.
    5. XXX123 | XXX | 2.
    5. XXX123 | XXX |
    9. XXX123 | XXX |

    Model:
    record type | Batch number. lot desc | date | detail line num | other

    1,4,5,9 are the types of records, if you see this line 5. XXX123 | XXX | 1| .. 1 represents a number of detail line, my requirement is if the number of detail line is null for the record type 5 then I want to abort the sqlloader.

    Is this possible?

    Published by: 940838 on November 21, 2012 23:54

    940838 wrote:
    I think that I am not clear in my requirement...

    The question was how to abort the charger if the number of detail line is not present in the record type 5. It is, however, normal detailing line num is not required for other types of records. points of view.

    Hello

    you were clear, and I did a quick test. Unfortunately you can not do this check in SQL * Loader as the WHEN in the control file clause allows not just GOLD.

    Even if you add this check using a constraint in your table and specify the maximum number of errors to 0, SQL * Loader will load the files until this error.

    Let me show you an example:

    (1) create a table with a constraint that, for record_type detail_line_number 5, may not be null.

    CREATE TABLE test
    (
       record_type    INTEGER
     , batch_number   VARCHAR2 (10)
     , batch_desc     VARCHAR2 (10)
     , batch_date     DATE
     , detail_line_num INTEGER
     , other          VARCHAR2 (10)
    );
    
    ALTER TABLE test
      ADD CONSTRAINT check_rec_5
         CHECK (   record_type = 5 AND detail_line_num IS NOT NULL
                OR record_type != 5) ENABLE;
                
    

    In this table, you will not be able to load lines with a record_type = 5 and NULL detail_line_num as this will be considered an error.

    We will prepare your input file:

    1|XXX123|XXX|20121121||
    4|XXX123|XXX|||
    5|XXX123|XXX||1|
    5|XXX123|XXX|||
    5|XXX123|XXX|||
    9|XXX123|XXX|||
    1|XXX123|XXX|20121121||
    4|XXX123|XXX|||
    5|XXX123|XXX||1|
    5|XXX123|XXX||2|
    5|XXX123|XXX|||
    9|XXX123|XXX|||1|XXX123|XXX|20121121||
    4|XXX123|XXX|||
    5|XXX123|XXX||1|
    5|XXX123|XXX||2|
    5|XXX123|XXX|||
    9|XXX123|XXX|||1|XXX123|XXX|20121121||
    4|XXX123|XXX|||
    5|XXX123|XXX||1|
    5|XXX123|XXX||2|
    

    As you can see that the input file has the fourth line with record_type = 5 and detail_line_num NULL. It is a mistake of the constraint.

    Here I used the control file:

    --test.ctl
    load data
    INFILE 'test.dat'
    APPEND
    INTO TABLE test
    FIELDS TERMINATED BY '|'
    TRAILING NULLCOLS
    (
     record_type     ,
     batch_number    ,
     batch_desc      ,
     batch_date      Date 'YYYYMMDD',
     detail_line_num ,
     other
    )
    

    If I try to run the SQL * Loader and ask to stop at the first error in this way:

    sqlldr userid=yourname/yourpass@yourdb control=test.ctl errors=0 rows=100
    

    SQL * Loader performs only 3 folders because it encounters an error in line 4 and having specified errors = 0 will not continue to load. In fact, the process will continue until she reached the point of validation (in this case 100 lines), but it is not loading any record after the error, or continue to read the file.

    So, if I check the table

    SELECT * FROM test;
    
    RECORD_TYPE BATCH_NUMBER BATCH_DESC BATCH_DATE            DETAIL_LINE_NUM OTHER
    ----------- ------------ ---------- --------------------- --------------- ----------
              1 XXX123       XXX        21-11-2012 00:00:00
              4 XXX123       XXX
              5 XXX123       XXX                                            1           
    

    You will only see the records until you have reached the error.

    This can be avoided, as documented in SQL * Loader manual reference:

    Load interrupted because they exceeded the maximum number of errors


    If the maximum number of errors is exceeded, SQL * Loader stops loading documents in any table and the work accomplished so far is committed.

    As you can see SQL * Loader to interrupt the treatment, but it engage in any case files until this error.

    Another solution is to create an external table in Oracle and do all the checks you want before you copy your table in a database table, as suggested BluShadow.

    Kind regards.
    Al

  • Reg: Problem SQL Loader-

    Hi Experts,

    I am trying to load data from a flat file in an Oracle table, but face some problems.

    Concern (1) (1)

    I have a directory where there are about 20 similar files named as 'rb_1', 'rb_2', 'rb_3', etc...

    All these data should be loaded in a Word only table 'X '.

    Is it possible that only 1 CTL file will make a loop and load all the files in X?

    Concern (2) (2)

    Field delimiter is Ctrl-X (CAN: cancel) and Ctrl-M (EM: em) characters

    Line delimiter is Ctrl-Z (SUB: substitute) and Ctrl-T (DC4: Device Control) characters

    Is there a way I can specify this in my CTL file?

    (I've only worked on delimiter of field as comma "«»", de champ comme virgule «», pas speciales personnages comme ca not special characters like that)

    Please let me know if any additional information is required.

    Help much appreciated.

    Thank you

    -Nordine


    Agree with Hoek, you'd better to use external tables you can specify multiple filenames at once, otherwise you will have a script that provides the name of the input file when calling sql loader and make this script loop for each file.

    Regarding the ctrl characters in your delimiters, control file supports the hexagonal versions of them for example

    fields terminated by ' 09 x. "

    where 9 is the hexagon of the ascii value of the character (in this case a tab character).

    CTRL-m, that would be x ' 0 of etc.

  • Option of SQL loader control file

    Hello

    I just started using sql loader and I doubt as a requirement.

    I used to get the first data file with 10 columns excel. We got a table with 10 columns backend and were load this excel file using sql loader.

    but since last week, they changed the data file and are now sending the data in column 8. what my condition is, for the other 2 columns, I want to insert text 'COLUMN_DROPPED' in the backend table. Rest 8 columns must be filled as usual.
    How can I handle files of control for this option?

    I just want to know the option that I why I am not providing control file.

    Thank you
    Puneet

    974647 wrote:
    My requirement is for the other 2 columns, I want to insert text 'COLUMN_DROPPED' in the backend table. Rest 8 columns must be filled as usual.

    First of all, it is only possible if remaining 2 column datatype is string (char/nchar, varchar2/nvarchar2, clob/nclob) and is at least 14 characters long. The rest is easy. Just change 2 last control file fields:

    column9  constant 'COLUMN_DROPPED',
    column10 constant 'COLUMN_DROPPED'
    

    SY.

  • SQL Loader insert string

    Hello

    I have recently started using SQL loader and got a request that I need assistance to do this: -.

    Lets say there is an excel file with the data to be loaded into the table 'test '. data from looks like this

    customer_id customer_location
    + new york 1 +.
    + new jersey 2 +.
    + california 3 +.


    My Test table looks like: -.

    create table test (customer_id number, client_name varchar2 (4000), customer_location varchar2 (200));


    My requirement is now that I need to write a control file that fills the field client_name with text "test_user" for each line of data file.

    So the final data should look like this: -.

    Select * from test;


    customer_id client_name customer_location
    + 1 test_user NYC +.
    + 2 test_user new jersey +.
    + 3 test_user California +.

    I use a direct charge. Please help me make the control file. I just want to know the logic for the settlement of the columns that are not present in great file.


    Thanks in advance.

    Edited by: 974647 April 1, 2013 10:17

    SQL * Loader supports constants. Read the definition of a column to a constant value.

    SY.

  • user input windows OS when loading data using sql loader

    Hello
    I have the oracle 11g Linux database.
    I have excel sheets with data that must be loaded into the database.
    I have oracle running on my windows client11g.

    When I or anyone else is running the load sql script to load the data, I need to capture the user OS (the one that runs the script of their windows login) and pass it via the sql loader and insert into the table as a column value outside the columns in the excel sheet.

    I think that this could be a very simple solution, I did some research but not just anywhere.
    Can someone guide me on this.

    Thanks in advance.
    Philip.

    Well, I built this example on the fly to show the answer. But it is based on documentation and previous experience with sql * loader or sys_context.

    SQL * Loader Control File Reference
    http://download.Oracle.com/docs/CD/E11882_01/server.112/e16536/ldr_control_file.htm#SUTIL005

    SQL * Loader field list reference
    http://download.Oracle.com/docs/CD/E11882_01/server.112/e16536/ldr_field_list.htm

    SQL - SYS_CONTEXT language reference
    http://download.Oracle.com/docs/CD/E11882_01/server.112/e17118/functions184.htm#SQLRF06117

    This forum is a good source of examples, as well as asktom.oracle.com

  • SQL * Loader invalid number error

    I'm trying to load a .csv using SQL * Loader and all ranks is rejected with an error invalid number.

    Here is the control file:

    OPTIONS (SKIP = 1)
    DOWNLOAD THE DATA
    INFILE 'shi_claims.csv '.
    REPLACE IN THE TABLE SHI_CLAIMS
    FIELDS ENDED BY ',' POSSIBLY FRAMED BY "" "
    TRAILING NULLCOLS
    (
    ID TANK
    DECIMAL EXTERNAL AMT
    )

    Here are the first lines of data in the .csv (note I am ignoring the first line):

    EmployeeID, PaidAmnt
    100550393,0
    100709611,120.04
    100795648,90
    100795648,5.24

    Here is the structure of the table, I'm trying to load:

    CREATE THE TABLE UST_GLOBAL. SHI_CLAIMS
    (
    ID VARCHAR2 (9 CHAR),
    AMT NUMBER (8.2)
    )

    Here's the .log file that results. All ranks lands in the .bad file.

    SQL * Loader: Release 10.2.0.4.0 - Production on Mon Mar 7 16:34:09 2011

    Copyright (c) 1982, 2007, Oracle. All rights reserved.

    Control file: /u02/sct/ust/shi_claims.ctl
    Data file:././data.7609732
    Bad leadership: 7609732.bad
    Delete the file: discard.7609732
    (Allow all releases)

    Number of loading: ALL
    Number of jump: 1
    Authorized errors: 50
    Link table: 64 lines, maximum of 256000 bytes
    Continuation of the debate: none is specified
    Path used: classics

    Table SHI_CLAIMS, loaded from every logical record.
    Insert the option in effect for this table: REPLACE TRAILING NULLCOLS option in effect

    Column Position Len term Encl. Datatype name
    ------------------------------ ---------- ----- ---- ---- ---------------------
    FIRST ID *, O ("") CHARACTER
    AMT NEXT *, O ("") CHARACTER

    Sheet 1: Rejected - error on the SHI_CLAIMS, AMT column table.
    ORA-01722: invalid number

    Sheet 2: Rejected - error on the SHI_CLAIMS, AMT column table.
    ORA-01722: invalid number

    (.. .and so forth for all ranks).

    I note that in the copy of the control file that is displayed in the .log file, the column AMT appears as a CHARACTER, while my control file means DECIMAL EXTERNAL. Could why, and this be part of the problem?

    Thanks for any help...

    Published by: wrfoster on March 8, 2011 09:40

    wrfoster wrote:
    Ideas on how to get rid of them?

    Well, ideally, if you can get rid of them when creating csv... If not do the AMT DUMP as I suggested previously to get the exact or the end characters ascii codes. Assuming that it is the new line of Chr (10) put the following text in the loader control file:

    AMT "RTRIM (:AMT,CHR(10)).

    SY.

  • Is SQL * Loader capable of replacing characters during load?

    Hello

    I have a table that is loaded into a DB Oracle with sql loader. Is it somehow possible to write a SPACE character instead of all the empty strings with the charger? I can illustrate what I need with this SQL code:
    update my_table 
    set first_column = ' ' 
    where first_column is null;
    Any suggestions?

    Thank you!

    my recommendation is to stop using SQL * LOADER and use of external tables, instead, it will give much better flexibility during the ETL and you do exactly what you ask

  • SQL LOADER vs INSTRUCTION INSERT

    1. What is the difference between Sql loader and insert statement?

    2. that will be more effective and better performance?

    3 Please give an example and explain.

    Please someone share their thoughts...

    Thanks in advance

    When you use sql loader you will use a direct path load i.e. you will be set up above the high tide and you will be bypassing undo on the table and it will insert in the index more efficiently.

    When you use insert / * + append * / select then you will be clooning the sqlloader but only if you do not have integrity constraint or insert triggers into your table.

    SQL Loder will be the direct loading path even if you have triggers and referential intergrity

    You see while sql loader seems to be more effective and not in function of the referential integrity or triggers to use a direct path load

    Concerning

    Mohamed Houri

  • What is SQL * Loader?

    Hello.
    I m using Oracle 10 g. I want what is SQL * Loader and how does it work?
    Tanx
    Sidibé

    Hello..

    SQL * Loader (sqlldr) is the utility to use for data loading performance. The data can be loaded from any text file and inserted in the database.

    Refer to [http://www.oracleutilities.com/OSUtil/sqlldr.html]

    In addition, you can find the document on [http://tahiti.oracle.com/]

    Anand

  • SQL Loader: Is it possible to set a variable?

    Hello all,.

    I'm loading of data with SQL Loader and find that I can put specific fields of the particular values using 'CONSTANT '. That's great. However, I am load several files in the same format and would like to 'label' each load. This would be by setting a variable before each load and then this to help write the month of the load (e.g. '200901') in the "SOURCE_FILE" column in the destination table.

    I imagine that the syntax would look something like this...

    DOWNLOAD THE DATA

    strSource = '200809'
    INFILE 'source_data_200809.csv '.
    strSource = '200810'
    INFILE 'source_data_200810.csv '.
    strSource = '200811'
    INFILE 'source_data_200811.csv '.

    ADD

    IN THE TABLE DESTINATION_TABLE
    FIELDS TERMINATED BY '; '. SURROUNDED OF POSSIBLY "" "
    TRAILING NULLCOLS
    (Char CUSTNO,
    Barcode tank,
    NAME char,
    Char SOURCE_FILE: strSource)

    Then, for each load I refer to the strSource variable and write the month appropriate in a column/field in the table.

    I've been googling and trawling through the documentation, but I can't seem to find a way to do it. Is this possible? Or maybe there's another method/path/tip for that? Or maybe it's just a matter of syntax?

    Any ideas?

    Kind regards
    Alan Searle

    Hello

    What will be the size of the file...?
    Instead, you can fill the data column in the .csv if possible in the worst case
    apply the ' TO_DATE (: fichier_source, 'YYYYMMDD').

    -Pavan Kumar N

  • SQL Loader for single registration repetitive data reading

    Hello

    I have my incoming data as follows:
    NAME, ID, Date1, Date2, Date3 Date4
    AST1_IDX1_EXCH_SERIES1, TD234512, (20070314,130000,112.5), (20070313,120000,112), (20070312,130000,116), (20070309,130000,115)
    AST2_IDX2_EXCH_SERIES2, TD234524, (20070314,130000,123.5), (20070313,120000,120.9), (20070312,130000,126.1), (20070309,130000,135.2)

    I have my DB such as:
    Create table (FACTOR)
    NAME VARCHAR2 (50).
    ID VARCHAR2 (20).
    DATE OF CLOSE_DATE,
    NUMBER OF CLOSE_TIME
    CLOSE_VALUE NUMBER (20,10)
    )

    I want to load the data so that the first two values go in columns (NAME, ID) and the other triplets go to the fields (CLOSE_DATE, CLOSE_TIME, CLOSE_VALUE) several times depending on the number of those present triplets. Is it possible to do so using SQL Loader?

    I'm trying to load this file (containing approximately 40000 these records) using SQL loader and tried options using CONTINUEIF, OBJECT of COLUMN, etc. but nothing works for me. Guidance in this regard will be highly appreciated.

    Thank you
    POOJA
  • Question to load data using sql loader in staging table, and then in the main tables!

    Hello

    I'm trying to load data into our main database table using SQL LOADER. data will be provided in separate pipes csv files.

    I have develop a shell script to load the data and it works fine except one thing.

    Here are the details of a data to re-create the problem.

    Staging of the structure of the table in which data will be filled using sql loader

    create table stg_cmts_data (cmts_token varchar2 (30), CMTS_IP varchar2 (20));

    create table stg_link_data (dhcp_token varchar2 (30), cmts_to_add varchar2 (200));

    create table stg_dhcp_data (dhcp_token varchar2 (30), DHCP_IP varchar2 (20));

    DATA in the csv file-

    for stg_cmts_data-

    cmts_map_03092015_1.csv

    WNLB-CMTS-01-1. 10.15.0.1

    WNLB-CMTS-02-2 | 10.15.16.1

    WNLB-CMTS-03-3. 10.15.48.1

    WNLB-CMTS-04-4. 10.15.80.1

    WNLB-CMTS-05-5. 10.15.96.1

    for stg_dhcp_data-

    dhcp_map_03092015_1.csv

    DHCP-1-1-1. 10.25.23.10, 25.26.14.01

    DHCP-1-1-2. 56.25.111.25, 100.25.2.01

    DHCP-1-1-3. 25.255.3.01, 89.20.147.258

    DHCP-1-1-4. 10.25.26.36, 200.32.58.69

    DHCP-1-1-5 | 80.25.47.369, 60.258.14.10

    for stg_link_data

    cmts_dhcp_link_map_0309151623_1.csv

    DHCP-1-1-1. WNLB-CMTS-01-1,WNLB-CMTS-02-2

    DHCP-1-1-2. WNLB-CMTS-03-3,WNLB-CMTS-04-4,WNLB-CMTS-05-5

    DHCP-1-1-3. WNLB-CMTS-01-1

    DHCP-1-1-4. WNLB-CMTS-05-8,WNLB-CMTS-05-6,WNLB-CMTS-05-0,WNLB-CMTS-03-3

    DHCP-1-1-5 | WNLB-CMTS-02-2,WNLB-CMTS-04-4,WNLB-CMTS-05-7

    WNLB-DHCP-1-13 | WNLB-CMTS-02-2

    Now, after loading these data in the staging of table I have to fill the main database table

    create table subntwk (subntwk_nm varchar2 (20), subntwk_ip varchar2 (30));

    create table link (link_nm varchar2 (50));

    SQL scripts that I created to load data is like.

    coil load_cmts.log

    Set serveroutput on

    DECLARE

    CURSOR c_stg_cmts IS SELECT *.

    OF stg_cmts_data;

    TYPE t_stg_cmts IS TABLE OF stg_cmts_data % ROWTYPE INDEX BY pls_integer;

    l_stg_cmts t_stg_cmts;

    l_cmts_cnt NUMBER;

    l_cnt NUMBER;

    NUMBER of l_cnt_1;

    BEGIN

    OPEN c_stg_cmts.

    Get the c_stg_cmts COLLECT in BULK IN l_stg_cmts;

    BECAUSE me IN l_stg_cmts. FIRST... l_stg_cmts. LAST

    LOOP

    SELECT COUNT (1)

    IN l_cmts_cnt

    OF subntwk

    WHERE subntwk_nm = l_stg_cmts (i) .cmts_token;

    IF l_cmts_cnt < 1 THEN

    INSERT

    IN SUBNTWK

    (

    subntwk_nm

    )

    VALUES

    (

    l_stg_cmts (i) .cmts_token

    );

    DBMS_OUTPUT. Put_line ("token has been added: ' |") l_stg_cmts (i) .cmts_token);

    ON THE OTHER

    DBMS_OUTPUT. Put_line ("token is already present'");

    END IF;

    WHEN l_stg_cmts EXIT. COUNT = 0;

    END LOOP;

    commit;

    EXCEPTION

    WHILE OTHERS THEN

    Dbms_output.put_line ('ERROR' |) SQLERRM);

    END;

    /

    output

    for dhcp


    coil load_dhcp.log

    Set serveroutput on

    DECLARE

    CURSOR c_stg_dhcp IS SELECT *.

    OF stg_dhcp_data;

    TYPE t_stg_dhcp IS TABLE OF stg_dhcp_data % ROWTYPE INDEX BY pls_integer;

    l_stg_dhcp t_stg_dhcp;

    l_dhcp_cnt NUMBER;

    l_cnt NUMBER;

    NUMBER of l_cnt_1;

    BEGIN

    OPEN c_stg_dhcp.

    Get the c_stg_dhcp COLLECT in BULK IN l_stg_dhcp;

    BECAUSE me IN l_stg_dhcp. FIRST... l_stg_dhcp. LAST

    LOOP

    SELECT COUNT (1)

    IN l_dhcp_cnt

    OF subntwk

    WHERE subntwk_nm = l_stg_dhcp (i) .dhcp_token;

    IF l_dhcp_cnt < 1 THEN

    INSERT

    IN SUBNTWK

    (

    subntwk_nm

    )

    VALUES

    (

    l_stg_dhcp (i) .dhcp_token

    );

    DBMS_OUTPUT. Put_line ("token has been added: ' |") l_stg_dhcp (i) .dhcp_token);

    ON THE OTHER

    DBMS_OUTPUT. Put_line ("token is already present'");

    END IF;

    WHEN l_stg_dhcp EXIT. COUNT = 0;

    END LOOP;

    commit;

    EXCEPTION

    WHILE OTHERS THEN

    Dbms_output.put_line ('ERROR' |) SQLERRM);

    END;

    /

    output

    for link -.

    coil load_link.log

    Set serveroutput on

    DECLARE

    l_cmts_1 VARCHAR2 (4000 CHAR);

    l_cmts_add VARCHAR2 (200 CHAR);

    l_dhcp_cnt NUMBER;

    l_cmts_cnt NUMBER;

    l_link_cnt NUMBER;

    l_add_link_nm VARCHAR2 (200 CHAR);

    BEGIN

    FOR (IN) r

    SELECT dhcp_token, cmts_to_add | ',' cmts_add

    OF stg_link_data

    )

    LOOP

    l_cmts_1: = r.cmts_add;

    l_cmts_add: = TRIM (SUBSTR (l_cmts_1, 1, INSTR (l_cmts_1, ',') - 1));

    SELECT COUNT (1)

    IN l_dhcp_cnt

    OF subntwk

    WHERE subntwk_nm = r.dhcp_token;

    IF l_dhcp_cnt = 0 THEN

    DBMS_OUTPUT. Put_line ("device not found: ' |") r.dhcp_token);

    ON THE OTHER

    While l_cmts_add IS NOT NULL

    LOOP

    l_add_link_nm: = r.dhcp_token |' _TO_' | l_cmts_add;

    SELECT COUNT (1)

    IN l_cmts_cnt

    OF subntwk

    WHERE subntwk_nm = TRIM (l_cmts_add);

    SELECT COUNT (1)

    IN l_link_cnt

    LINK

    WHERE link_nm = l_add_link_nm;

    IF l_cmts_cnt > 0 AND l_link_cnt = 0 THEN

    INSERT INTO link (link_nm)

    VALUES (l_add_link_nm);

    DBMS_OUTPUT. Put_line (l_add_link_nm |) » '||' Has been added. ") ;

    ELSIF l_link_cnt > 0 THEN

    DBMS_OUTPUT. Put_line (' link is already present: ' | l_add_link_nm);

    ELSIF l_cmts_cnt = 0 then

    DBMS_OUTPUT. Put_line (' no. CMTS FOUND for device to create the link: ' | l_cmts_add);

    END IF;

    l_cmts_1: = TRIM (SUBSTR (l_cmts_1, INSTR (l_cmts_1, ',') + 1));

    l_cmts_add: = TRIM (SUBSTR (l_cmts_1, 1, INSTR (l_cmts_1, ',') - 1));

    END LOOP;

    END IF;

    END LOOP;

    COMMIT;

    EXCEPTION

    WHILE OTHERS THEN

    Dbms_output.put_line ('ERROR' |) SQLERRM);

    END;

    /

    output

    control files -

    DOWNLOAD THE DATA

    INFILE 'cmts_data.csv '.

    ADD

    IN THE STG_CMTS_DATA TABLE

    When (cmts_token! = ") AND (cmts_token! = 'NULL') AND (cmts_token! = 'null')

    and (cmts_ip! = ") AND (cmts_ip! = 'NULL') AND (cmts_ip! = 'null')

    FIELDS TERMINATED BY ' |' SURROUNDED OF POSSIBLY "" "

    TRAILING NULLCOLS

    ('RTRIM (LTRIM (:cmts_token))' cmts_token,

    cmts_ip ' RTRIM (LTRIM(:cmts_ip)) ")". "

    for dhcp.


    DOWNLOAD THE DATA

    INFILE 'dhcp_data.csv '.

    ADD

    IN THE STG_DHCP_DATA TABLE

    When (dhcp_token! = ") AND (dhcp_token! = 'NULL') AND (dhcp_token! = 'null')

    and (dhcp_ip! = ") AND (dhcp_ip! = 'NULL') AND (dhcp_ip! = 'null')

    FIELDS TERMINATED BY ' |' SURROUNDED OF POSSIBLY "" "

    TRAILING NULLCOLS

    ('RTRIM (LTRIM (:dhcp_token))' dhcp_token,

    dhcp_ip ' RTRIM (LTRIM(:dhcp_ip)) ")". "

    for link -.

    DOWNLOAD THE DATA

    INFILE 'link_data.csv '.

    ADD

    IN THE STG_LINK_DATA TABLE

    When (dhcp_token! = ") AND (dhcp_token! = 'NULL') AND (dhcp_token! = 'null')

    and (cmts_to_add! = ") AND (cmts_to_add! = 'NULL') AND (cmts_to_add! = 'null')

    FIELDS TERMINATED BY ' |' SURROUNDED OF POSSIBLY "" "

    TRAILING NULLCOLS

    ('RTRIM (LTRIM (:dhcp_token))' dhcp_token,

    cmts_to_add TANK (4000) RTRIM (LTRIM(:cmts_to_add)) ")" ""

    SHELL SCRIPT-

    If [!-d / log]

    then

    Mkdir log

    FI

    If [!-d / finished]

    then

    mkdir makes

    FI

    If [!-d / bad]

    then

    bad mkdir

    FI

    nohup time sqlldr username/password@SID CONTROL = load_cmts_data.ctl LOG = log/ldr_cmts_data.log = log/ldr_cmts_data.bad DISCARD log/ldr_cmts_data.reject ERRORS = BAD = 100000 LIVE = TRUE PARALLEL = TRUE &

    nohup time username/password@SID @load_cmts.sql

    nohup time sqlldr username/password@SID CONTROL = load_dhcp_data.ctl LOG = log/ldr_dhcp_data.log = log/ldr_dhcp_data.bad DISCARD log/ldr_dhcp_data.reject ERRORS = BAD = 100000 LIVE = TRUE PARALLEL = TRUE &

    time nohup sqlplus username/password@SID @load_dhcp.sql

    nohup time sqlldr username/password@SID CONTROL = load_link_data.ctl LOG = log/ldr_link_data.log = log/ldr_link_data.bad DISCARD log/ldr_link_data.reject ERRORS = BAD = 100000 LIVE = TRUE PARALLEL = TRUE &

    time nohup sqlplus username/password@SID @load_link.sql

    MV *.log. / log

    If the problem I encounter is here for loading data in the link table that I check if DHCP is present in the subntwk table, then continue to another mistake of the newspaper. If CMTS then left create link to another error in the newspaper.

    Now that we can here multiple CMTS are associated with unique DHCP.

    So here in the table links to create the link, but for the last iteration of the loop, where I get separated by commas separate CMTS table stg_link_data it gives me log as not found CMTS.

    for example

    DHCP-1-1-1. WNLB-CMTS-01-1,WNLB-CMTS-02-2

    Here, I guess to link the dhcp-1-1-1 with balancing-CMTS-01-1 and wnlb-CMTS-02-2

    Theses all the data present in the subntwk table, but still it gives me journal wnlb-CMTS-02-2 could not be FOUND, but we have already loaded into the subntwk table.

    same thing is happening with all the CMTS table stg_link_data who are in the last (I think here you got what I'm trying to explain).

    But when I run the SQL scripts in the SQL Developer separately then it inserts all valid links in the table of links.

    Here, she should create 9 lines in the table of links, whereas now he creates only 5 rows.

    I use COMMIT in my script also but it only does not help me.

    Run these scripts in your machine let me know if you also get the same behavior I get.

    and please give me a solution I tried many thing from yesterday, but it's always the same.

    It is the table of link log

    link is already present: dhcp-1-1-1_TO_wnlb-cmts-01-1

    NOT FOUND CMTS for device to create the link: wnlb-CMTS-02-2

    link is already present: dhcp-1-1-2_TO_wnlb-cmts-03-3
    link is already present: dhcp-1-1-2_TO_wnlb-cmts-04-4

    NOT FOUND CMTS for device to create the link: wnlb-CMTS-05-5

    NOT FOUND CMTS for device to create the link: wnlb-CMTS-01-1

    NOT FOUND CMTS for device to create the link: wnlb-CMTS-05-8
    NOT FOUND CMTS for device to create the link: wnlb-CMTS-05-6
    NOT FOUND CMTS for device to create the link: wnlb-CMTS-05-0

    NOT FOUND CMTS for device to create the link: wnlb-CMTS-03-3

    link is already present: dhcp-1-1-5_TO_wnlb-cmts-02-2
    link is already present: dhcp-1-1-5_TO_wnlb-cmts-04-4

    NOT FOUND CMTS for device to create the link: wnlb-CMTS-05-7

    Device not found: wnlb-dhcp-1-13

    IF NEED MORE INFORMATION PLEASE LET ME KNOW

    Thank you

    I felt later in the night that during the loading in the staging table using UNIX machine he created the new line for each line. That is why the last CMTS is not found, for this I use the UNIX 2 BACK conversion and it starts to work perfectly.

    It was the dos2unix error!

    Thank you all for your interest and I may learn new things, as I have almost 10 months of experience in (PLSQL, SQL)

Maybe you are looking for