Comparison of record in a cursor

I need to compare the documents between two tables in a slider so that I can insert data into another table if the data is NOT even:

CURSOR cur1 is select t1.*, t2.* from t1, t2 where t1.col1 = t2.col2
FOR rec1 IN LOOP c1_cursor
.....
IF
NVL (REC1. Col1,'* ') = NVL(rec1.col2,'*') AND
NVL(REC1.col3,'*') = NVL(rec1.col4,'*')
THEN NULL;
ON THE OTHER
INSERT INTO...
END IF;
END LOOP;

The records come side of left hand of the cursor right of table t2 and table t1. I have 1 million records to compare and 30 columns to compare, how to increase performance. Currently, it takes about 40 minutes for the cursor go through this comparison.
I have to use a cursor b/c, happened to treatment that must be done for the columns before be compared to IF stmt.

Thanks and greetings
Swayamprakash.Chiluveru

I think that this whole thing can be done without the help of any cursor or a loop.

You can see-->

[Insert conditional | http://www.psoug.org/reference/insert.html]

Kind regards.

LOULOU.

Tags: Database

Similar Questions

  • Hi Expert, please tell me that how can I recover a recording of a cursor based on a condition

    There is a slider. Where can be one or more folder shows.

    I need to choose Next.

    1. If it is displays multiple records that choose this record where a field is showing not null

    2. If only one record in slider that choose this one (donot penalty on this field shows null or not null)

    Please tell me what I have to do it in.

    Thank you

    You do it in your query SELECT itself. CURSOR is nothing more than a set of instructions to execute the SQL statement. So, unless you get all records you do not know how many records in the cursor.

    Your selection would be something like that.

    Select

    BeO

    Select

    count (*) over() num_rows

    Of

    where

    )

    where num_rows = 1

    (or)

    Num_Rows > 1 and is not null

    )

  • How to display in put it if no records found using cursors

    Hello

    I have 10 dept numbers like 100 101... 109, assume some deptno is not records, how can I show in put as "this deptno has documents please check.

    In the example below deptno 106 has not made, so how can I display in put it...

    DECLARE

    CURSOR c1 (dpno emp.deptno%TYPE)

    IS

    SELECT *.

    WCP

    WHERE deptno = 106;

    I have c1% ROWTYPE;

    dpno emp.deptno%TYPE;

    BEGIN

    OPEN c1 (dpno);

    LOOP

    FETCH c1 I-BEAM;

    OUTPUT WHEN c1% NOTFOUND;

    Dbms_output.put_line (c1% ROWCOUNT);

    end if;

    END LOOP;

    CLOSE c1;

    END;

    Thank you

    SQL > DECLARE
    2 CURSOR c1 (dpno emp.deptno%TYPE)
    3 EAST
    4. SELECT *.
    5 FROM emp
    6. WHERE deptno = 106;
    7 I have c1% ROWTYPE;
    8 dpno emp.deptno%TYPE.
    BEGIN 9
    10 c1 (dpno) OPEN;
    11 LOOP
    12 FETCH c1 I-BEAM;
    EXIT 13 WHEN c1% NOTFOUND;
    14 DBMS_OUTPUT.put_line (c1% ROWCOUNT);
    15 END LOOP;
    16
    If 17 nvl (c1% rowcount, 0) = 0 then
    18 dbms_output.put_line ("' no found rows");
    19 end if;
    20
    21 CLOSE c1;
    22 END;
    23.
    Not found line

    PL/SQL procedure successfully completed.

  • Insert all records from a custom to a staging table.

    Hello

    Is it possible to insert all records of a cursor in a custom table using plsql instead of open a cursor, and each record in a loop?

    Thank you

    KK

    Use INSERT INTO your_staging_tbl... SELECT... Of your_cuatom_tbl

  • SQL cursor problem

    Hi all

    I want to see the records in the table emp or a message if the emp table is empty, but under cursor shows the two,

    How can I solve this problem, please help.

    declare
    cursor emp_cur is
    Select * from emp;
    SheikYerbouti emp % rowtype;
    Start
    Open emp_cur;
    loop
    extract in SheikYerbouti emp_cur;
    If emp_cur % notfound then
    dbms_output.put_line ('there no record in the employee table');
    "exit";
    on the other
    dbms_output.put_line (emp_rec.empno |) » '|| emp_rec.ename);
    end if;
    end loop;
    close emp_cur;
    end;

    You should do something like this,

    not tested.

    DECLARE
       CURSOR emp_cur
       IS
          SELECT * FROM emp;
    
       emp_rec   emp%ROWTYPE;
       i         NUMBER := 0;
    BEGIN
    
       IF emp_cur%ISOPEN THEN
    
          CLOSE emp_cur;
    
       END IF;
    
       OPEN emp_cur;
    
       LOOP
    
          FETCH emp_cur INTO emp_rec;
    
          EXIT WHEN emp_cur%NOTFOUND;
    
          i     := i + 1;
    
          DBMS_OUTPUT.PUT_LINE (emp_rec.empno || ' ' || emp_rec.ename);
    
       END LOOP;
    
       IF i = 0 THEN
          DBMS_OUTPUT.PUT_LINE ('There is no record in employee table ');
       END IF;
    
       CLOSE emp_cur;
    
    END;
    

    Earlier you were printing that the records did not exist for when the extraction fails. Extraction fails at the end of the recording for any cursor. If you have found the two.
    Now, you print it out only if message I = 0, which means that the cursor did not return a single record.

    G.

  • update of records

    How many lines can I update in a slider...

    in my app with more than 20,000 records...

    Please suggest

    Published by: OraclePLSQL on February 23, 2011 13:02

    OraclePLSQL wrote:
    can the number of records I update in a slider...

    Your question makes me feel that you don't have good understanding of what the cursor is.

    You are unable to update records in a cursor.

    A slider is just a work in memory space Oracle allocates for each process SQL statement. A slider is not all the data stored in it. There only the instructions that must be performed to extract the data from n6cessoires. Data will be available in the data buffer.

    When you issue command oracle OPEN allocates a workspace in memory for the cursor. When you RETRIEVE oracle executes the instructions and gets the data from the data buffer. And finally when you issue ABOUT oracle command releases the workspace of memory.

  • Apply the function of a column of a Ref Cursor

    Hello

    I have a stored procedure that returns a refcursor. Is it possible to apply a function as for example SUBSTR LPAD and a custom on a column in the refcursor function returned? The problem is that I can't change the existing stored procedure and I was wondering if it would be possible to write somewhat a wrapper procedure (or an anonymous PL/SQL block) that would actually apply a scalar function and only then return the result to the client?

    Thanks and regards,
    Swear

    do you want after retrieve you records of Ref Cursor

    SQL> create or replace
      2  procedure rc_test (p_rc out sys_refcursor)
      3  is
      4    l_rc sys_refcursor;
      5  begin
      6     open l_rc for
      7     select dummy from dual;
      8     p_rc := l_rc;
      9  end;
     10  /
    
    Procedure created.
    
    SQL> declare
      2     r sys_refcursor;
      3     v varchar2(1);
      4  begin
      5     rc_test (r);
      6     fetch r into v;
      7     dbms_output.put_line (lower (v));
      8     close r;
      9  end;
     10  /
    x
    
    PL/SQL procedure successfully completed.
    
  • How to create a record of pl/sql in oracle

    Oracle Forms 6i

    Hai All

    My question how to create a record with a cursor for loop.

    While I'm generating my if statement elsif only some of my files are not completely recovered, so I generate using the cursor for loop pls tell how to do

    My code is

    declare
    t_in dail_att.intime%type;
    t_out dail_att.intime%type;
    t_code dail_att.barcode%type;
    dail_att.attend_date%type V_DATE;

    cursor cur_test is
    Select respondent, outtime, barcode, dail_att attend_date;
    -in t_in, t_out, t_code, dail_att V_DATE;

    Start

    go_block ('TEST_SRI');
    PREMIER_ENREGISTREMENT;
    LOOP

    If: bartime between 0145 and then 0630
    Update dail_att set = outtime: bartime where barcode =: bar code
    and ATTEND_DATE =: BARDATE-1 and intimate are zero and outtime is not null;


    elsif: bartime between 0630 and 0900 or: bartime between 1130 and 1230 or
    : bartime between 1700 and 1800 and t_in is null then

    insert into dail_att(barcode,intime,attend_date)
    values(:Barcode,:Bartime,:bardate);

    elsif: bartime > 1645 and t_in is not null and t_out is null then
    Update dail_att set = outtime: bartime where barcode =: bar code
    and ATTEND_DATE =: BARDATE and respondent are not null and outtime has the value null.
    on the other

    Update dail_att set = outtime: bartime where barcode =: bar code
    and ATTEND_DATE =: BARDATE and respondent are not null and outtime has the value null.

    end if;
    WHEN THE OUTPUT: SYSTEM. LAST_RECORD = "TRUE" OR: BAR CODE IS NULL;
    NEXT_RECORD;
    END LOOP;
    forms_ddl ('commit');
    exception
    while others then
    forms_ddl ('rollback');
    message(SQLERRM|| dbms_error_Text);
    message(SQLERRM|| dbms_error_Text);
    End;


    Pls tell me if I need to create a folder or other...

    Concerning

    Srikkanth.M

    You can run a loop throgh query records of Pentecost an implicit cursor (which automatically manages the open cursor, fetch and next record):

      for rec in (select intime,outtime,barcode,attend_date from dail_att; )
      loop
    
           t_in :=rec.intime;
           t_out :=rec.outtime;
           t_code :=rec.barcode;
           t_date := attend_date;
    
        /*
    
             PUT YOUR CODE HERE ... (if ..then... elsif... logic)
             you can avoid setting variables 'cause you can directly use the implicit cursor variables: rec.intime etc.
    
         */
    
      end loop;
    END;
    

    In any case, I suggest you check the where the condition of your block... because if not all data is collected it should be a problem in your application... well, even the cursor (if it is based on the same query) will return less data than expected.

    Luca

  • Invalid argument when you delete a record in doubles

    I use BerkeleyDB 4.7 on Gentoo 2.6.24 - r7.

    I have a database with keys duplicated which I access via a slider. When I try to delete one of the records duplicate the function c_del() returns the value 22 (EINVAL) which means a flag is not valid or the cursor is not initialized.

    According to the documentation, the indicator (the second argument) should be zero. So the problem must be with the cursor, but him still said that the slider is very well.

    I have distilled the problem of autonomous code below. You should be able to cut and paste into a file named deltest.c and compile it. The comments near the top shows how to compile and run it.

    The code may seem long, but it's really very simple. He wrote just three records with duplicate keys and reads them. He tries to remove the second disk.

    Help, please. I don't know what I'm missing.

    -Code starts here-

    #include < db.h >
    #include < stdio.h >
    #include < stdlib.h > to
    #include < string.h >

    #define FREE (V) if (V) {free (V); V = NULL ;}

    /*
    o deltest deltest.c-L /usr/local/BerkeleyDB.4.7 GCC - ldb
    mkdir deltest_env
    . / deltest
    RM deltest_env
    */
    main()
    {
    DB_ENV * envp;
    DB * dbp;
    DBC * cursor;
    DBT key;
    DBT data;
    DB_TXN * txn;

    int rc;

    /*-----------------------
    An open environment and the database; define indicators sorted duplicates
    */
    RC = db_env_create (& envp, 0);
    fprintf (stderr, "after the structure created environment: %d\n", rc);

    RC = envp-> open (envp, 'duptest_env', DB_CREATE |) DB_INIT_TXN | DB_INIT_LOCK | DB_INIT_LOG | DB_INIT_MPOOL, 0);
    fprintf (stderr, "after the opening of environment: %d\n", rc);

    RC = db_create (& dbp, envp, 0);
    fprintf (stderr, "after the created database structure: %d\n", rc);

    RC = dbp-> set_flags (dbp, DB_DUPSORT);
    fprintf (stderr, "after the series of flags: %d\n", rc);

    RC = dbp-> open (dbp, NULL, "deltest", NULL, DB_BTREE, DB_CREATE |) DB_AUTO_COMMIT, 0600);
    fprintf (stderr, "after the opening of database: %d\n", rc);

    /*-----------------------
    BEGIN transaction, write three records with the same key, commit
    */
    TXN = NULL;
    RC = envp-> txn_begin (envp, NULL, & txn, 0);
    fprintf (stderr, "after obtaining the transaction handle: %d\n", rc);

    Memset (& key, 0, sizeof (DBT));
    Memset (& data, 0, sizeof (DBT));

    Key.Data = strdup ("key");
    Key.Size = strlen (key.data);

    Data.Data = strdup ("some arbitrary data");
    Data.Size = strlen (data.data);

    RC = dbp-> put (dbp, txn, key, & data, DB_NODUPDATA);
    fprintf (stderr, "after the first written record: %d\n", rc);

    FREE (data.data)
    Memset (& data, 0, sizeof (DBT));
    Data.Data = strdup ("some other arbitrary data');
    Data.Size = strlen (data.data);

    RC = dbp-> put (dbp, txn, key, & data, DB_NODUPDATA);
    fprintf (stderr, "after the first record in double writes: %d\n", rc);

    FREE (data.data)
    Memset (& data, 0, sizeof (DBT));
    Data.Data = strdup ("Some data more arbitrary");
    Data.Size = strlen (data.data);

    RC = dbp-> put (dbp, txn, key, & data, DB_NODUPDATA);
    fprintf (stderr, "after the second written duplicate: %d\n", rc);

    RC = txn-> commit (txn, 0);
    fprintf (stderr, "after the transaction are committed: %d\n", rc);


    /*-----------------------
    Create a cursor and read back the three records.
    After reading the other, we try to remove it.
    Then we read for the fourth time just show that there is more no record.
    */
    RC = dbp-> cursor (dbp, NULL, & slider, 0);
    fprintf (stderr, "after the cursor created: %d\n", rc);

    FREE (key.data)
    FREE (data.data)
    Memset (& key, 0, sizeof (DBT));
    Key.Flags = DB_DBT_MALLOC;
    Memset (& data, 0, sizeof (DBT));
    Data.Flags = DB_DBT_MALLOC;

    RC =-> c_get cursor (cursor, & key and data, DB_NEXT);
    fprintf (stderr, "after the first EEG: %d - % s: %s\n", rc, key.data, data.data);

    FREE (data.data)
    FREE (key.data)
    Memset (& key, 0, sizeof (DBT));
    Key.Flags = DB_DBT_MALLOC;
    Memset (& data, 0, sizeof (DBT));
    Data.Flags = DB_DBT_MALLOC;

    RC =-> c_get cursor (cursor, & key and data, DB_NEXT);
    fprintf (stderr, "after the second get: %d - % s: %s\n", rc, key.data, data.data);

    / * Here, we try to delete the current record * /.
    RC = cursor-> c_del (cursor, 0);
    fprintf (stderr, "after delete: %d\n", rc);
    / * The return code is EINVAL (22), but I see nothing wrong with the arguments to the c_del() function * /.



    FREE (data.data)
    FREE (key.data)
    Memset (& key, 0, sizeof (DBT));
    Key.Flags = DB_DBT_MALLOC;
    Memset (& data, 0, sizeof (DBT));
    Data.Flags = DB_DBT_MALLOC;

    RC =-> c_get cursor (cursor, & key and data, DB_NEXT);
    fprintf (stderr, "after the third get: %d - % s: %s\n", rc, key.data, data.data);




    FREE (data.data)
    FREE (key.data)
    Memset (& key, 0, sizeof (DBT));
    Key.Flags = DB_DBT_MALLOC;
    Memset (& data, 0, sizeof (DBT));
    Data.Flags = DB_DBT_MALLOC;

    RC =-> c_get cursor (cursor, & key and data, DB_NEXT);
    fprintf (stderr, "after the fourth get: %d - % s: %s\n", rc, key.data, data.data);



    /*-------------------------------------------
    Close the cursor, data base and the environment
    */

    RC = cursor-> c_close (cursor);
    fprintf (stderr, "after the cursor close: %d\n", rc);

    RC = dbp-> close (dbp, 0);
    fprintf (stderr, "after the closing of the database: %d\n", rc);

    RC = envp-> close (envp, 0);
    fprintf (stderr, "after the closure of environment: %d\n", rc);

    Exit (0);
    }

    Published by: user8104091 on June 23, 2009 16:45

    Make a Berkeley DB error output? If this is not the case, try adding this call before opening the environment:

    envp->set_errfile(envp, stderr);
    

    Nevertheless, it seems that the problem is that you open the transactional database, then open the cursor without a transaction. Nontransactional cursors can read a transactional database (in isolation 'read committed'), but cannot perform updates. To update a transactional database, you must include a transaction.

    Here, you can open the cursor in a transaction that is configured with the DB_READ_COMMITTED flag to avoid read - lock the database entire when you scan through it.

    Kind regards
    Michael Cahill, Oracle Berkeley DB.

  • Hotmail no longer works. I can open mail on yahoo, MSN premium, IE9, chrome, but firefox doesn't work anymore? I reinstalled the two and point of restoration, still broken?

    When I open the Fire Fox, click Hotmail, it opens the page with the open.cannot of the Inbox folder, click on anything? Cannot open the mail, or all records thereon, the cursor turns into a finger, but nothing opens or closes in all? reinstalled evrything, made a restore point. It works on all browsers, but firefox? use fire fox for years?

    I found the problem. It's the ad block plus 2.0. I just noticed that I was disabling each of them was. I noticed in Firefox that the envelopes have disappeared! That's why the post did not open, so in safe mode with disabled modules returned envelopes. then I restarted in reg mode and then turned off one-by-one. It was the adBlock Plus 2.0. Thank you for your advice. I would have never found. Thank you!

  • Windows media player will not go back. How can I solve this problem?

    When I click back it does not.  I have to stop the player back to the beginning.

    Even if the ToolTip for the "Previous" said that holding down button will be re-wind, it doesn't seem to work.  Ironically, the fast forward function of the button 'Next' works.  To return to an earlier part of a recording, place the cursor on the edge of the progress bar ("Seek" should appear as a toll point) and click and drag the 'heel' (I don't know how it's called really, if anything.) back to the part you want to hear again.

  • Tabular with nvl (max (col), 0) + 1

    Hi all

    I have a table block, I want to generate sequence for the key item numbers primary with nvl (max (col), 0) + 1

    I wrote this in a w-n-r-i trigger:

    "LAST_RECORD;

    SELECT NVL (MAX (ALERT_ID), 0) + 1 ON: EX_ALERT_SETUP. ALERT_ID EX_ALERT_SETUP; "

    but when I enter a new record with the cursor, it also gets the '1', body I have not saved the first '1 ',.

    How to deal with this situation?

    Thank you

    ORA-01400 wrote:

    Hi all

    I have a table block, I want to generate sequence for the key item numbers primary with nvl (max (col), 0) + 1

    I wrote this in a w-n-r-i trigger:

    "LAST_RECORD;

    SELECT NVL (MAX (ALERT_ID), 0) + 1 ON: EX_ALERT_SETUP. ALERT_ID EX_ALERT_SETUP; "

    but when I enter a new record with the cursor, it also gets the '1', body I have not saved the first '1 ',.

    How to deal with this situation?

    Thank you

    If it's a bad design, simply change the trigger as before Insert at the block level. Sequences of database is suggested.

    Hope this helps

    Hamid

  • Exact divisions of 2000

    Hi guys,.

    I have some pl/SQL with a variable that moves through the records of a cursor and counts each record.  The cursor can go back and say 10000records (this can vary), but I want to do something specific each 2000th record.  Is there a way to check if my variable (which is incremented for each record in the slider) is a multiple of 2000 and cannot make my code.  For example, I want only my code to trigger the folder 2000,4000,6000,8000, 10000 etc.

    Thanks for any help I receive.


    Yes, you can use the mathematical function MOD to determine if you have reached a certain number of documents...

    for example, each 20 records...

    SQL > ed
    A written file afiedt.buf

    1 with t as (select rownum r of the double connection by rownum<=>
    2  --
    3 end of false documents
    4  --
    5. Select r
    6, case when mod (r 20) = 0 then 'Yes' null otherwise end as do_it
    7 * t
    SQL > /.

    R DO_
    ---------- ---
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20 Yes
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    Yes 40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    Yes 60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    Yes 80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    Yes 100

    100 selected lines.

    SQL >

    What do you plan to do each 2000 records?  If it's a "commit", then you are definitely something wrong.

  • Rows affected the dynamic SQL


    Hello

    VERSION - Oracle9i Enterprise Edition Release 9.2.0.6.0 - 64 bit Production

    I want the number of rows affected by SQL dynamic, as shown below in the code where insert statement will be repeated for each record in the CURSOR.

    for rec in c1
    loop


    ABC: =' insert into test
    Select a.*,' | recomm. OP_ID |', "' | recomm. OP_NAME | " 'of BL_testI' | recomm. OP_ID: ' where START_DATE > = trunc(sysdate-2) and START_DATE < trunc(sysdate-1)';

    insert into str_test values (abc);

    immediately run abc;

    commit;

    When exit c1% notfound;
    end loop;

    In a normal query I would do it spontaneously SQL COUNT but cannot use it here.

    Thnx in advance

    Just use SQL % ROWCOUNT. What is the problem with that?

    Here is an example.

    SQL > declare
    l_sql 2 varchar2 (4000);
    3. start
    4 l_sql: = ' insert into t select * from emp';
    5. immediately run l_sql;
    6 dbms_output.put_line(l_sql ||) ': Number of inserted rows = ' | to_char(SQL%RowCount));)
    7 end;
    8.

    insert into t select * from EMP: number of inserted rows = 11

    PL/SQL procedure successfully completed.

    SQL >

  • Button to block multi line

    Guys, I was wondering if someone could help me. I have a block record multi that shows about 10 lines on the screen of the user, I also added a button to this disc multi block so there are 10 buttons, each button next to the corresponding line. When I click the button, it processes the data of the current line and gives a result, however it doesn't seem to work like that. If I asked back and have 10 records displayed on the screen and then click on the button 5 down which must process the data for the 5th record down there actually processes the data for the first record where the cursor is currently located after the first request. Is there anyway that I can get the cursor to go into the folder that corresponds to the key? IE if I manually click a folder and then the buttons it treats all document the cursor, but I want it to automatically go to the record corresponding to the button when the button is pressed?

    Thanks for any help I receive.

    Set the navigable property to true for your button mouse.

    see you soon

Maybe you are looking for

  • Why my app store does not disappear after the update to 9.2.1?

    After that I updated my iPod touch 6th generation iOS 9.2.1 My App Store has disappeared. Can you tell me why the App Store could do something like that?

  • Can't stop the operating system

    When I try to stop that I get a series of boxes to come and say that the laptop trying to close programs to which I am invited to click 'End now' or 'Cancel '. Why didn't he just closes everything?It takes forever to close all the latter.

  • Taking keyboard Compaq Presario CQ62

    The CPU cooling fan just died on my laptop, but all open to access, I managed to damage the plug that connects the Ribbon from the keyboard, or rather seems to me broke a corner of the black plastic bar to lock the Ribbon connector. The connector is

  • I need to recover my email after being hacked

    ease help meMy email account was stolen by a hacker, one called. He was using my account to e-mail until today and I hope that I can provide you with the enough information that can recover my stolen email. If I'm missing any information, please cont

  • Foglight inconsistency for alarms

    Hi everyone, I've noticed difference in notification of alarm between page main monitor for a host (in this example host AD) and its menu of exploration that appear when you click on the Red number 1 and put the photo for example... How can it be tha