How to Compare Data length of staging table with base table definition

Hi,
I've two tables :staging table and base table.
I'm getting data from flatfiles into staging table, as per requirement structure of staging table and base table(length of each and every column in staging table is 25% more to dump data without any errors) are different for ex :if we've city column with varchar length 40 in staging table it has 25 in base table.Once data is dumped into staging table I want to compare actual data length of each and every column in staging table with definition of base table(data_length for each and every column from all_tab_columns) and if any column differs length I need to update the corresponding row in staging table which also has a flag called err_length.
so for this I'm using cursor c1 is select length(a.id),length(a.name)... from staging_table;
cursor c2(name varchar2) is select data_length from all_tab_columns where table_name='BASE_TABLE' and column_name=name;
But we're getting data atonce in first query whereas in second cursor I need to get each and every column and then compare with first ?
Can anyone tell me how to get desired results?
Thanks,
Mahender.

This is a shot in the dark but, take a look at this example below:
SQL> DROP TABLE STAGING;
Table dropped.
SQL> DROP TABLE BASE;
Table dropped.
SQL> CREATE TABLE STAGING
  2  (
  3          ID              NUMBER
  4  ,       A               VARCHAR2(40)
  5  ,       B               VARCHAR2(40)
  6  ,       ERR_LENGTH      VARCHAR2(1)
  7  );
Table created.
SQL> CREATE TABLE BASE
  2  (
  3          ID      NUMBER
  4  ,       A       VARCHAR2(25)
  5  ,       B       VARCHAR2(25)
  6  );
Table created.
SQL> INSERT INTO STAGING VALUES (1,RPAD('X',26,'X'),RPAD('X',25,'X'),NULL);
1 row created.
SQL> INSERT INTO STAGING VALUES (2,RPAD('X',25,'X'),RPAD('X',26,'X'),NULL);
1 row created.
SQL> INSERT INTO STAGING VALUES (3,RPAD('X',25,'X'),RPAD('X',25,'X'),NULL);
1 row created.
SQL> COMMIT;
Commit complete.
SQL> SELECT * FROM STAGING;
        ID A                                        B                                        E
         1 XXXXXXXXXXXXXXXXXXXXXXXXXX               XXXXXXXXXXXXXXXXXXXXXXXXX
         2 XXXXXXXXXXXXXXXXXXXXXXXXX                XXXXXXXXXXXXXXXXXXXXXXXXXX
         3 XXXXXXXXXXXXXXXXXXXXXXXXX                XXXXXXXXXXXXXXXXXXXXXXXXX
SQL> UPDATE  STAGING ST
  2  SET     ERR_LENGTH = 'Y'
  3  WHERE   EXISTS
  4          (
  5                  WITH    columns_in_staging AS
  6                  (
  7                          /* Retrieve all the columns names for the staging table with the exception of the primary key column
  8                           * and order them alphabetically.
  9                           */
10                          SELECT  COLUMN_NAME
11                          ,       ROW_NUMBER() OVER (ORDER BY COLUMN_NAME) RN
12                          FROM    ALL_TAB_COLUMNS
13                          WHERE   TABLE_NAME='STAGING'
14                          AND     COLUMN_NAME != 'ID'
15                          ORDER BY 1
16                  ),      staging_unpivot AS
17                  (
18                          /* Using the columns_in_staging above UNPIVOT the result set so you get a record for each COLUMN value
19                           * for each record. The DECODE performs the unpivot and it works if the decode specifies the columns
20                           * in the same order as the ROW_NUMBER() function in columns_in_staging
21                           */
22                          SELECT  ID
23                          ,       COLUMN_NAME
24                          ,       DECODE
25                                  (
26                                          RN
27                                  ,       1,A
28                                  ,       2,B
29                                  )  AS VAL
30                          FROM            STAGING
31                          CROSS JOIN      COLUMNS_IN_STAGING
32                  )
33                  /*      Only return IDs for records that have at least one column value that exceeds the length. */
34                  SELECT  ID
35                  FROM
36                  (
37                          /* Join the unpivoted staging table to the ALL_TAB_COLUMNS table on the column names. Here we perform
38                           * the check to see if there are any differences in the length if so set a flag.
39                           */
40                          SELECT  STAGING_UNPIVOT.ID
41                          ,       (CASE WHEN ATC.DATA_LENGTH < LENGTH(STAGING_UNPIVOT.VAL) THEN 'Y' END) AS ERR_LENGTH_A
42                          ,       (CASE WHEN ATC.DATA_LENGTH < LENGTH(STAGING_UNPIVOT.VAL) THEN 'Y' END) AS ERR_LENGTH_B
43                          FROM    STAGING_UNPIVOT
44                          JOIN    ALL_TAB_COLUMNS ATC     ON ATC.COLUMN_NAME = STAGING_UNPIVOT.COLUMN_NAME
45                          WHERE   ATC.TABLE_NAME='BASE'
46                  )       A
47                  WHERE   COALESCE(ERR_LENGTH_A,ERR_LENGTH_B) IS NOT NULL
48                  AND     ST.ID = A.ID
49          )
50  /
2 rows updated.
SQL> SELECT * FROM STAGING;
        ID A                                        B                                        E
         1 XXXXXXXXXXXXXXXXXXXXXXXXXX               XXXXXXXXXXXXXXXXXXXXXXXXX                Y
         2 XXXXXXXXXXXXXXXXXXXXXXXXX                XXXXXXXXXXXXXXXXXXXXXXXXXX               Y
         3 XXXXXXXXXXXXXXXXXXXXXXXXX                XXXXXXXXXXXXXXXXXXXXXXXXXHopefully the comments make sense. If you have any questions please let me know.
This assumes the column names are the same between the staging and base tables. In addition as you add more columns to this table you'll have to add more CASE statements to check the length and update the COALESCE check as necessary.
Thanks!

Similar Messages

  • How to compare date in Varchar2(25 Byte) with dates

    We have Oracle SQL developer 1.2.1.
    I have a column "A" of type Varchar2(25 Bytes) which is getting data stored in below format,
    10/08/2009 12:04:23 AM
    I wante to comapre column A with dates so that I can delete the records older than (Sysdate - 30).
    Any help?

    Glad you found the solution yourself. Please mark the question as answered then.
    Also note this forum is for issues with the SQL Developer tool. Questions about SQL And PL/SQL should go to the forum with the that same name.
    Regards,
    K.

  • How to move data from a staging table to three entity tables #2

    Environment: SQL Server 2008 R2
    I have a few questions:
    How would I prevent duplicate records, when/ IF SSIS is executed many times?
    How would I know that all huge volume of data being loaded in the entity tables?
    In reference to "how to move data from a staging table to three entity tables ", since I am loading large volume of data, while using lookup transformation:
    which of the merge components is best suited.
    How to configure merge component correctly. (screen shot is preferred) 
    Please refer to the following link
    http://social.msdn.microsoft.com/Forums/en-US/5f2128c8-3ddd-4455-9076-05fa1902a62a/how-to-move-data-from-a-staging-table-to-three-entity-tables?forum=sqlintegrationservices

    You can use RowCount transformation in the path where you want to capture record details. Then inside rowcount transformation pass a integer variable to get count value inside
    the event handler can be configured as below
    Inside Execute SQL task add INSERT statement to add rowcount to your audit table
    Can you also show me how to Check against destination table using key columns inside a lookup task and insert only non
    matched records (No Match output)
    This is explained clearly in below link which Arthur posted
    http://www.sqlis.com/sqlis/post/Get-all-from-Table-A-that-isnt-in-Table-B.aspx
    For large data I would prefer doing this in T-SQL. So what you could do is dump data to staging table and then apply
    T-SQL MERGE between tables (or even a combination of INSERT/UPDATE statements)
    Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs

  • How to compare date and time together

    Hi,
    How to compare Date and Time together?
    For example in a database table there are two fields rundate and runtime.  I want to compare these two with perticular date and time in the program.  Like, I want to pull all the records where the records's date and time are less than a perticular date and time in the program.
    Hope the question is clear...
    Thanks.
    Kavita

    Hi Kavita
    There is no as such Date and Time Comparision FM in Standard SAP  But You can define your own like this
    <b>FUNCTION ZAV4_COMPAREDATETIME.
    ""Lokale Schnittstelle:
    *"  IMPORTING
    *"     REFERENCE(DATE1) TYPE  DATS
    *"     REFERENCE(TIME1) TYPE  TIMS
    *"     REFERENCE(DATE2) TYPE  DATS
    *"     REFERENCE(TIME2) TYPE  TIMS
    *"  EXPORTING
    *"     VALUE(TWOISMORETOPICAL) TYPE  C
      twoismoretopical = ''.
      if date2 > date1.
        twoismoretopical = 'X'.
      else.
         if date2 = date1 and time2 > time1.
           twoismoretopical = 'X'.
         endif.
      endif.
    ENDFUNCTION.</b>
    Regards
    Mithlesh

  • How to read data from a CLUSTER STRUCTURE not cluster table.

    Hi,
    how to read data from a CLUSTER STRUCTURE not cluster table.
    regards,
    Usha.

    Hello,
    A structre doesnt contain data.. so u cannot read from it. U need to find out table of that structure and read data from it.
    Regards,
    Mansi.

  • How to delete data from single field in a database table?

    Hi guys,
         Plz suggest me How to delete data from single field in a database table?
    thnks,
    pavan

    hi
    in addition to abv details..chk this:
    http://help.sap.com/saphelp_nw2004s/helpdata/en/fc/eb3aef358411d1829f0000e829fbfe/content.htm
    http://dev.mysql.com/doc/maxdb/en/34/ee7fbd293911d3a97d00a0c9449261/content.htm
    regards,
    madhu

  • How to extract data from info cube into an internal table using ABAP code

    HI
    Can Anyone plz suggest me
    How to extract data from info cube into an internal table using ABAP code like BAPI's or function modules.
    Thankx in advance
    regds
    AJAY

    HI Dinesh,
    Thankq for ur reply
    but i ahve already tried to use the function module.
    When I try to Use the function module RSDRI_INFOPOV_READ
    I get an information message "ERROR GENERATION TEST FRAME".
    can U plz tell me what could be the problem
    Bye
    AJAY

  • How to compare date which is greatest date

    iam new to sql
    how to compare date which date is greatest date with example
    can i use to_char to compare date
    SELECT eno, ename, GREATEST (TBLE.MAX1, TBLE.MAX2) recent_date "
                   FROM (SELECT TBLA.eno, TBLA.ename, "
                   MAX (TO_CHAR (TBL.date1, 'MM/DD/YYYY HH24:MI') "
                   ) MAX1, "
                   MAX (TO_CHAR (TBL.date2, 'MM/DD/YYYY HH24:MI') "
                   ) MAX2 "
                   FROM dual TBL, dual2 TBLA
    in above query if any one of the date having null value then recent_date is showing 'null'
    and also it showing wrong value
    example
    date1='08-22-2009' and date2='01-23-2010' then it showing wrong recent_datel ike='08-22-2009'
    as according my knowledge it is comparing with month it sholud not be like this wat i have to do pls explain with example my o/p should come for recent_date like =''01-23-2010''
    Edited by: user9112274 on Aug 27, 2010 5:31 AM

    Hi,
    there are numerous ways to compare dates, i give you some examples:
    with data_Sample as
    (select to_date('01-jan-2001','dd-mon-yyyy') d1, to_date('01-mar-2002','dd-mon-yyyy') d2, to_date('03-feb-2002','dd-mon-yyyy') d3 from dual)
    select greatest(d1,d2,d3) from data_Sample
    GREATEST(D1,D2,D3)
    3/1/2002
    with data_Sample as
    (select to_date('01-jan-2001','dd-mon-yyyy') d1 from dual union all
    select to_date('01-mar-2002','dd-mon-yyyy')   from dual union all
    select to_date('03-feb-2002','dd-mon-yyyy')  from dual)
    select max(d1) from data_Sample
    MAX(D1)
    3/1/2002
    declare
    d1 date :=to_date('01-jan-2001','dd-mon-yyyy');
    d2 date :=to_date('01-jan-2001','dd-mon-yyyy');
    begin
    if d1>d2 then
    dbms_output.PUT_LINE('d1 greater than d2');
    else
    dbms_output.PUT_LINE('d1 less or equql than d2');
    end if;
    end;
    output:
    d1 less or equal than d2now concerning your question:
    >
    can i use to_char to compare date
    >
    If you have date data types : don't convert them.
    if you have no choice, use something like:
    if to_char(d1,'YYYYMMDD') > to_char(d2,'YYYYMMDD') then
    else
    end if;Take care when you convert a date into a char format it becomes string comparison (with all it implies) (It's the reason why i've use an explicit mask format).

  • How to retrieve data from domain(Value Range)  of the table

    hi
    how to retrieve data from domain(Value Range)  of the table
    thanks

    Hello,
    You can try using the FM: DOMAIN_VALUE_GET TB_DOMAINVALUES_GET.
    BR,
    Suhas
    Edited by: Suhas Saha on Mar 24, 2009 10:08 AM

  • How to link TCJ_Documents table with BKPF table

    Dear all,
    i am new ABAPer, i need to join TCJ_Documents table with BKPF table.
    but, i can not find the relationship between this two tables.
    so, please help !
    thanks !

    Hi....
    There is a company code (BUKRS) in both tables.
    Also Fiscal year(GJAHR)...
    What is the problem with that?
    Sample code...
    data: begin of itab occurs 0,
          bukrs type bukrs,
          cjnr type cjnr,
          belnr type belnr_d,
          end of itab.
    start-of-selection.
    select p~bukrs p~belnr q~comp_code from bkpf as p
           inner join tcj_documents as q
           on p~bukrs = q~comp_code
           into table itab.
    loop at itab.
      write:/ itab-bukrs.
    endloop.
    Thanks,
    Naveen.i

  • Import tables with nested table : ORA-00600

    In Oracle 9.2
    Create object, type as table, and table with nested table (store as syms_ntab) are successfully.
    Also its export.
    In process of import on another server (also 9.2, 'fromuser=one touser=two') shows errors:
    . . importing table "SYMS_NTAB"
    IMP-00058: ORACLE error 600 encountered
    ORA-00600: internal error code, arguments: [kokeeafi1], [2], [2], [], [], [], [], []
    IMP-00075: Warning: The nested table may contain partial rows or duplicate rows
    But for all that table is created and error occur on phase inserting strings.
    What is this?
    In Oracle 8.0.5 i perform similar operation without error.

    From Oracle error messages and codes manual:
    ORA-00600 internal error code, arguments: [string], [string], [string], [string], [string], [string], [string], [string]
    Cause: This is the generic internal error number for Oracle program exceptions. It indicates that a process has encountered a low-level, unexpected condition. Causes of this message include:
    * timeouts
    * file corruption
    * failed data checks in memory
    * hardware, memory, or I/O errors
    * incorrectly restored files
    The first argument is the internal message number. Other arguments are various numbers, names, and character strings. The numbers may change meanings between different versions of Oracle.
    Action: Report this error to Oracle Support Services after gathering the following information:
    * events that led up to the error
    * the operations that were attempted that led to the error
    * the conditions of the operating system and databases at the time of the error
    * any unusual circumstances that occurred before receiving the ORA-00600 message
    * contents of any trace files generated by the error
    * the relevant portions of the Alter files
    Note: The cause of this message may manifest itself as different errors at different times. Be aware of the history of errors that occurred before this internal error.

  • Linking user table with system table

    Hello, I'm trying to link a user table with IC table in order to asign many sales person to a customer.
    I've created a new button in the IC form. When clicked a new form is opened to asign sales person to the IC. Now I need to retrieve the records assigned to this IC. How can I do that???
    Regards.
    Angel.

    Hi Angel,
    I would put a matrix in the new form where you could see/asign/delete the sales person.
    Have a look at this post where you can find a great code from Sebastian Danober to fill a matrix from a recordset.
    Another option could be to modify the existing IC form and add a new folder with a matrix where you can manage the sales person.
    Check this other post with code for adding folder to an existing form.
    Regards,
    Ibai Peñ

  • Partition exchange error on table with nested table

    On Oracle 11.2.0.1, I have a partitioned table with some partitions that need to be 'archived' (in terms of moving partitions to an 'archive' table).
    I have a source table like:
    CREATE TABLE IS_PODACI245
      ID_OBJEKTA_IDENTIFIKACIJA  NUMBER(10),
      ID_OBJEKTA                 NUMBER(20),
      DATUM                      TIMESTAMP(6)       NOT NULL,
      TZ                         NUMBER(3),
      DATA1                      NUMBER(10),
      DATA2                      NUMBER(6),
      DATA3                      NUMBER(10),
      DATA4                      NUMBER,
      DATA5                      T_NTCIP_CLIMATE_TABLE
    NESTED TABLE DATA5 STORE AS IS_PODACI245_STORE_TABLE
    TABLESPACE DATA
    PARTITION BY RANGE (DATUM)
      PARTITION P_201107 VALUES LESS THAN (TIMESTAMP' 2011-08-01 00:00:00')
        LOGGING
        NOCOMPRESS
        TABLESPACE DATA, 
      PARTITION P_MAXVALUE VALUES LESS THAN (MAXVALUE)
        LOGGING
        NOCOMPRESS
        TABLESPACE DATA
    NOCOMPRESS
    NOCACHE
    NOPARALLEL
    MONITORING;
    CREATE INDEX IDX_IS_PODACI245_KOMPLEKS ON IS_PODACI245
    (ID_OBJEKTA_IDENTIFIKACIJA, ID_OBJEKTA, DATUM)
      TABLESPACE DATA
    LOCAL ( 
      PARTITION P_201107
        LOGGING
        NOCOMPRESS
        TABLESPACE DATA, 
      PARTITION P_MAXVALUE
        LOGGING
        NOCOMPRESS
        TABLESPACE DATA
    NOPARALLEL;
    CREATE OR REPLACE TYPE t_ntcip_climate_table as table of t_ntcip_climate_fmt;
    CREATE OR REPLACE TYPE t_ntcip_climate_FMT as object
    (  dev_index number(6)
    ,   dev_description varchar2(512)
    ,   dev_type number(10)
    ,   dev_status number(10)
    ,   dev_mfr_status varchar2(512)
    ,   dev_active number(3)
    ,   dev_test_activation number(10)
    /I would like to make exchange partition using stage table, and everything is going fine on all tables, but only on a few of them (listed source is one of them, and they're only tables with nested tables wihin), where I get an error.. but sometimes ;)
    on a statement like:
    ALTER TABLE IS_PODACI245_ARH EXCHANGE PARTITION P_201106  WITH TABLE IS_PODACI245_STAGE EXCLUDING INDEXES  WITHOUT VALIDATION;I got an error:
    ORA-00001: unique constraint (TXV.SYS_C0032911) violated
    it's an unique index between parent and nested table.
    what could cause that problem?

    Dear,
    I suppose that the unique constraint
    ORA-00001: unique constraint (TXV.SYS_C0032911) violatedis the one you 've created on the nested table IS_PODACI245_STORE_TABLE
    If so, why not disable that constraint and try again.
    I have never exchanged such a kind of partitioned table having a nested table in it. But, I could imagine that the cloned non partitioned table IS_PODACI245_STAGE should at least be the exact image of the partitioned table IS_PODACI245_ARH (of course without the partition part) but with the nested table part and including all indexes
    In addition, if you have a parent/child relationship between your partitioned tables, then there is a chronological order of exchange starting by the child and then finishing by the parent
    see the following link for more information about this order of exchange (and comment 2 for an example also)
    http://jonathanlewis.wordpress.com/2006/12/10/drop-parent-partition/#more-65
    Hope this helps
    Mohamed Houri

  • Mix object tables with relational tables?

    Hallo,
    is it possible to mix object tables with relational tables in one database?
    I didn't succeed in assigning a foreign key from a relational table to an object table.
    Is this only working with column objects in relational tables?

    Hi
    is it possible to mix object tables with relational tables in one database?
    Every database contains both types of tables. So, it is basically not a problem.
    I didn't succeed in assigning a foreign key from a relational table to an object table.
    Is this only working with column objects in relational tables?It would be interesting to know how you tried... e.g. what error you get... Here an example (executed on 11.1).
    SQL> create or replace type tt as object ( n number );
      2  /
    SQL> create table ot of tt (constraint ot_pk primary key (n));
    SQL> create table rt (n number, constraint rt_ot_fk foreign key (n) references ot (n));
    SQL> insert into ot values (tt(1));
    SQL> insert into rt values (1);
    SQL> insert into rt values (2);
    insert into rt values (2)
    ERROR at line 1:
    ORA-02291: integrity constraint (OPS$CHA.RT_OT_FK) violated - parent key not foundHTH
    Chris

  • Join Istore table with AR tables

    Hi Gurus,
    How to join ibe_msites_b table with AR table. I am trying to get list of all customers from different mini sites. These are the AR tables i am using
    HZ_Cust_Accounts
    HZ_Parties
    Regards,

    The following query should give you resullts for B2C. Change the query based on your requirement incase if you want it for B2B. Please note that I haven't added alll the conditions. This should be your starting point.
    Hope this helps,
    RK
    SELECT imt.msite_name,
    hp.party_name
    FROM jtf_um_subscription_reg jusr,
    jtf_um_subscription_resp jure,
    fnd_responsibility fr,
    ibe_msite_resps_b imrb,
    ibe_msites_tl imt,
    fnd_user fu,
    hz_parties hp
    WHERE jusr.subscription_id = jure.subscription_id
    AND jure.responsibility_key = fr.responsibility_key
    AND fr.responsibility_id = imrb.responsibility_id
    AND imrb.msite_id = imt.msite_id
    AND imt.language = USERENV('LANG')
    AND fu.user_id =jusr.user_id
    AND fu.person_party_id = hp.party_id

Maybe you are looking for

  • Can i installed ios.6 on iphone 3gs

    can i installed ios.6 on iphone 3gs

  • Raising a notification from 3rd party software

    Hi We have a client looking at raising notifications within the asset management system of SAP via a sql/.net software application. The 3rd party software has a defect register which could be used to open the SAP notification. We would like to popula

  • Help with Help in CS5? - Flash specifically

    I recently upgraded to CS5 from CS3. Previously, in CS3, I always found Help to be very helpful and easy to use. Now, in CS5, I've found Help to be extremely difficult to use and cant find answers to my questions. Maybe im doing it wrong?? Maybe my H

  • RBC with attachment

    Hi Friends, Im working on SAP LSO, and we are using Request based correspondance (RBC). Is it possible to send an attachment with the correspondance? For example, if a learner is booked in a course, along with the booking confirmation mail that I sen

  • Which HDD

    Hello, i'm configuring a Mac Pro. Can anyone tell me why to pay € 319 for a 500 Gb Serial ATA disk? I'm new to Apple stuff so I don't know anything about compatibility, but Serial ATA seems Serial ATA to me and high-quality companies like Maxtor make