Need help with SQL Loader

I have a third-party site that transforms the information into a csv summary. I can't change the format, and they are not ready to give directly from db and db, so I try and then import it. I'm trying to use SQL Loader, but I can't seem to make it work. I looked in the documentation (VERY rare examples) as well as several websites and I can't find anything that can help out me.

Control file:
LOAD DATA
INFILE 'Daily_Diagnostics_test.csv'
BADFILE 'Diag_failed.csv'
APPEND
INTO TABLE ROAD_DIAGS
FIELDS TERMINATED BY ","
--WHEN VEHICLE != 'Vehicle' AND VEHICLE != 'Total'
(VEHICLE, DRIVER, START_DATE, START_TIME, START_TZ, END_DATE, END_TIME, END_TZ, 
 TM_DRV_MINS, TM_IDLE_MINS, TM_PTO_MINS, TRIP_TM_MINS,
 FUEL_DRV_GALS, FUEL_IDLE_GALS, FUEL_PTO_GALS, FUEL_TRIP_GALS, FUEL_START_GALS,
 MPG, DRV_MPG, START_ODOM, END_ODOM, DIFF_ODOM, AVG_MPH, MAX_MPH, MAX_RPM,
 DATE1, TM1, TZ1, ADDRESS_NUM1, ADDRESS_STREET1, ADDRESS_ST1, ADDRESS_ZIP1, ADDRESS_COUNTY1,
 DATE2, TM2, TZ2, ADDRESS_NUM2, ADDRESS_STREET2, ADDRESS_ST2, ADDRESS_ZIP2, ADDRESS_COUNTY2,
 STOP_CT, FAULT_CODE, HARD_BRAKE)
Note that the line WHEN is commented out, because I can't make it work.

and here is a sample of the data:
Vehicle,Driver,Start Date,Start Time,Timezone,End Date,End Time,Timezone,Driving (hh:mm),Idle (hh:mm),PTO (hh:mm),Trip (hh:mm),Driving (gals),Idle (gals),PTO (gals),Trip (gals),Before Trip (gals), MPG,Driving MPG,Start,End,Trip Distance (miles),Average(MPH),Maximum(MPH),Maximum RPM(rpm),Date,Time,Timezone,Address,Street,City,State,Zip,County,Date,Time,Timezone,Address,Street,City,State,Zip,County,Stop Count,Fault Code,Hard Brake,
26033, ,01/23/08,12:40 AM,MST,01/23/08,12:42 AM,MST,0,3,0,3,0,0.12,0,0.12, ,0,0,295829.22,295829.22,0,0,6.84, ,01/23/08,12:23 AM,MST,0,COUNTY ROAD 108,SAVAGE,MT,59262,RICHLAND,01/23/08,12:23 AM,MST,0,COUNTY ROAD 108,SAVAGE,MT,59262,RICHLAND,0,4, ,
26033, ,01/23/08,12:43 AM,MST,01/23/08,04:03 AM,MST,126,74,0,200,0,0,0,0, ,0,0,295829.22,295914.97,85.75,25.72,67.11, ,01/23/08,12:23 AM,MST,0,COUNTY ROAD 108,SAVAGE,MT,59262,RICHLAND,01/23/08,03:56 AM,MST,0,COUNTY ROAD 125,SIDNEY,MT,59270,RICHLAND,8,3, ,
26033, ,01/23/08,04:03 AM,MST,01/23/08,12:29 PM,MST,317,190,0,507,0,0,0,0, ,0,0,295914.97,296139.9,224.94,26.64,65.87, ,01/23/08,03:56 AM,MST,0,COUNTY ROAD 125,SIDNEY,MT,59270,RICHLAND,01/23/08,12:29 PM,MST,756,BELL RD,SIDNEY,MT,59270,RICHLAND,14,5, ,
Total, , , ,443,267,0,710,0,0.12,0,0.12, ,0,0,295829.22,296139.91,310.69,26.38,67.11, , , , , , , , , , , , , , , , , , , ,22,12,0,
Vehicle,Driver,Start Date,Start Time,Timezone,End Date,End Time,Timezone,Driving (hh:mm),Idle (hh:mm),PTO (hh:mm),Trip (hh:mm),Driving (gals),Idle (gals),PTO (gals),Trip (gals),Before Trip (gals), MPG,Driving MPG,Start,End,Trip Distance (miles),Average(MPH),Maximum(MPH),Maximum RPM(rpm),Date,Time,Timezone,Address,Street,City,State,Zip,County,Date,Time,Timezone,Address,Street,City,State,Zip,County,Stop Count,Fault Code,Hard Brake,
26035, ,01/23/08,03:59 AM,MST,01/23/08,09:05 AM,MST,222,85,0,306,50.87,1.5,0,52.37, ,3.32,3.42,285056.53,285230.5,173.98,34.07,68.97, ,01/23/08,03:24 AM,MST,756,BELL RD,SIDNEY,MT,59270,RICHLAND,01/23/08,09:00 AM,MST,0,COUNTY ROAD 338,SAVAGE,MT,59262,RICHLAND,7,3, ,
26035, ,01/23/08,09:06 AM,MST,01/23/08,03:37 PM,MST,273,118,0,391,68.5,1.5,0,70, ,3.24,3.31,285230.5,285457.3,226.8,34.8,69.59, ,01/23/08,09:00 AM,MST,0,COUNTY ROAD 338,SAVAGE,MT,59262,RICHLAND,01/23/08,03:37 PM,MST,756,BELL RD,SIDNEY,MT,59270,RICHLAND,11,3, ,
26035, ,01/23/08,03:45 PM,MST,01/23/08,04:38 PM,MST,32,21,0,53,7.37,0.25,0,7.62, ,3.42,3.54,285457.3,285483.4,26.1,29.73,67.73, ,01/23/08,03:37 PM,MST,756,BELL RD,SIDNEY,MT,59270,RICHLAND,01/23/08,04:33 PM,MST,0,COUNTY ROAD 108,SAVAGE,MT,59262,RICHLAND,2,3, ,
26035, ,01/23/08,04:49 PM,MST,01/23/08,10:22 PM,MST,256,76,0,332,52,1.25,0,53.25, ,3.71,3.8,285483.4,285681.0,197.6,35.67,64, ,01/23/08,04:33 PM,MST,0,COUNTY ROAD 108,SAVAGE,MT,59262,RICHLAND,01/23/08,10:17 PM,MST,0,COUNTY ROAD 108,SAVAGE,MT,59262,RICHLAND,9,3, ,
26035, ,01/23/08,10:25 PM,MST,01/23/08,10:35 PM,MST,4,5,0,10,0.37,0,0,0.37, ,1.68,1.68,285681.0,285681.62,0.62,3.9,24.85, ,01/23/08,10:17 PM,MST,0,COUNTY ROAD 108,SAVAGE,MT,59262,RICHLAND,01/23/08,10:35 PM,MST,0,COUNTY ROAD 338,SAVAGE,MT,59262,RICHLAND,1,5, ,
Total, , , ,787,305,0,1092,179.11,4.5,0,183.61, ,3.4,3.49,285056.53,285681.62,625.1,34.35,69.59, , , , , , , , , , , , , , , , , , , ,30,17,0,
As you can see, I need to have the SQL Loader to ignore the header and summary lines that appear for each grouping. Your suggestions are welcome as I need to implement this in an automatic process, I can call with a batch script.

blarman74 wrote:
Can anyone suggest how to fix this problem? The log file shows this error:

Record 8: Rejected - Error on table ROAD_DIAGS, column DATE2.
ORA-01858: a non-numeric character was found where a numeric was expected

The error message is clear - you try to load a value "non-date" in a DATE column and, therefore, sql * loader berms.
That points to a discrepancy between the list of columns in the control file and, in the data file.
Note the position of the table of the "DATE2" column in the table "ROAD_DIAGS":

test@XE>
test@XE> l
  1  select table_name,
  2         column_name,
  3         column_id
  4    from user_tab_columns
  5   where table_name='ROAD_DIAGS'
  6*    and column_name='DATE2'
test@XE> /

TABLE_NAME      COLUMN_NAME      COLUMN_ID
--------------- --------------- ----------
ROAD_DIAGS      DATE2                   34

test@XE>

If your control file specifies that the 34th column in the data file must be "DATE2". However-

test@XE>
test@XE> -- display the line number and the 34th column of the data file
test@XE>
test@XE> !perl -ne '{@a=split/,/; print $.,"\t",$a[33],"\n"}' Daily_Diagnostics_test.csv
1       County
2       RICHLAND
3       RICHLAND
4       RICHLAND
5
6       County
7       RICHLAND
8       RICHLAND
9       RICHLAND
10      RICHLAND
11      RICHLAND
12

test@XE>

the 34th column in your data file is 'COUNTY', which is counted in your control file.

Here is the list of the columns for 29 to 37 positions in the csv file:

test@XE>
test@XE> !perl -ne '{if ($. == 1) {@a=split/,/; foreach $i (28..36) {print $i+1,"\t",$a[$i],"\n"}}}' Daily_Diagnostics_test.csv
29      Address
30      Street
31      City
32      State
33      Zip
34      County
35      Date
36      Time
37      Timezone

test@XE>
test@XE>

And here are the columns specified in the control file:

  ...
  ...
  ADDRESS_NUM1,
  ADDRESS_STREET1,
  ADDRESS_ST1,
  ADDRESS_ZIP1,
  ADDRESS_COUNTY1,
  DATE2            DATE "MM/DD/YYYY",
  TM2              DATE "HH:MI AM",
  TZ2,
  ...
  ...

(You can open the csv file in MS Excel to get a better picture of the data in there).

As seen above, due to the incompatibility, sql * loader loads 'City' in ADDRESS_ST1, 'State' in ADDRESS_ZIP1, "Zip" in ADDRESS_COUNTY1 and DATE2 "County" - where it error.

The solution would be-

(a) If you want to load the 'City' information from the data file, and then add the "City" column in the table (if nonexistent) and specify in the control file.

(b) If you do not want to load the 'City' information from the data file, you can specify a column to 'FILL' in the file of control as follows:

  ...
  ...
  ADDRESS_NUM1,
  ADDRESS_STREET1,
  city1            FILLER,
  ADDRESS_ST1,
  ADDRESS_ZIP1,
  ADDRESS_COUNTY1,
  DATE2            DATE "MM/DD/YYYY",
  TM2              DATE "HH:MI AM",
  TZ2,
  ADDRESS_NUM2,
  ADDRESS_STREET2,
  city2            FILLER,
  ADDRESS_ST2,
  ADDRESS_ZIP2,
  ADDRESS_COUNTY2,
  ...
  ...

Hope that helps,
isotope

Tags: Database

Similar Questions

  • Need help with Sql Tunning

    Under Update taking 2 h complete 3000 sets.

    UPDATE ARR_TRANSACTIONS ARR

    SET = NUMBER99

    (SELECT ARR_1.NUMBER99

    OF ARR_TRANSACTIONS ARR_1, ARR_HEADER BH

    WHERE ARR_1.ARR_ID = BH. ARR_ID

    AND BH. FLAG = "Y".

    AND ARR_1.LINE_ID = ARR. ORIG_INV_LINE_ID

    AND ARR_1.NUMBER9 IS NOT NULL

    AND ROWNUM = 1)

    WHERE ARR BATCH_ID = 26219

    AND ARR. NUMBER99 IS NULL

    I added more some condition where to reduce cost and its working fine. But I need to rise more than performance on SQL.

    Please help with SQL.

    I do not see the number of 3000 lines in the plan - so I guess that the optimizer does not compute with the correct numbers. Could generate the plan with dbms_xplan.display_cursor? This could tell us something about filter predicates and access.

    In the given situation, I would check:

    • is the access to the index in step 1 (filtered by the relevant conditions: this could be BATCH_ID = 26219) return actually 248 entries (or something similar)?
    • Access table in step 2 returning 204 lines (or something similar) after applying the filters given? If the number of lines is much bigger then a Nested Loops is perhaps not a good idea.

    To make this much simpler check, you could create a plan with statistics of content (RowSource) given that the plan containing the real and the number of estimated rows.

    If the estimated cardinalities are not plausible the next question would be if the statistics are strong and up to date.

  • Need help with SQL/PL/SQL for Dates

    Hi Experts - need help with a SQL query.

    I need to insert some date fields in a table called CALENDAR_PERIOD.

    Current data in CALENDAR_PERIOD table with their data types:

    STARTPERIOD (DATE) YEAR (NUMBER) PERIOD_LABEL (Varchar2 255)

    02/11/2014 2014 2014/02/11 SUN

    03/11/2014 2014 14/03/11 MON

    04/11/2014 2014 11/04/14 MAR

    I have to increment above values up to the year 2025. I don't know how to write SQL and increment of these values.

    Ex: My next value should insert: 05/11/2015 2014 11/05/14 WED like that I need to insert data until 12 31, 2025.

    Can you please help me with PL/SQL block?

    Really appreciate your help!

    DB version:

    Oracle Database 11 g Enterprise Edition Release 11.2.0.3.0 - 64 bit Production

    PL/SQL Release 11.2.0.3.0 - Production

    CORE Production 11.2.0.3.0

    AMT for IBM/AIX RISC System/6000: Version 11.2.0.3.0 - Production

    NLSRTL Version 11.2.0.3.0 - Production

    Thank you
    Sandy

    Hello Sandy,

    Maybe something like

    INSERT INTO calendar_period (startperiod, year, period_label)

    SELECT DATE '' 2014-11-04 + LEVEL

    , TO_NUMBER (TO_CHAR (DATE '' 2014-11-04 + LEVEL, "YYYY"))

    , TO_CHAR (DATE '' 2014-11-04 + LEVEL, "MM/DD/YY DY")

    OF the double

    CONNECT BY LEVEL<= date="" '2025-12-314="" -="" date="">

    ;

    ((mais je ne comprends pas pourquoi nous créons une telle table "année" et "period_label" peuvent être calculé à partir de startperiod))

    Best regards

    Bruno Vroman.

  • Need help about sql loader

    Hello

    I will execute following command

    sqlldr admin_user@ces CONTROL = D:\sample_control.ctl log = D:\sample_log.log D:\Sample_bad.bad = bad

    In the case of valid data, it's inserted data properly into the table. While no valid records added in the wrong file.

    Now I want to restore whenever valid data that the number of bad record greater than equal to 10.

    In short, whenever the file has more than 10 invalid records, I don't want to insert any record of this file.

    Please give me the solution. Thanks in advance.

    SQL * Loader command line reference

    DISCARDMAX (Integer)

    Concerning

    Etbin

  • Need help with sql query

    Dear all,

    I have a sql like query below

    SELECT min (G.TRANSACTION_DATE), D.REQUEST_NUMBER

    MTL_TXN_REQUEST_HEADERS D,.

    MTL_TXN_REQUEST_LINES, E.

    MTL_MATERIAL_TRANSACTIONS G,.

    Mtl_Transaction_Types I have

    WHERE D.HEADER_ID = E.HEADER_ID

    AND G.TRANSACTION_TYPE_ID = I.TRANSACTION_TYPE_ID

    AND Upper (I.Transaction_Type_Name) = Upper ('TEC outcome')

    AND E.LINE_ID = G.MOVE_ORDER_LINE_ID

    AND D.MOVE_ORDER_TYPE = 5

    TO_DATE (G.TRANSACTION_DATE) BETWEEN TO_DATE('01-JAN-2014') AND TO_DATE('31-DEC-2014')

    D.REQUEST_NUMBER GROUP

    I need to get the first number of the application and finally ask for number based on the date of the transaction, how can I get the number of name application and based on the date of the transaction for the same query, please help me.

    above query is back under results

    results.jpg

    If the query should return a line with the number of application like 2383 based on minimum transaction date and another column based on the maximum transaction date, please help me.

    so in the example above, it must return

    FIRST REQUEST NUMBER LAST NUMBER

    2383                                      1886

    Thank you

    select min(request_number) keep(dense_rank first order by transaction_date asc ) request_number_min
         , min(request_number) keep(dense_rank first order by transaction_date desc) request_number_max
      from (
            select min(g.transaction_date) transaction_date
                 , d.request_number
              from mtl_txn_request_headers d
                 , mtl_txn_request_lines e
                 , mtl_material_transactions g
                 , mtl_transaction_types i
             where d.header_id                    = e.header_id
               and g.transaction_type_id          = i.transaction_type_id
               and upper(i.transaction_type_name) = upper('WIP Issue')
               and e.line_id                      = g.move_order_line_id
               and d.move_order_type              = 5
               and to_date(g.transaction_date) between to_date('01-jan-2014') and to_date('31-dec-2014')
             group
                by d.request_number
           )
    
  • Need help with sql query performance

    Dear all,

    I have a sql like query below, I need to give the following query please help me identify which statement I should tune to have better performanece.

    Select rownum LINE_NUM,

    A.LINE_ID,

    TO_CHAR (A.INVITMID),

    TO_NUMBER (A.PICKQTY),

    UNLOADINGPNT NULL,

    RRNUM NULL,

    WORKORDNUM NULL,

    WORKORDDESC NULL,

    A.PONUM,

    DTR_DUMB NULL,

    A.DESCRIPTION,

    FROM_SUB NULL,

    TO_SUB NULL,

    NO SOURCE,

    ASSET_NUMBER NULL,

    A.RECEIPTNUM,

    MOVEORD NULL,

    FROM_LOC NULL,

    TO_LOC NULL,

    MSD_NUM NULL,

    CONTAIN_LINE NULL,

    A.UOM,

    A.PO_RELEASE

    de)

    Select headerid Po.Po_Header_Id,

    rcv1. Po_Line_Id LINE_ID,

    rcv1.item_id INVITMID,

    (NVL(Rcv1.Transact_Qty,0)-NVL(rcv2.transact_qty,0)) PICKQTY,

    Po.Segment1 PONUM,

    Rcv1.Receipt_Num RECEIPTNUM,

    Rcv1.Item_Desc DESCRIPTION,

    Rcv1.Transact_Uom GLU,

    Rcv1.Po_release

    Po_Headers_All in.,.

    (Select rcv3. Po_Header_Id, RCV3.receipt_num, rcv3. Po_Line_Id, rcv3. Destination_Type_Code, rcv3. Item_Id, rcv3. Item_Desc, rcv3. Transact_Uom, SUM (rcv3. Transact_Qty) Transact_Qty, rcv3. PO_RELEASE OF)

    SELECT A.Po_Header_Id,

    C.RECEIPT_NUM receipt_num,

    A.Po_Line_Id,

    A.Destination_Type_Code,

    B.Item_Id,

    B.item_description Item_Desc,

    A.UNIT_OF_MEASURE Transact_Uom,

    A.QUANTITY Transact_Qty,

    D.RELEASE_NUM PO_RELEASE

    OF RCV_TRANSACTIONS,.

    RCV_SHIPMENT_HEADERS C.

    B RCV_SHIPMENT_LINES,

    PO_RELEASES_ALL D

    WHERE C.SHIPMENT_HEADER_ID = A.SHIPMENT_HEADER_ID

    AND B.SHIPMENT_LINE_ID = A.SHIPMENT_LINE_ID

    AND UPPER (A.Transaction_Type) = "to DELIVER".

    AND higher (A.Destination_Type_Code) = "EXPENSES".

    AND D.PO_RELEASE_ID = A.PO_RELEASE_ID

    UNION ALL

    SELECT A.Po_Header_Id,

    C.RECEIPT_NUM receipt_num,

    A.Po_Line_Id,

    A.Destination_Type_Code,

    B.Item_Id,

    B.item_description Item_Desc,

    A.UNIT_OF_MEASURE Transact_Uom,

    A.QUANTITY Transact_Qty,

    D.RELEASE_NUM PO_RELEASE

    OF RCV_TRANSACTIONS,.

    RCV_SHIPMENT_HEADERS C.

    B RCV_SHIPMENT_LINES,

    PO_RELEASES_ALL D

    WHERE C.SHIPMENT_HEADER_ID = A.SHIPMENT_HEADER_ID

    AND B.SHIPMENT_LINE_ID = A.SHIPMENT_LINE_ID

    AND B.ITEM_ID IS NULL

    AND UPPER (A.Transaction_Type) = "to DELIVER".

    AND higher (A.Destination_Type_Code) = "WORKSHOP".

    D.PO_RELEASE_ID AND = A.PO_RELEASE_ID) rcv3

    GROUP BY rcv3. Po_Header_Id, RCV3.receipt_num, rcv3. Po_Line_Id, rcv3. Destination_Type_Code, rcv3. Item_Id, rcv3. Item_Desc, rcv3. Transact_Uom, rcv3. Rcv1 PO_RELEASE),

    (SELECT A.PO_LINE_ID,

    Sum (A.Quantity) transact_qty,

    A.PO_HEADER_ID,

    C.RECEIPT_NUM

    OF RCV_TRANSACTIONS,.

    RCV_SHIPMENT_HEADERS C.

    B RCV_SHIPMENT_LINES,

    PO_RELEASES_ALL D

    WHERE C.SHIPMENT_HEADER_ID = A.SHIPMENT_HEADER_ID

    AND B.SHIPMENT_LINE_ID = A.SHIPMENT_LINE_ID

    AND UPPER (A.Transaction_Type) = "RETURN to the RECEPTION"

    AND D.PO_RELEASE_ID = A.PO_RELEASE_ID

    A.PO_LINE_ID, A.PO_HEADER_ID, C.RECEIPT_NUM GROUP) Rcv2

    Where Po.Po_Header_Id = Rcv1.Po_Header_Id (+)

    And Rcv1.Po_Line_Id = Rcv2.Po_Line_Id (+)

    And Rcv1.Receipt_Num = Rcv2.Receipt_Num (+)

    And Rcv1.Transact_Qty <>Nvl(Rcv2.Transact_Qty,999999999)

    Group of po.po_header_id, rcv1.po_line_id, po.segment1, rcv1.receipt_num, rcv1.item_id, Rcv1.Item_Desc, rcv1. TRANSACT_UOM, rcv1. PO_RELEASE, (NVL(Rcv1.Transact_Qty,0)-NVL(RCV2.transact_qty,0))) has

    Is my version of the database: Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64 bit Production

    Please find the attached PLAN to EXPLAIN.

    EXPLAINPLAN.jpg

    Thank you

    May be essentially the same join (between a, b, c and d) twice instead of three times

    sounds like it could be done with a single join (between a, b, c, and d), but you do not some columns than the columns of rcv1 rcv2

    We can work on what we can see only

    Select rownum line_num,

    rcv1.po_line_id line_id,

    TO_CHAR (rcv1.item_id) invitmid,

    NVL(rcv1.transact_qty,0) - nvl(rcv2.transact_qty,0) pickqty,

    unloadingpnt null,

    rrnum null,

    workordnum null,

    workorddesc null,

    Po. Ponum Segment1,

    dtr_dumb null,

    description of the rcv1.item_desc,

    from_sub null,

    to_sub null,

    No source,

    asset_number null,

    rcv1.receipt_num receiptnum,

    moveord null,

    from_loc null,

    to_loc null,

    msd_num null,

    contain_line null,

    Glu rcv1.transact_uom,

    rcv1.po_release

    of po_headers_all in.

    left outer join

    (select a.po_header_id,

    c.receipt_num,

    a.po_line_id,

    a.destination_type_code,

    b.item_id,

    b.item_description item_desc,

    a.unit_of_measure transact_uom,

    Sum (a.Quantity) transact_qty,

    d.release_num po_release

    from (select shipment_header_id,

    shipment_line_id,

    po_release_id,

    po_header_id,

    po_line_id,

    destination_type_code,

    unit_of_measure,

    quantity

    of rcv_transactions

    where upper (a.transaction_type) = "to DELIVER".

    and upper (a.destination_type_code) ('charge', 'WORKSHOP')

    ) a

    inner join

    rcv_shipment_lines b

    On a.shipment_line_id = b.shipment_line_id

    inner join

    c rcv_shipment_headers

    On a.shipment_header_id = c.shipment_header_id

    left outer join

    po_releases_all d

    On a.po_release_id = d.po_release_id

    where upper (a.destination_type_code) = "EXPENSES".

    or (upper (a.destination_type_code) = 'WORKSHOP'

    and b.item_id is null

    )

    A.po_header_id group,

    c.receipt_num,

    a.po_line_id,

    a.destination_type_code,

    b.item_id,

    b.item_description,

    a.unit_of_measure,

    d.release_num

    ) rcv1

    On po.po_header_id = rcv1.po_header_id

    left outer join

    (select a.po_line_id,

    Sum (a.Quantity) transact_qty,

    a.po_header_id,

    c.receipt_num

    from (select shipment_header_id,

    shipment_line_id,

    po_release_id,

    po_header_id,

    quantity

    of rcv_transactions

    where upper (a.transaction_type) = "RETURN to THE RECIPIENTS.

    ) a

    inner join

    rcv_shipment_lines b

    On a.shipment_line_id = b.shipment_line_id

    inner join

    c rcv_shipment_headers

    On a.shipment_header_id = c.shipment_header_id

    left outer join

    po_releases_all d

    On a.po_release_id = d.po_release_id

    A.po_line_id group,

    a.po_header_id,

    c.receipt_num

    ) rcv2

    On rcv1.po_line_id = rcv2.po_line_id

    and rcv1.receipt_num = rcv2.receipt_num

    where rcv1.transact_qty! = nvl(rcv2.transact_qty,999999999)

    Concerning

    Etbin

  • Help with SQL Loader when Clause

    I have 2 exact same structure Oracle tables.


    NUMBER OF ENO
    NUMBER OF PARENT
    NUMBER OF CHILDREN
    ENAME VARCHAR2 (50 bytes)
    ADDRESS VARCHAR2 (50 bytes)
    CITY VARCHAR2 (50 bytes)
    SRCFILENAME VARCHAR2 (50 bytes)
    SDATE VARCHAR2 (400 bytes)
    Current_Load VARCHAR2 (1 byte)




    Have a data file and a charger control file that loads data into these 2 tables.
    I need to make a conditional charge using a when clause.
    Condition: what MOTHER = CHILD, load table 2 other load in table 1

    My control file looks like this.
    LOAD DATA 
    INFILE 'TEST_20120815.txt' 
    APPEND INTO TABLE test1 
    fields terminated by "|" 
    trailing nullcols 
    ( 
    eno, 
    parent, 
    child, 
    ename, 
    address, 
    city , 
    sdate "to_date(:sdate,'DD/MM/YYYY')", 
    SrcFileName, 
    col7 filler, 
    "Current_Load" constant 'Y' 
    ) 
    INTO TABLE test2 when (parent=child) 
    fields terminated by "|" 
    trailing nullcols 
    ( 
    eno position(1), 
    parent, 
    child, 
    ename, 
    address, 
    city , 
    sdate "to_date(:sdate,'DD/MM/YYYY')", 
    SrcFileName, 
    col7 filler, 
    "Current_Load" constant 'Y' 
    ) 
    But it does not work. It works fine if I give a direct value like PARENT = 'P '.

    Any idea how compare the 2 fields while the conditional support?

    You can't compare 2 fields with the WHEN clause in SQL * file the charger control.
    only literal values as defined by the syntax:

    http://docs.Oracle.com/CD/B19306_01/server.102/b14215/ldr_control_file.htm#i1005657

    As already suggested, you'd be better to load data using an external table which allows to apply conditions you want in your SQL query, which is to get the data.

  • Need help with SQL Query - change of name history of audit table.

    I need your help to find the result in the following way...


    Emp No    New_name    Old_Name
    -----------------------------------------------
    1           Name3        Name2
    1           Name2        Name1
    create table emp(emp_id number(10),
    emp_name varchar(50),
    constraints emp_pk primary key(emp_id) );
    
    
    
    create table emp_audit(
    audit_id number(10),
    emp_id number(10),
    emp_name varchar(50),
    audit_date date,
    constraints emp_audit_pk primary key (audit_id),
    constraints  emp_audit_emp_fk foreign key(emp_id)  references emp(emp_id));
    
    insert into emp values(1,'Name3');
    
    
    insert into EMP_AUDIT (audit_id, emp_id, emp_name, audit_date)
    values (1, 1, 'Name1', to_date('14-08-2011', 'dd-mm-yyyy'));
    insert into EMP_AUDIT (audit_id, emp_id, emp_name, audit_date)
    values (2, 1, 'Name2', to_date('15-08-2011', 'dd-mm-yyyy'));
    commit;
    Thank you...

    Dipabkar Bédard (DB) wrote:

    We write is the query without using "partition by" in oracle...?

    with t as (
               select  audit_id,
                       emp_id,
                       emp_name,
                       row_number() over(order by audit_id) rn
                 from  emp_audit
                 order by emp_id,
                          audit_id
              )
    select  a.audit_id,
            a.emp_id,
            a.emp_name old_name,
            nvl(b.emp_name,(select c.emp_name from emp c where c.emp_id = a.emp_id)) new_name
      from  t a left join t b
            on (
                    b.emp_id = a.emp_id
                and
                    b.rn = a.rn + 1
               )
    /
    
      AUDIT_ID     EMP_ID OLD_NAME                                           NEW_NAME
    ---------- ---------- -------------------------------------------------- ------------
             1          1 Name1                                              Name2
             2          1 Name2                                              Name3
    
    SQL> 
    

    And without analytical functions:

    with t1 as (
                select  audit_id,
                        emp_id,
                        emp_name
                  from  emp_audit
                  order by emp_id,
                           audit_id
               ),
         t2 as (
                select  audit_id,
                        emp_id,
                        emp_name,
                        rownum rn
                  from  t1
               )
    select  a.audit_id,
            a.emp_id,
            a.emp_name old_name,
            nvl(b.emp_name,(select c.emp_name from emp c where c.emp_id = a.emp_id)) new_name
      from  t2 a left join t2 b
            on (
                    b.emp_id = a.emp_id
                and
                    b.rn = a.rn + 1
               )
    /
    
      AUDIT_ID     EMP_ID OLD_NAME                                           NEW_NAME
    ---------- ---------- -------------------------------------------------- ----------
             1          1 Name1                                              Name2
             2          1 Name2                                              Name3
    
    SQL> 
    

    SY.

  • Need help with sql, and bash

    Hi guys,.

    My main problem/situation is when sqlplus returns no data (no message selected lines)

    Bash shell script condition

    echo $open_items

    15 if [[$open_items == "0"]]

    16. can

    echo 17 0

    18 else

    19 1 echo

    20 fi

    and real sql is as follows:

    elect the count (*) a table with a condition.

    I get the output as follows:

    + open_items ='

    COUNT (*)

    ----------

    0'

    + echo 'COUNT (*)'---0

    COUNT ()) - 0

    + [[

    COUNT (*)

    ----------

    0 == \0 ]]

    + echo 1

    1

    What to do so that I can get a number in the output of sql is my question because the condition of shell script is based entirely on sqlplus out. I tried set feedback off, but it does not help.

    Any help would be much appreciated!

    SQL lover wrote:

    OK I try it and give you feedback

    In fact, I take out execution of sql into a variable

    MyVar = $(sqlplus-s/as sysdba)<>

    Set echo off feedback off verify off trimsp head off pages 0

    Select count (*) from dba_users;

    output

    EXPRESSIONS OF FOLKLORE)

    echo myvar is $myvar

  • Need help with SQL

    Hi all

    Database Version: 10g

    I have a situation where, as below:

    < select recipes

    Since then (select max (version_number), recipes

    of pa_budget_versions

    where project = 2304285

    and budget_status_code = 'B '.

    "trunc (creation_date) between 1 March 2014 ' and 30 March 2014"

    Income group) >

    I want to create a function with the above query and to return the amount of income.


    My query above returns the amount and date of data and the end of the beginning will be the settings I will pass. But if the query does not return the recipes for the start date and the end date, I want to go back a month and check if there are recipes, like this I wish to go back until I get the income.


    "Example: if I run the query for March 1, 2014 'and 30 March 2014 ' amount no., I want to continue and run to February 1, 2014' and 28 February 2014" and so on, continue until I get the income.


    Could you please help me to get this. Thank you.

    Thanks and greetings

    Srinivas

    Hello

    user2626293 wrote:

    ... could you please explain to me how does this WITH clause and how do you know that in a given situation, we have to use WITH the clause. ...

    I'm not sure that understand the question.

    A WITH clause that is very similar to a view.  Both allow you to use the result set of a query in the table.

    How can you know that when a WITH clause that is necessary?  As I explained in answer #22 above, a WITH clause that is rarely necessary; in most situations, you can use an online, or a regular view, instead.

    You want to know when a WITH clause or view online or a regular view is necessary?  Whenever you need to use the result set of a query as if it were a table.

    A set of common situation when you want to use the result of a query as if it were a table when you want to use the same calculation multiple times in a query.  In this example, I wanted to use the last_creation_date more than once.  I could have repeated the same exact calculation each time that I needed it, but it would be tedious, and it would make the code difficult to maintain and probably ineffective.  Instead, I calculated it once, in the subquery, I called got_last_creation_date.

  • need help with sql queries

    Dear all,

    I have a parameter like below

    11000048,11000050

    I need to convert in SQL format below, please help me

    "11000048","11000050"


    ' parameter would be so separated by commas, I need to convert in above format, if the parameter is a number say 1111111 must convert it as "1111111" in sql.


    Please help me.


    Thank you

    You can do it

    your_parameter: = "" ' | " Replace (your_parameter, ",", "",""). '"';

  • Need help with SQL statement

    So I am new to SQL and ORACLE. I need to know how to do the commands below in a single statement. I did it in two here, but I have no idea how do it in one. Any ideas?

    ALTER TABLE books
    ADD Catcode VARCHAR2 (3);

    ALTER TABLE books
    ADD CONSTRAINT books_catcode_fk FOREIGN KEY (catcode)
    REFERENCES (catcode) category;

    Any help appreciated ^^
    SQL> ed
    Wrote file afiedt.buf
    
      1  alter table books
      2    add( catcode varchar2(3),
      3         constraint books_catcode_fk
      4            foreign key( catcode )
      5*        references category( catcode ) )
    SQL> /
    
    Table altered.
    

    Justin

  • Need help with sql query involving distinct and County

    I have 2 tables and I want to get the number of specific names. Find the details below. It's hard to explain but I will try to provide as much detail as I can.

    Table A:
    ID of the SR
    1001 1
    1002 2
    2 1003
    1004 3


    Table B:
    Name of the key SrNew
    1 David 1001
    2 James 1002
    3 James 1002
    4 James 1003
    5 James 1004
    6 Mike 1004

    Result: I'm looking:
    Count names such as if the name appears for the same ID of Table A two times, and then only count 1.

    Name of County
    David 1
    James 2 (1002 and 1003 for the same ID (ID #2) so count as 1 for this and then 1 more for 1004 and ID 3)
    1 Mike


    I have following question:
    SELECT distinct (b.Name), a.ID
    FROM TableA, TableB b
    Where a.Sr = b.SrNew Group By b.Name, a.ID

    and as a result I get:
    ID name
    David 1
    James 2
    3 James
    3 Mike


    Now, I want to just the number of each name with the result, but don't know how I can do this with a sql?

    Thanks in advance.

    Who help me?

    SELECT b.Name, count(distinct a.ID)
    FROM TableA a, TableB b
    Where a.Sr = b.SrNew
    Group By b.Name
    

    Nicolas.

  • need help with SQL Server 2008 R2 deadlock uninstall process

    I installed SQL Server 2008 R2 trial version on my PC running Windows Vista Ultimate, a day ago, but he placed himself completely in the disk partition (E :) that I specified. [i.e. I found some parts of the installation in my C:\program files as well as a USB as well].

    I tried to uninstall SQL Server 2008 R2, but was only partially successful.  I'm prevented from uninsalling the main parts using the programs and features Panel - that is "Microsoft SQL Server 2008 R2" and "Microsoft SQL Server 2008 R2 Setup (in English).

    Still visible are:

    1 C:\Program Files (x 86) \Microsoft SQL Server

    2 C:\Program Files (x 86) \Microsoft Visual Studio 9.0

    3 C:\ProgramData\Microsoft\Windows\Start demarrer\programmes\microsoft SQL Server 2008 R2

    I would like your help to uninstall the other goals of SQL Server, so that I can do a clean install once more.

    Any advice on how SQL Server 2008 R2 evaluation version must be correctly installed what a future unistall is not messy, would be welcome.

    Hello

    Your question of Windows 7 is more complex than what is generally answered in the Microsoft Answers forums. It is better suited for the SQL Server forums. Please post your question in the SQL Server forums.

    http://social.msdn.Microsoft.com/forums/en/category/SQLServer

  • Need help with SQL strings

    Team,

    I have a requirement in my project where I need to subscribe to a channel of sup of the main chain and store them in the other column.

    for example,.

    I have a table with 2 columns and table has more than 500 discs.

    1st column has values as follows

    "High pressure 0.5 in.

    "Plate 0.3 in.

    ' Health 3.0 in.

    "" 8721 hygienic 1.0 in ""

    My requirement is that I have to take inches part and store in the 2nd column.

    my 2nd column must contain values such as 0.3, 0.5, 1.0, 0.3

    Thanks in advance,

    RAK

    Hey, Rak,

    This sounds like a job for regular expressions, particularly REGEXP_SUBSTR.

    Exactly how depends on your specific needs.  If the number always consists of 1 or more digits on either side of a decimal point, then

    REGEXP_SUBSTR (str

    , '\d+\.\d+'

    )

    Returns the number of the largest Dim Str as string.

    I hope that answers your question.

    If not, post a small example of data (CREATE TABLE and only relevant columns, INSERT statements) for all of the tables involved and the results desired from these data.

    Point where the above expression is to produce erroneous results, and explain, using specific examples, how you get the right results from data provided in these places.

    Always say what version of Oracle you are using (for example, 11.2.0.2.0).

Maybe you are looking for

  • Version 4. Where the orange Firefox in the upper left tab?

    After installing Firefox 4, I watched the tutorials. It is supposed to be a tab of orange color in the upper left corner of the browser - tab is called "Firefox". After installation, I found that I have no tab. Where is he? Is this necessary? I use X

  • Sony Action Cam live AS30 / V Out?

    Hello! Don't AS30 can live out AV while recording? I'm a fan of b.

  • multimedia keyboard wireless Shintaro & mouse

    Have installed the above and both work perfectly, however I want to configure the mouse so that I can get document flip when you press the scroll button, I can find the keyboard but not the mouse, only previous ones show on Control Panel, run of prog

  • print and scan the doctor does not

    Hello My printer is hp deskjet hp990cxi I have upgraded to windows 10 so now using the windows driver. I tried to use print and scan of the doctor. Search printer but can't find ink levels using ink supplys comes up with the message not connected or

  • How to use COM DLL in LabWindows

    Hello I have a COM .dll file that looks like this when opened with dll export viewer: I would like to use the Get4AxisPos function in LabWindows. I realized that, as I only have the .dll file, the only way to call these functions are the LoadLibrary(