How to compare the length of the data to a staging table with the definition of the base table

Hello
I have two tables: staging of the table and the base table.
I get flatfiles data in the staging of the table, depending on the structure of the requirement of staging of the table and the base table (length of each column in the staging table is 25% more data dump without errors) are different for ex: If we have the city long varchar 40 column in table staging there 25 in the base table. Once data are discharged into the intermediate table that I want to compare the actual length of the data for each column in the staging table with the database table definition (data_length for each column of all_tab_columns) and if no column is different length that I need to update the corresponding line in the intermediate table which also has an indicator called err_length.

so for that I use the cursor c1 is select length (a.id), length (b.SID) of staging_table;
c2 (name varchar2) cursor is select data_length all_tab_columns where table_name = 'BASE_TABLE' and column_name = name;
But we get atonce data in the first query while the second slider, I need to get for each column and then compare with the first?
Can someone tell me how to get the desired results?

Thank you
Manoi.

Hey, Marco.

Of course, you can set src.err_length in the USING clause (where you can reference all_tab_columns) and use this value in the SET clause.
It is:

MERGE INTO  staging_table   dst
USING  (
       WITH     got_lengths     AS
                 (
          SELECT  MAX (CASE WHEN column_name = 'ENAME' THEN data_length END)     AS ename_len
          ,     MAX (CASE WHEN column_name = 'JOB'   THEN data_length END)     AS job_len
          FROM     all_tab_columns
          WHERE     owner          = 'SCOTT'
          AND     table_name     = 'EMP'
          )
     SELECT     s.ename
     ,     s.job
     ,     CASE WHEN LENGTH (s.ename) > l.ename_len THEN 'ENAME ' END     ||
          CASE WHEN LENGTH (s.job)   > l.job_len   THEN 'JOB '   END     AS err_length
     FROM     staging_table     s
     JOIN     got_lengths     l     ON     LENGTH (s.ename)     > l.ename_len
                         OR     LENGTH (s.job)          > l.job_len
     )     src
ON     (src.ename     = dst.ename)
WHEN MATCHED THEN UPDATE
     SET     dst.err_length     = src.err_length
;

As you can see, you have to hardcode the names of the columns common to several places. I swam () to simplify that, but I found an interesting (at least for me) alternative grouping function involving the STRAGG user_defined.
As you can see, only the subquery USING is changed.

MERGE INTO  staging_table   dst
USING  (
       SELECT       s.ename
       ,       s.job
       ,       STRAGG (l.column_name)     AS err_length
       FROM       staging_table          s
       JOIN       all_tab_columns     l
      ON       l.data_length  < LENGTH ( CASE  l.column_name
                                          WHEN  'ENAME'
                                THEN      ename
                                WHEN  'JOB'
                                THEN      job
                                   END
                           )
       WHERE     l.owner      = 'SCOTT'
       AND      l.table_name     = 'EMP'
       AND      l.data_type     = 'VARCHAR2'
       GROUP BY      s.ename
       ,           s.job
       )     src
ON     (src.ename     = dst.ename)
WHEN MATCHED THEN UPDATE
     SET     dst.err_length     = src.err_length
;

Instead of the user-defined STRAGG (that you can copy from AskTom), you can also use the undocumented, or from Oracle 11.2, WM_CONCAT LISTAGG built-in function.

Tags: Database

Similar Questions

  • How to compare the 2 versions of the same document in Pages?

    How to compare the 2 versions of the same document on Pages?

    There is no OS X Visual tool which can open two Pages document and show the differences between them - other than the human eye.

    What information are you interested in identify as different between the two documents? What specific version of Pages?

  • How to compare the content of two Wordpad / documents notebook without reading them line by line?

    How to compare the content of two Wordpad / documents notebook without reading them line by line?

    Hello

    Without this feature is included in the operating system.

    However, you can use your favorite search engine to look for software that needs to perform these tasks.

    WARNING of THIRD PARTY SOFTWARE: Using third-party software, including hardware drivers can cause serious problems that may prevent your computer from starting properly. Microsoft cannot guarantee that problems resulting from the use of third-party software can be solved. Software using third party is at your own risk.

    Hope this information helps.

  • HOW TO COMPARE THE REGULAR TEACHER VS VERSIONS?

    HOW TO COMPARE THE REGULAR TEACHER VS VERSIONS?

    Thank you

    An educational version of Photoshop Elements are totally same (feature wise) than the regular commercial versions. So, it is unnecessary to compare.

  • How to compare the new values with the old values in triggers.

    Dear all,

    Please tell me how to compare the new values with the old values in triggers.

    Hi, the employee example is in the document. You'd better read yourself.

    CREATE OR REPLACE TRIGGER Print_salary_changes
      BEFORE DELETE OR INSERT OR UPDATE ON Emp_tab
      FOR EACH ROW
    WHEN (new.Empno > 0)
    DECLARE
        sal_diff number;
    BEGIN
        sal_diff  := :new.sal  - :old.sal;
        dbms_output.put('Old salary: ' || :old.sal);
        dbms_output.put('  New salary: ' || :new.sal);
        dbms_output.put_line('  Difference ' || sal_diff);
    END;
    /
    
  • How to compare the structure of multiple tables... have just TOAD &amp; CAULK

    Hello

    Several times, I get a request to load the data in the tables of one schema to another. But before doing that I need to compare the structures of tables in the source and target schema.

    How can I do? The list of tables to continue to change every now and then. A TOAD there is no option to compare a selected table list. Comparing schemas whole is not an option before me that patterns are too huge and it takes a lot of time to do the level schema comparison.
    Note This is a client machine, and we are not allowed to install any s/w.


    I'm working on the provision of a unix script that does this for me. But that may take some time given the intense work schedule and my lack of knowledge of unix scripting languages.

    Can anyone suggest a way to do it?

    Regds,
    Malika

    I need to compare the structures of tables in the schema source & target.

    SELECT THE TABLE TABLE_NAME, COLUMN_NAME, DATA_TYPE, DATA_TYPE_MOD, DATA_TYPE_OWNER, DATA_LENGTH, DATA_PRECISION, DATA_SCALE DBA_TAB_COLUMNS WHERE OWNER = 'SOURCE '.
    LESS
    SELECT THE TABLE TABLE_NAME, COLUMN_NAME, DATA_TYPE, DATA_TYPE_MOD, DATA_TYPE_OWNER, DATA_LENGTH, DATA_PRECISION, DATA_SCALE DBA_TAB_COLUMNS WHERE OWNER = 'TARGET'
    UNION
    SELECT THE TABLE TABLE_NAME, COLUMN_NAME, DATA_TYPE, DATA_TYPE_MOD, DATA_TYPE_OWNER, DATA_LENGTH, DATA_PRECISION, DATA_SCALE DBA_TAB_COLUMNS WHERE OWNER = 'TARGET'
    LESS
    SELECT THE TABLE TABLE_NAME, COLUMN_NAME, DATA_TYPE, DATA_TYPE_MOD, DATA_TYPE_OWNER, DATA_LENGTH, DATA_PRECISION, DATA_SCALE DBA_TAB_COLUMNS WHERE OWNER = 'SOURCE '.

  • How to compare the time slices in 15 minutes?

    Using Flash 8 Pro AS2

    Have an animation to play once at the first visit to the site, regardless of the number of pages visited within the site. Then start over when to return to site.

    I thought that SharedObject would work for this. I managed to do it run at the same time to visit the site and the value of the shared object. Problem is that the animation NEVER play again because the shared object is never removed.

    Is there a way to put so it was like a session then that would solve this easy. I don't know how to do if there is a way.

    So I decided to make the swf file to check the page reload or if come back once again, site 15 minutes has elapsed. If so, update the time in being shared right now and the animation playback.

    Problem is that I have NO idea how compare the time set in the shared object at the moment to check whether or not the 15 minutes has passed.

    I tried different things, but the comparison, at the end of the hour, goes into the negative numbers. I am here minutes passing between saved time and the current time. Nothing else for a few minutes.

    I'm not a mathematical genius or understand all the stuff that I see out there in the tutorials and code examples, when it comes to the date and the time of calculation.

    I need to be. Delete the shared object to the closure or the site navigation browser.
    OR
    Check if 15 minutes has passed then at day time in the shared object and read the animation

    I'm just stuck in the calculation of time to determine whether or not the 15 minutes passed.

    What happens if they return to the site of the days or even weeks? My minutes of follow-up test has no meaning when entering hours and days or even weeks or months. Of course, my approach does NOT work.

    Any help would be great. Don't forget to Flash 8 pro and AS2 NOT AS3 or flash 9.


    Thank you

    I don't know how you look at the time, but if you create a DATE object:

    var today: Date = new Date(); It's actually an object of date and time.

    So, if you compare this date and time with an earlier date object and the object of time by using the Date method getTime() as follows

    Now.getTime () - previousDate.getTime () = the number of milliseconds that have elapsed between the "previousDate' and 'now '. If the difference is > 15 * 60 * 1000, 15 minutes.

  • How to compare the original value of table size and the changed value

    juice I took a table and then took the function of the size of the array so that it shows me the number of the elements present in it. so it'll be the original table size value. If the items in the table even changes another value, then I want to compare the original table size value and the value of table size has changed. How to compare... Please help me. you are looking for a possible solution. Thank you

    Hi stara,

    the attached picture shows the ony solution.

    It will be useful.

    Mike

  • How to compare the current password encrypted pasword enter APEX4.1

    Hi all
    In my application uses the following package
    create or replace PACKAGE BODY app_security_pkg
    AS
    PROCEDURE login 
              (
               p_uname IN VARCHAR2
              ,p_password IN VARCHAR2
              ,p_session_id IN VARCHAR2
              ,p_flow_page IN VARCHAR2
              )
    IS
     lv_goto_page NUMBER DEFAULT 1;
    BEGIN
     
     -- This logic is a demonstration of how to redirect 
     -- to different pages depending on who successfully 
     -- authenticates. In my example, it simply demonstrates 
     -- the ADMIN user going to page 1 and all other users going
     -- to page 2. Add you own logic here to detrmin which page 
     -- a user should be directed to post authentication.
     IF UPPER(p_uname) = 'ADMIN'
     THEN
      lv_goto_page := 1;
     ELSE
      lv_goto_page := 2;
     END IF;
    
    APEX_UTIL.SET_SESSION_STATE('FSP_AFTER_LOGIN_URL');
    
     wwv_flow_custom_auth_std.login 
     (
      p_uname => p_uname,
      p_password => p_password,
      p_session_id => p_session_id,
      p_flow_page => p_flow_page || ':' || lv_goto_page
      );
    
    EXCEPTION
    WHEN OTHERS
    THEN 
     RAISE;
    END login;
    
    PROCEDURE add_user 
    (
     p_username IN VARCHAR2
    ,p_password IN VARCHAR2
    )
    AS
    BEGIN
    INSERT INTO app_users (username, PASSWORD)
        VALUES (UPPER (p_username),
            get_hash (TRIM (p_username), p_password));
    
    COMMIT;
    
    EXCEPTION
    WHEN OTHERS
    THEN 
     ROLLBACK; 
     RAISE;
    END add_user;
    
    -- Function to Perform a oneway hash of the users 
    -- passwords. This cannot be reversed. This exmaple 
    -- is a very week hash and if been used on a production 
    -- system, you may want to use a stronger hash algorithm.
    -- Read the Documentation for more info on DBMS_CRYPTO as 
    -- this is the supported package from Oracle and 
    -- DBMS_OBFUSCATION_TOOLKIT is now depricated.
    FUNCTION get_hash (p_username IN VARCHAR2, p_password IN VARCHAR2)
    RETURN VARCHAR2
    AS
    BEGIN
    RETURN DBMS_OBFUSCATION_TOOLKIT.md5 (
    input_string => UPPER (p_username) 
                    || '/' 
                    || UPPER (p_password));
    END get_hash;
    
    PROCEDURE valid_user2 (p_username IN VARCHAR2, p_password IN VARCHAR2)
    AS
    v_dummy VARCHAR2 (1);
    BEGIN
    SELECT '1'
    INTO v_dummy
    FROM app_users
    WHERE UPPER (username) = UPPER (p_username)
    AND PASSWORD = get_hash (p_username, p_password);
    EXCEPTION
    WHEN NO_DATA_FOUND
    THEN raise_application_error (-20000, 'Invalid username / password.');
    END valid_user2;
    
    FUNCTION valid_user (p_username IN VARCHAR2, p_password IN VARCHAR2)
    RETURN BOOLEAN
    AS
    BEGIN
    valid_user2 (UPPER (p_username), p_password);
    RETURN TRUE;
    EXCEPTION
    WHEN OTHERS
    THEN RETURN FALSE;
    END valid_user;
    
    END app_security_pkg;
    Here the ADD_USER procedure will convert the password and stores in the Table app_users in encrypted form.

    In my application, users can change their password,
    So I need to compare the password entering the Current_password field with the password encrypted in the app_users table.
    So I used the following code,
    declare
      l_x varchar2(30);
    begin
      select username into l_x
            from app_users
        where upper(username) = upper(:P7_USERNAME)
          and password = :P7_CURRENT_PASSWORD;
      return (true);
    exception
      when no_data_found then
        return (false);
    end;
    This code works fine when the password is stored without encryption, but it displays error, after encryption

    because the password entered is simply password and not encrypted if the two are different even if the user enters the correct password.

    Please tel me how encrypt the entered password to compare with the encrypted password.

    Thank you
    Kind regards
    gurujothi.

    Hi guru,.

    When you say comparing it is obvious that both must be in the same format, so either you have to compare both encrypted or not encrypted.

    Do you have an example on apex.oracle.com?

    Thank you

  • How to compare the source of PL/SQL in two databases using a clever trick

    Hello
    Here is my scenario:

    We have a very large (> 50) team of developers who work on PL/SQL.
    As and as new improvements/fixes are tested successfully, DBA migrates the new source code for DEV to QA, then the PROD instance.

    Very often, the developers are invited to check if the source code migrated to the instance target is the right. This Yes, because we use an automated migration tools... .and sometimes DBA can make mistake in migrating the wrong version (say a beta code).

    So that developers are left with comparing the source manually or by using the file compare tools... a very tedious job.
    (I know not a strict discipline to keep a barrette and version will help you; but we have a lot of existing code that does not adhere to this rule)

    So, is it possible to do ' intelligently '... I thought of a way to get the code of HASH/HASHKEY of all lines of source code of a procedure or a pkg and then again to get the HASHCODE/HASHKEY of all codes/HASHKEYs of lines of source for a particular package. to get a unique HASHKEY for a pkg... .and then I can compare this HASHKEY of 2 bodies... and they are same, means the code is the same... Otherwise, the code is different

    for example
    Select custom_hashkey_prc (text) from dba_source, whose name = "MY_PKG.

    Thank you.

    Published by: DT1977 on January 19, 2009 15:31

    Using a HASH to check if the two sources are the same would be a valid way to do a quick check, although it will obviously not be to tell you where the differences are.

    In Oracle 10 g, you can use the DBMS_CRYPTO package to generate HASH values...

    http://www.psoug.org/reference/dbms_crypto.html

    We use this method to detect changes in the data where exist CLOB columns (because we cannot use set operators of SQL on CLOB).

  • How to compare the contents of the cell against a series list range of values?

    Hi all! I really need help.

    I have tried to help myself using the formula of numbers and other discussions Apple guide but do not find a method using the info. Unfortunately, in two days and no work done, I feel rather useless! I read the guides but I can't understand the syntax, or the use, if, AND, OR, etc..

    I have a list of about 800 alphanumeric codes. There are about 80 I want to "stand out". About 30 of them I can isolate content in the adjacent cell, but the other 50 are repeats of the first 30 but are without cells adjacent "filterable" so I can't isolate easily. I thought that I could create a formula that would give rise to 'TRUE' IF (-none of the 30 listed alphanumeric codes appear in column A). Something like:

    = IF (A2 = (AFS4572 OR HFU9372 OR UWK1993 OR EPD5490), "TRUE", "FALSE")

    or written more readable

    = IF (A2 = (AFS4572, HFU9372, UWK1993, EPD5490), 'TRUE', 'FALSE')

    Can someone help me with a formula?

    Or at least some information on:

    (a) how to think straight

    (b) recommend a reasonable way to learn the syntax of the formula numbers?

    Hello

    COUNTIF() would be your friend as shown in column B in the following example. Column C shows how to use the OR() function if you have a particular reason to select.

    For example,.

    Table 1 (excerpt)
    
    A1  code
    A2  HFU9372
    A3  EPD5490
    A4  AFS4572
       
    B1 
    B2  =COUNTIF(CODES::A,A2)>0
    B3  =COUNTIF(CODES::A,A3)>0
    B4  =COUNTIF(CODES::A,A4)>0
       
    C1 
    C2  =OR(A2="AFS4572",A2="HFU9372",A2="UWK1993",A2="EPD5490")
    C3  =OR(A3="AFS4572",A3="HFU9372",A3="UWK1993",A3="EPD5490")
    C4  =OR(A4="AFS4572",A4="HFU9372",A4="UWK1993",A4="EPD5490")
    

    Notes.

    Formula in B2 and C2 can be filled down.

    The table is bulit with numbers v2.

    Kind regards

    H

  • How to compare the content of two files so I can delete duplicate records

    I'm trying to clean up several subfolders with duplicates without looking at the details of each record.  Is it possible in Windows XP to compare the content of two files whether they are an exact replica.

    Hi rav42010,

    Follow the steps in the article.

    Description of the tool in Windows XP disk cleanup

    http://support.Microsoft.com/kb/310312

    You can also use third-party app to perform the task using your favorite search engine.

    Note: Using third-party software, including hardware drivers can cause serious problems that may prevent your computer from starting properly. Microsoft cannot guarantee that problems resulting from the use of third-party software can be solved. Software using third party is at your own risk.

  • How to compare the U2412M with the old 2407FPW?

    I had the 2407FPW since ' 07 and love it. I like the picture not bright. I'm about to order a new Dell and I wonder if the U2412M is comparable in quality? It has the same resolution (1920 x 1200), in contrast to the other Dell Ultrasharp 24 "monitor that is only 1920 x 1080.

    Joe

    2407WFP panels = S - PVA Samsung (LTM240M2) or THE Optronics AMVA (M240UW01)
    U2412M Board = LG e - IPS (LM240WU8-SLA2)

    Compare the specifications in manuals:
    FTP://FTP.Dell.com/manuals/all-products/esuprt_electronics/esuprt_Display/Dell-12407wfp-hc_User%27s%20Guide_en-us.PDF

    FTP://FTP.Dell.com/manuals/all-products/esuprt_electronics/esuprt_Display/Dell-u2412m_User%27s%20Guide_en-us.PDF

    Read these comments (HC was not too different from the original):
    http://www.tftcentral.co.UK/reviews/dell_u2412m.htm

    http://www.tftcentral.co.UK/reviews/dell_2407wfp-HC.htm

  • How to compare the DOF of the OWNER. Table_name two DB in a single query?

    Hello community,

    I am trying to compare the DDL from a table that is located in two databases with the same name and the same pattern:

    select my_files.schema_name || '.' || my_files.table_name as table_name
         , case ( select dbms_lob.compare( dbms_metadata.get_ddl(one.object_type, one.object_name, one.owner)
                                         , dbms_metadata.get_ddl(two.object_type, two.object_name, two.owner)
                                         )
                    from all_objects  one
                       , all_objects@db_link  two
                   where one.object_type = 'TABLE'
                     and one.owner = my_files.schema_name
                     and one.object_name = my_files.table_name
                     and two.object_type = one.object_type
                     and two.owner = one.owner
                     and two.object_name = one.object_name
                )
             when 0 then 'Y'
             else 'N'
           end as ddl_equal_flag
      from my_files;
    

    When I run the query above in SQL Developer, I get results like:

    Table-name DDL_EQUAL_FLAG
    MY_SCHEMA. TABLE_1THERE
    MY_SCHEMA. TABLE_2THERE
    MY_SCHEMA. TABLE_3THERE
    etc.etc.

    But I wonder if it really works... I suspect DBMS_METADATA. GET_DDL returns the DDL of the database where I am connected, regardless of the database link, I used. Is this correct?

    And if so, is there another approach that gives me the expected results?

    Your help is very appreciated!

    Best regards, Yvo

    I would not use DBMS_METADATA, but the DBA_TAB_COLUMNS query directly.

  • How to compare the LDAP password

    Hello

    I am able to bind to the LDAP connection using the program java and able to search the DN of the user and get the userPassword attribute. I get encrypted password. My question is what is the encryption algorithm should I use to convert my password in plain text to compare with the password LDAP attribute?

    You do not compare the password entered with the LDAP password. You try to authenticate to the LDAP server as long as that user with the entered password. If you succeed, the password is correct. This is what is called an LDAP "bind" operation, not to be confused with the JNDI 'bind '. In JNDI, it's a reconnect().

Maybe you are looking for

  • Equium A60 - required OneNote product key

    Hi all I recently changed the HDD on my Equium A60, because the original was defective.I reinstalled the operating system and software, that it was delivered with the help of my DVD which is a copy kindly provided by Toshiba that I lost the original

  • Tecra M10 - will not do a 1080 p screen resolution

    I have a Tecra M10 (PTMB3A-0KH06C), running on Windows XP (standard version of Toshy) anchored in a port replicator. To this, I have a Samsung XL2370 the DVI port. I installed the Samsung drivers, and recognizes the lappy. However, when I put it in t

  • HP G72 laptop: HP G72 laptop does not start, error code of disk hard when you use HP Diagnostics

    I have a laptop G72 and it will start, but Windows 7 does not start. On using diagnostic tools in the start menu, my hard drive and my departure fail their tests, with both giving me this error code: UCUFWF-56C81D-XD003G-60WF03 No idea what this mean

  • Is there a way to change my id without losing my original files?

    I have some body some how send unsolicited offers me fing based on my e mail ID/account. I would like to Cahnege my e mail ID without losing my files than archieves onclude of old correspondence. It is poosible. If so how can it be done without wipin

  • Inspiron N0710 THAT there IS NO AUDIO OUTPUT INSTALLED

    Windows 7 Home Premium operating system, system worked very well, when I check my sound device manager is very good. When I check sound it tells me that no Audio output is installed? I've updated my Dell online here and the system check found no prob