Manage the SQLCODE in Plsql procedure

Hello

can you tell me how I can manage the sqlcode for each sql statement and continue the treatment?

For example, I read a table and write the data in another table.

If I get an error of key double pears (IE already entered folders) I would write a log table and read the next record.

The Exception Management stop the process and does not continue reading.


Thank you

-When you transform data between table1 and table2, duplicates will be captured in error_log table with the key that splits to, message error oracle error number, try to run the statements below and understand the process and let me know for any information.

@@@@@@@

create table table1 (tabl1_column number);  -primary table

create table table2 (tabl2_column unique number); -Secondary table

create table error_log (duplicate_key number, error_code varchar2 (100), error_message varchar2 (100)); -error log table

Insert into table1 values (1);

Insert into table1 values (1);

Insert into table1 values (2);

Insert into table1 values (3);

script:

====

create or replace procedure sp_sample

as

v_error_msg varchar2 (100): = null;

v_error_code varchar2 (100): = null;

Start

for rec loop (select tabl1_column from table1)

Start

insert into table2 (tabl2_column) values (rec.tabl1_column);

exception when others then

v_error_msg: = sqlerrm;

v_error_code: = sqlcode;

Insert in error_log (duplicate_key, error_code, error_message) values(rec.tabl1_column,v_error_code,v_error_msg);

commit;

end;

end loop;

end;

/

Execute the statement:

===============

Set serveroutput on;

exec sp_sample;

/

Check the result:

==============

Select * from table1;

Select * from table2;

Select * from error_log;

Tags: Database

Similar Questions

  • The display of an image defined in an external PLSQL procedure that renders the code HTML and called in a region of the APEX

    I have an external PLSQL procedure that dynamically creates a report out of the HTML tags that I then called an anonymous block APEX PLSQL.  I'm making bad images with the following code:
    in the external procedure.  How do you get around that? (NOTE: the procedure is too big to store directly in the APEX)

    ....

    ' < style td = "width: auto;" "padding: 0px 5px 0px ' > '. spc_rec. SPC_VIABILITY_STATUS. "< table > ' |

    "< style td =" width: auto; " text-align: left; "padding: 0px 5px 0px" > ' | spc_rec. SPC_VIABILITY_REASON. "< table > ' |

    TD > < img src = "" #IMAGE_PREFIX #check2.gif "alt =" "/ > < table > '"

    ....

    Thanks in advance

    PaulP

    Hi Paul,.

    You can use the global variable of the APEX package below to get the image prefix in pl/sql. Of course, your procedure should be in APEX, schema analysis application.

    APEX_APPLICATION. G_IMAGE_PREFIX

    Kind regards

    Hari

  • Business event does not trigger the PLSQL procedure... What should do?

    We need to call a plsql procedure when the workflow approval GL ended with approval. I thought I could do it by customizing the relevant business event.

    We are on EBS 12.1.3 with RDBMS: 11.2.0.3.0.

    I see the event oracle.apps.gl.Journals.journal.approve company has been disabled currently. I've enabled and created a subscription for her. Subscription was a PLSQL procedure. Currently, for objective test only thing it does is to insert a row in a table.

    Parameters of the subscription to corporate events:
    System: ORDEBS. SYSTEM.COM

    Triggering event
    Source type: Local
    Event filter: oracle.apps.gl.Journals.journal.approve


    Execution condition
    Phase: 100
    Status: enabled
    Rule data: Message

    Action type: custom
    Error on: stop blocking and cancellation

    Action
    Rule of PL/SQL function: XX_GL_APPROVE_BE_PKG. Get_Attributes
    Priority: normal

    Documentation (not sure what value to give the latter. I went with the values below).
    Owner: Name of the company
    Tag owner: custom Schema

    Using query I can see the event company is called when occurs below approval (an added line each time approval that has happened). But I don't see all the lines in the table where to insert a line. What could go wrong? How can I make sure that the procedure was called?

    Select * from WF_DEFERRED where corrid'art = 'APPS:oracle.apps.gl.Journals.journal.approve. '

    Procedure:
    CREATE OR REPLACE PACKAGE BODY APPS. XX_GL_APPROVE_BE_PKG
    AS
    PROCEDURE Get_Attributes
    IS
    BEGIN
    INSERT INTO xx.xx_test_table VALUES (' to BE');
    COMMIT;
    END Get_Attributes;
    END XX_GL_APPROVE_BE_PKG;

    Hello

    This OWNER_TAG represents an actual application under license, as "DNF" without the quotes. The business event system will send subscriptions for licensed products.

    Also, in order to detect any other possible errors please add a subscription of type error. In this way the BES will catch the error and will notify SYSADMIN of this failure, it's not silent. You can use this link to see how: https://blogs.oracle.com/oracleworkflow/entry/defining_business_events_with_synchronous

    Kind regards

    Alejandro

  • PLSQL procedure with the ORA-01858: a non-digit character was found where

    Hi friends,
    I'm pretty much back to the plsql programming. I am creating the plsql procedure that basically accepts the values of variables and controls difference of two columns if she's even if different it inserts values into the temporary table GTT_S_DOC_QUOTE, and then inserts data into another table in s_doc_quote please help me or correct my procedure.
    Since I'm getting below error ORA-01858: a non-digit character was found here where waiting a digital .my procedure is as below.
    CREATE OR REPLACE PROCEDURE QUOTE_STS)

    ROW_ID_IN GGATE_CT. GTT_S_DOC_QUOTE. ROW_ID % TYPE,
    STAT_CD_IN GGATE_CT. GTT_S_DOC_QUOTE. STAT_CD % TYPE,
    PREV_STS_CD_IN GGATE_CT. GTT_S_DOC_QUOTE. PREV_STS_CD % TYPE,
    BU_ID_IN GGATE_CT. GTT_S_DOC_QUOTE. BU_ID % TYPE,
    CREATED_IN GGATE_CT. GTT_S_DOC_QUOTE. CREATED % TYPE,
    X_CRRNT_TOT_AGRD_RMS_IN GGATE_CT. GTT_S_DOC_QUOTE. X_CRRNT_TOT_AGRD_RMS % TYPE,
    X_CRRNT_TOT_BLCKD_RMS_IN GGATE_CT. GTT_S_DOC_QUOTE. X_CRRNT_TOT_BLCKD_RMS % TYPE,
    X_CRRNT_TOT_PCKDUP_RMS_IN GGATE_CT. GTT_S_DOC_QUOTE. X_CRRNT_TOT_PCKDUP_RMS % TYPE,
    X_CRRNT_TOT_PCKDUP_AVGRT_IN GGATE_CT. GTT_S_DOC_QUOTE. X_CRRNT_TOT_PCKDUP_AVGRT % TYPE,
    X_CRRNT_TOT_BLCKD_AVGRT_IN GGATE_CT. GTT_S_DOC_QUOTE. X_CRRNT_TOT_BLCKD_AVGRT % TYPE,
    X_CRRNT_CNTRCT_SR_REVN_IN GGATE_CT. GTT_S_DOC_QUOTE. X_CRRNT_CNTRCT_SR_REVN % TYPE,
    X_CRRNT_CNTRCT_FD_REVN_IN GGATE_CT. GTT_S_DOC_QUOTE. X_CRRNT_CNTRCT_FD_REVN % TYPE,
    X_CRRNT_CNTRCT_BEV_REVN_IN GGATE_CT. GTT_S_DOC_QUOTE. X_CRRNT_CNTRCT_BEV_REVN % TYPE,
    X_CRRNT_CNTRCT_RM_REVN_IN GGATE_CT. GTT_S_DOC_QUOTE. X_CRRNT_CNTRCT_RM_REVN % TYPE,
    X_CRRNT_USD_EXCHNG_RT_IN GGATE_CT. GTT_S_DOC_QUOTE. X_CRRNT_USD_EXCHNG_RT % TYPE,
    X_CRRNT_CNTRCT_OTHR_REVN_IN GGATE_CT. GTT_S_DOC_QUOTE. X_CRRNT_CNTRCT_OTHR_REVN % TYPE,
    X_CRRNT_CNTRCT_RSRC_REVN_IN GGATE_CT. GTT_S_DOC_QUOTE. X_CRRNT_CNTRCT_RSRC_REVN % TYPE,
    LAST_UPD_IN GGATE_CT. GTT_S_DOC_QUOTE. LAST_UPD % TYPE)

    BEGIN

    IF (PREV_STS_CD == STAT_CD) then
    END if;
    INSERT INTO GTT_S_DOC_QUOTE)
    ROW_ID,
    STAT_CD,
    PREV_STS_CD,
    BU_ID,
    CREATED,
    X_CRRNT_TOT_AGRD_RMS,
    X_CRRNT_TOT_BLCKD_RMS,
    X_CRRNT_TOT_PCKDUP_RMS,
    X_CRRNT_TOT_PCKDUP_AVGRT,
    X_CRRNT_TOT_BLCKD_AVGRT,
    X_CRRNT_CNTRCT_SR_REVN,
    X_CRRNT_CNTRCT_FD_REVN,
    X_CRRNT_CNTRCT_BEV_REVN,
    X_CRRNT_CNTRCT_RM_REVN,
    X_CRRNT_USD_EXCHNG_RT,
    X_CRRNT_CNTRCT_OTHR_REVN,
    X_CRRNT_CNTRCT_RSRC_REVN,
    LAST_UPD
    )
    VALUES ('ROW_ID_IN',
    "STAT_CD_IN,"
    "PREV_STS_CD_IN,"
    "BU_ID_IN,"
    "CREATED_IN,"
    "X_CRRNT_TOT_AGRD_RMS_IN,"
    "X_CRRNT_TOT_BLCKD_RMS_IN,"
    "X_CRRNT_TOT_PCKDUP_RMS_IN,"
    "X_CRRNT_TOT_PCKDUP_AVGRT_IN,"
    "X_CRRNT_TOT_BLCKD_AVGRT_IN,"
    "X_CRRNT_CNTRCT_SR_REVN_IN,"
    "X_CRRNT_CNTRCT_FD_REVN_IN,"
    "X_CRRNT_CNTRCT_BEV_REVN_IN,"
    "X_CRRNT_CNTRCT_RM_REVN_IN,"
    "X_CRRNT_USD_EXCHNG_RT_IN,"
    "X_CRRNT_CNTRCT_OTHR_REVN_IN,"
    "X_CRRNT_CNTRCT_RSRC_REVN_IN,"
    'LAST_UPD '.
    );

    INSERT INTO S_DOC_QUOTE_CT
    (ROW_ID_OUT, STAT_CD_OUT, PREV_STS_CD_OUT, BU_ID_OUT, CREATED_OUT, X_CRRNT_TOT_AGRD_RMS_OUT, X_CRRNT_TOT_BLCKD_RMS_OUT, X_CRRNT_TOT_PCKDUP_RMS_OUT, X_CRRNT_TOT_PCKDUP_AVGRT_OUT,
    X_CRRNT_TOT_BLCKD_AVGRT_OUT, X_CRRNT_CNTRCT_SR_REVN_OUT, X_CRRNT_CNTRCT_FD_REVN_OUT, X_CRRNT_CNTRCT_BEV_REVN_OUT, X_CRRNT_CNTRCT_RM_REVN_OUT, X_CRRNT_USD_EXCHNG_RT_OUT, X_CRRNT_CNTRCT_OTHR_REVN_OUT,
    SELECT X_CRRNT_CNTRCT_RSRC_REVN_OUT ROW_ID), STAT_CD, PREV_STS_CD, BU_ID, CREATED, X_CRRNT_TOT_AGRD_RMS, X_CRRNT_TOT_BLCKD_RMS, X_CRRNT_TOT_PCKDUP_RMS, X_CRRNT_TOT_PCKDUP_AVGRT,.
    X_CRRNT_TOT_BLCKD_AVGRT, X_CRRNT_CNTRCT_SR_REVN, X_CRRNT_CNTRCT_FD_REVN, X_CRRNT_CNTRCT_BEV_REVN, X_CRRNT_CNTRCT_RM_REVN, X_CRRNT_USD_EXCHNG_RT, X_CRRNT_CNTRCT_OTHR_REVN,
    GGATE_CT X_CRRNT_CNTRCT_RSRC_REVN. GTT_S_DOC_QUOTE;

    COMMIT;
    end if;
    end QUOTE_STS;

    I was wondering why I get this error even if I stated the PREV_STS_CD

    What line do you think that you said PREV_STS_ID on? As far as I can see that the IF statement is the first mention of it in your code. My guess is that you mean PREV_STATS_ID_IN (goes the same for STAT_CD / STAT_CD_IN).

    If you write

    IF prev_sts_cd_in = stat_cd_in
    THEN
       NULL;
    END IF;
    
    do_something_here;
    

    then "do_something_here" will be processed regardless of the IF condition. I think what you probably wanted was something like

    IF prev_sts_cd_in = stat_cd_in
    THEN
       NULL;
    ELSE
       do_something_here;
    END IF;
    

    Is it possible for the prev_sts_cd and the stat_cd null? The test above would not handle this.

    Also, as others have mentioned, the first INSERT statement attempts to insert the strings like "ROW_ID_IN" you probably want to use the value of the ROW_ID_IN parameter, which is the reason why you get the error ORA-01858. I'm guessing here of course, but I took out the quotes.

    That would make your code something like this:

    CREATE OR REPLACE PROCEDURE quote_sts
        ( row_id_in                    ggate_ct.gtt_s_doc_quote.row_id%TYPE
        , stat_cd_in                   ggate_ct.gtt_s_doc_quote.stat_cd%TYPE
        , prev_sts_cd_in               ggate_ct.gtt_s_doc_quote.prev_sts_cd%TYPE
        , bu_id_in                     ggate_ct.gtt_s_doc_quote.bu_id%TYPE
        , created_in                   ggate_ct.gtt_s_doc_quote.created%TYPE
        , x_crrnt_tot_agrd_rms_in      ggate_ct.gtt_s_doc_quote.x_crrnt_tot_agrd_rms%TYPE
        , x_crrnt_tot_blckd_rms_in     ggate_ct.gtt_s_doc_quote.x_crrnt_tot_blckd_rms%TYPE
        , x_crrnt_tot_pckdup_rms_in    ggate_ct.gtt_s_doc_quote.x_crrnt_tot_pckdup_rms%TYPE
        , x_crrnt_tot_pckdup_avgrt_in  ggate_ct.gtt_s_doc_quote.x_crrnt_tot_pckdup_avgrt%TYPE
        , x_crrnt_tot_blckd_avgrt_in   ggate_ct.gtt_s_doc_quote.x_crrnt_tot_blckd_avgrt%TYPE
        , x_crrnt_cntrct_sr_revn_in    ggate_ct.gtt_s_doc_quote.x_crrnt_cntrct_sr_revn%TYPE
        , x_crrnt_cntrct_fd_revn_in    ggate_ct.gtt_s_doc_quote.x_crrnt_cntrct_fd_revn%TYPE
        , x_crrnt_cntrct_bev_revn_in   ggate_ct.gtt_s_doc_quote.x_crrnt_cntrct_bev_revn%TYPE
        , x_crrnt_cntrct_rm_revn_in    ggate_ct.gtt_s_doc_quote.x_crrnt_cntrct_rm_revn%TYPE
        , x_crrnt_usd_exchng_rt_in     ggate_ct.gtt_s_doc_quote.x_crrnt_usd_exchng_rt%TYPE
        , x_crrnt_cntrct_othr_revn_in  ggate_ct.gtt_s_doc_quote.x_crrnt_cntrct_othr_revn%TYPE
        , x_crrnt_cntrct_rsrc_revn_in  ggate_ct.gtt_s_doc_quote.x_crrnt_cntrct_rsrc_revn%TYPE
        , last_upd_in                  ggate_ct.gtt_s_doc_quote.last_upd%TYPE )
    IS
    BEGIN
        IF prev_sts_cd_in = stat_cd_in
        THEN
            NULL;
        ELSE
            INSERT INTO gtt_s_doc_quote
                 ( row_id
                 , stat_cd
                 , prev_sts_cd
                 , bu_id
                 , created
                 , x_crrnt_tot_agrd_rms
                 , x_crrnt_tot_blckd_rms
                 , x_crrnt_tot_pckdup_rms
                 , x_crrnt_tot_pckdup_avgrt
                 , x_crrnt_tot_blckd_avgrt
                 , x_crrnt_cntrct_sr_revn
                 , x_crrnt_cntrct_fd_revn
                 , x_crrnt_cntrct_bev_revn
                 , x_crrnt_cntrct_rm_revn
                 , x_crrnt_usd_exchng_rt
                 , x_crrnt_cntrct_othr_revn
                 , x_crrnt_cntrct_rsrc_revn
                 , last_upd )
            VALUES
                 ( row_id_in
                 , stat_cd_in
                 , prev_sts_cd_in
                 , bu_id_in
                 , created_in
                 , x_crrnt_tot_agrd_rms_in
                 , x_crrnt_tot_blckd_rms_in
                 , x_crrnt_tot_pckdup_rms_in
                 , x_crrnt_tot_pckdup_avgrt_in
                 , x_crrnt_tot_blckd_avgrt_in
                 , x_crrnt_cntrct_sr_revn_in
                 , x_crrnt_cntrct_fd_revn_in
                 , x_crrnt_cntrct_bev_revn_in
                 , x_crrnt_cntrct_rm_revn_in
                 , x_crrnt_usd_exchng_rt_in
                 , x_crrnt_cntrct_othr_revn_in
                 , x_crrnt_cntrct_rsrc_revn_in
                 , last_upd );
    
            INSERT INTO s_doc_quote_ct
                 ( row_id
                 , stat_cd
                 , prev_sts_cd
                 , bu_id
                 , created
                 , x_crrnt_tot_agrd_rms
                 , x_crrnt_tot_blckd_rms
                 , x_crrnt_tot_pckdup_rms
                 , x_crrnt_tot_pckdup_avgrt
                 , x_crrnt_tot_blckd_avgrt
                 , x_crrnt_cntrct_sr_revn
                 , x_crrnt_cntrct_fd_revn
                 , x_crrnt_cntrct_bev_revn
                 , x_crrnt_cntrct_rm_revn
                 , x_crrnt_usd_exchng_rt
                 , x_crrnt_cntrct_othr_revn
                 , x_crrnt_cntrct_rsrc_revn
                 , last_upd)
            SELECT row_id
                 , stat_cd
                 , prev_sts_cd
                 , bu_id
                 , created
                 , x_crrnt_tot_agrd_rms
                 , x_crrnt_tot_blckd_rms
                 , x_crrnt_tot_pckdup_rms
                 , x_crrnt_tot_pckdup_avgrt
                 , x_crrnt_tot_blckd_avgrt
                 , x_crrnt_cntrct_sr_revn
                 , x_crrnt_cntrct_fd_revn
                 , x_crrnt_cntrct_bev_revn
                 , x_crrnt_cntrct_rm_revn
                 , x_crrnt_usd_exchng_rt
                 , x_crrnt_cntrct_othr_revn
                 , x_crrnt_cntrct_rsrc_revn
                 , last_upd
            FROM   ggate_ct.gtt_s_doc_quote;
    
        END IF;
    END quote_sts;
    
  • Describe the Table inside the PLSQL procedure

    Dear all,
    I write a procedure which takes tablename as input and displays these columns in the table as output. How to describe a table within a plsql procedure. Also how to display columns, because each table will have a different number of columns. Please suggest.




    Thank you and best regards,
    Mahesh

    Hello
    You can have a procedure like this

    CREATE OR REPLACE PROCEDURE retrieve_tab_cols_prc(l_table_name VARCHAR2,l_owner_name varchar2) AS
    CURSOR TAB_COL_CURSOR IS
    select *
    from all_tab_cols
    where table_name = l_table_name
    and owner = l_owner_name
    ORDER BY column_id;
    BEGIN
    FOR CUR_REC IN TAB_COL_CURSOR
    LOOP
    dbms_output.put_line(CUR_REC.COLUMN_ID||' : '||CUR_REC.COLUMN_NAME);
    END LOOP;
    END retrieve_tab_cols_prc;
    
    Procedure created.
    
    SQL> begin
      2  RETRIEVE_TAB_COLS_PRC('EMP','SCOTT');
      3  end;
      4  /
    
    1 : EMPNO
    2 : ENAME
    3 : JOB
    4 : MGR
    5 : HIREDATE
    6 : SAL
    7 : COMM
    8 : DEPTNO
    
  • Are THE settings in the optional PLSQL procedures by default?

    I have a system well established using a central procedure here, and I want to add an OUT parameter, so I can get my hands on a reference number that it generates when it is running. It is... If I add the necessary OF THE parameters at the end of the argument list, each procedure that calls it, all of a sudden?


    () P_DO_THING
    one number,
    b NUMBER of OUTPUT,
    internal_ref OUT NUMBER - new!
    ) IS
    ...


    Bravo guys

    charred wrote:
    If I add the necessary OF THE parameters at the end of the argument list, each procedure that calls it, all of a sudden?

    Yes.

    What you can do is to overload the procedure. Use the same procedure with additional parameter name out and without output parameter.
    One without out parameter could call the old one with the output parameter and ignore everything that is returned.

    This will allow you to call the procedure and achieve a result without having to change all existing calls for this procedure.

    example not tested

    create or replace package test
    
      procedure P_DO_THING(a IN NUMBER, b OUT NUMBER);
    
      procedure P_DO_THING(a IN NUMBER, b OUT NUMBER, internal_ref OUT NUMBER);
    end test;
    /
    
    create or replace package body test
    
      procedure P_DO_THING(a IN NUMBER, b OUT NUMBER)
      IS
        v_dummy_ref number;
      BEGIN
         P_DO_THING(a IN NUMBER, b OUT NUMBER, v_dummy_ref);
      end;
    
      procedure P_DO_THING(a IN NUMBER, b OUT NUMBER, internal_ref OUT NUMBER)
      IS
      BEGIN
        do_something;
      END;
    
    end test;
    /
    

    You can now call test.p_do_thing with two or three parameters as you want.

    Published by: Sven w. on January 26, 2009 17:24

  • How do you manage exceptions / errors in stored procedures?

    How do you manage exceptions / errors in stored procedures?

    Exceptions/errors can be handled in different ways in the stored procedures.
    (1) could be using an EXCEPTION block in the procedure in which to use WHEN THEN.
    (2) may declare a variable in the DECLARE section as EXCEPTION type,
    raise it to the extent necessary using STIMULUS and manipulate in EXCEPTIONAL setting using the WHEN clause.
    (3) could use keywords SQLCODE & SQLERRM to display no errors and the error code...

  • PLSQL procedure error "component must be reported.

    Hello
    Greetings

    I need to write a PLSQL procedure to compare the data between two different requests (through the collection), but in the face of an error

    VERSION - Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bi

    EXAMPLE OF CODE-


    CREATE or REPLACE procedure V_test

    type v_record is (record
    CUSTOMER_TYPE varchar2 (10),
    PRODUCT_CATEGORY varchar2 (10),
    PRODUCT_DESC varchar2 (40));

    type v_tst1 is table of v_record INDEX OF pls_INTEGER;
    V_TEST1 v_tst1;

    type v_tst2 is table of v_record INDEX OF pls_INTEGER;
    V_TEST2 v_tst2;


    Start


    Select CUSTOMER_TYPE, b.PRODUCT_CATEGORY, c.PRODUCT_DESC
    BULK COLLECT INTO V_TEST1
    of a, b, c
    where a.PRODUCT_CATEGORYD = b.PRODUCT_CATEGORY and a.PRODUCT = c.PRODUC
    CUSTOMER_TYPE, PRODUCT_CATEGORY, PRODUCT_DESC group;



    Select CUSTOMER_TYPE, PRODUCT_CATEGORY, PRODUCT_DESC
    BULK COLLECT INTO VAS_TEST2
    d
    Group of CUSTOMER_TYPE, b.PRODUCT_CATEGORY, c.PRODUCT_DESC;



    BECAUSE me in V_TEST1. FIRST... V_TEST1. LAST
    LOOP
    FOR j IN V_TEST2. FIRST... V_TEST2. LAST
    loop


    If VAS_TEST1. CUSTOMER_TYPE (i) = VAS_TEST2. CUSTOMER_TYPE (j) then
    If VAS_TEST1. PRODUCT_CATEGORY (i) = VAS_TEST2. PRODUCT_CATEGORY (j) then


    insert into v_tab values (sysdate, V_TEST1. CUSTOMER_TYPE (i), V_TEST1. PRODUCT_CATEGORY (i), V_TEST1. PRODUCT_DESC (i));
    commit;

    end if;

    end if;



    END LOOP;



    END LOOP;
    END;
    /

    ERROR - "PLS-00302: component 'CUSTOMER_TYPE' must be declared '.

    Thank you in advance to suggest corrections or alternatives
  • Using the slider as a procedure parameter

    Hello

    I'm new in PL/SQL, but I need to build the procedure and trigger to check for a condition.
    I scoured the web, but I can't find something similar as my problem (maybe that I can not describe it well, or I'm doing something I shouldn't...)

    Well, I am designing a database that will manage the groups. A group can include another, so I need to check that there is no recursion.

    Let's say I have this table INC. where GID is my GroupID and INCLUDES the ID of the groups included in the first.
     GID   INCLUDES
    ---- ----------
      13         12
      13         14
      13         15
      16         11
      16         13
    I have also a subgroups procedure which lists all the groups included in that given:
    CREATE OR REPLACE PROCEDURE subgroups(cur OUT SYS_REFCURSOR, parent_id IN NUMBER)
    IS
    BEGIN
      OPEN cur FOR
        SELECT includes
        FROM inc
          START WITH gid= parent_id
          CONNECT BY PRIOR includes=gid ;
    END ;
    /
    This procedure will also be used in a PHP script, so I would keep independent.
    Now my problem is in this trigger:
    CREATE OR REPLACE TRIGGER t_inc_check_recurs
      BEFORE INSERT OR UPDATE ON inc
      FOR EACH ROW
    DECLARE
      cur SYS_REFCURSOR ;
      --i cur%ROWTYPE ;
      i inc%ROWTYPE;
    BEGIN
      subgroups(cur, :NEW.gid) ;
      LOOP
          FETCH cur INTO i ;
          EXIT WHEN cur%NOTFOUND;
          dbms_output.put_line('Test '||i.includes);
      END LOOP;
      CLOSE cur;
    END ;
    /
    In this case, it seems that I have trouble with the types used:
    SQL> insert into inc values(12,13) ;
    insert into inc values(12,13)
                *
    ERROR at line 1:
    ORA-06504: PL/SQL: Return types of Result Set variables or query do not match
    (1) is there anyone who could tell me how I should send the cursor as a parameter?
    It works fine:
    SQL> var cur refcursor ;
    SQL> exec subgroups(:cur, 13);
    SQL> print cur ;
    (2) do you know how can I declare 'i' in this genre: I heart % ROWTYPE?


    Thank you very much!

    >
    In this case, it seems that I have trouble with the types used:
    >
    No.-you have problems because you're trying to extract a value in a rowtype that requires TWO values

    Your procedure uses a cursor which is only expecting a SINGLE value

      OPEN cur FOR
        SELECT includes
        FROM inc
    

    But your trigger defines a rowtype for the entire line

      i inc%ROWTYPE;
    BEGIN
      subgroups(cur, :NEW.gid) ;
      LOOP
          FETCH cur INTO i ;
    

    And if you get this error
    >
    ORA-06504: PL/SQL: return variables of the game results or the query types do not match
    >
    Also - you can also declare and define a cursor in a package specification, and then use this cursor definition in the procedure and the trigger.

  • Why we need to create the package instead of procedure or function in Oracle

    Hello

    Recently, I attended an interview, they asked,
    why we must create the package instead of procedure or function in oracle. Is a specific advantage, if we create together.
    I'm not sure. can u tell me please someone.

    Thank you and best regards,
    Sanjeev.

    Hello

    A part of the oracle documentation.

    What is a PL/SQL Package?
    A package is a schema object which includes subroutines, variables, and logically related PL/SQL types. Packages have two parts: a specification (spec) and a body. Sometimes, the body is unnecessary. The specification is the interface to the package. It declares the types, variables, constants, exceptions, cursors, and subprograms that can be referenced from outside the package. The body defines queries for the sliders and the code for the subprogrammes.

    Benefits of the PL/SQL Packages
    Packages have a long history in software engineering, offering important characteristics for a reliable, maintainable, and reusable code, often in team for large systems development efforts.

    Modularity

    Packages allow you to logically encapsulate Associates types, elements, and subroutines in a module named PL/SQL. Each package is easy to understand, and the interfaces between packages are simple, clear and well defined. This facilitates the development of applications.

    Easier application design

    When you design an application, all you need initially is the interface information in the package specification. You can code and compile a spec without his body. Stored subprograms that reference the package can then be compiled as well. You should not set the package body entirely until you are ready to complete the application.

    Information masking

    With packages, you can specify which types, elements, and subprogrammes are (and accessible) public or private (hidden and inaccessible). For example, if a package contains four subprogrammes, three can be public and one private. The package hides the implementation of the subprogramme private so that only the package (not your application) is affected if the application changes. This simplifies maintenance and improvement. Also, by hiding the implementation details of the users, you protect the integrity of the packaging.

    Feature added

    Sliders and packed public variables persist for the lifetime of a session. They can be shared by all the subprogrammes that are running in the environment. They allow you to manage data in any of the transactions without storing in the database.

    Best performance

    When you call a subprogram packaged for the first time, the whole package is loaded into memory. Subsequent calls to related subprograms in package require no disk i/o.

    Packets stop cascading dependencies and avoid an unnecessary recompilation. For example, if you change the body of a packaged function, Oracle does not recompile other routines that call the function; These routines only depend on parameters and return value that are declared in the specification, so they are recompiled only if the specification changes.

  • How to manage the pause embedded inside the CSV column line

    Hello

    I'm under pressure to make it work. I've already put this question on the forum of the APEX, but on reflection, I think that it relates more to PL/SQL rather than APEX APEX 4.1 having already utility to manage the Upload of CSV.
    If you already read in the forum of the APEX, please ignore.
    I'm sorry for that. Thanks for reading.

    I need to develop an application that allows the user to upload a CSV file to a table of interface.
    The APEX version on my workplace is 4.0.2.
    I used the code of
    http://dbswh.webhop.NET/HTMLDB/f?p=blog:read:0:article:11000346061523
    It all works fine until recently I find
    If a column in a CSV file cotain a break line (or line spacing) for example (the tester copy and paste this text which has a line break on a column in a spreadsheet)

    It is the first sentence.
    It is the second sentence.

    It will break the 'it's the second sentence In a new column.

    The contents of the CSV read next to Notepad as below
    Date of assessment, Date, assessment provider, name of the assessor, Court, first name, middle name, last name, PRN person record, NHI number, assisted defendant Y/N number, is dependent on O/N, Notes, primary of ethnicity, "the ethnic origin other, please specify", gender, currently in treatment O/N, another Substance, Substance of concern 5 specified
    22/09/2012, Co name of the provider, Warren Edgley, Wellington, sale, 2545554, dgsdf,, 'is the first sentence.
    It's the second sentence. ', Japanese, woman, b.

    This is the CSV UTIL code, please help me how can I replace the line break to a space so that the download process is correct.
      CREATE OR REPLACE PACKAGE BODY "CSV_UTIL" 
    AS
         --strip the beginning and the end quotes, then replace double quotation with single 
       FUNCTION de_quote (p_str IN VARCHAR2, p_enc_by IN VARCHAR2)
          RETURN VARCHAR2
       IS
       v_str VARCHAR2(32767) := p_str;
       BEGIN
          IF (p_enc_by IS NULL)
          THEN
             RETURN p_str;
          ELSE
            
            IF SUBSTR(p_str,-1) = p_enc_by THEN
               v_str := SUBSTR(p_str,1,LENGTH(p_str)-1);
            END IF;
            IF SUBSTR(p_str,1,1) = p_enc_by THEN
               v_str := SUBSTR(v_str,2);
            END IF;  
            RETURN REPLACE (v_str,
                             p_enc_by || p_enc_by,
                             p_enc_by
                            );
          END IF;
       END de_quote;
    
       PROCEDURE parse (p_str IN VARCHAR2, p_enc_by IN VARCHAR2, p_sep IN VARCHAR2)
       IS
          l_n          NUMBER   DEFAULT 1;
          l_in_quote   BOOLEAN  DEFAULT FALSE;
          l_ch         NCHAR (1);
          l_len        NUMBER   DEFAULT NVL (LENGTH (p_str), 0);
       BEGIN
          IF (l_len = 0)
          THEN
             RETURN;
          END IF;
    
          g_words := g_empty;
          g_words (1) := NULL;
    
          FOR i IN 1 .. l_len
          LOOP
             l_ch := SUBSTR (p_str, i, 1);
    
             IF (l_ch = p_enc_by)
             THEN
                l_in_quote := NOT l_in_quote;
             END IF;
    
             IF (l_ch = p_sep AND NOT l_in_quote)
             THEN
                l_n := l_n + 1;
                g_words (l_n) := NULL;
             ELSE
                g_words (l_n) := g_words (l_n) || l_ch;
             END IF;
          END LOOP;
    
          g_words (l_n) := de_quote (g_words (l_n), CHR(10));
          g_words (l_n) := de_quote (g_words (l_n), CHR(13));
          FOR i IN 1 .. l_n
          LOOP
             g_words (i) := de_quote (g_words (i), p_enc_by);
          END LOOP;
       END parse;
    
    /*
    
    Author: Oleg Lihvoinen
    Company: DbSWH
    
    Changes:
    10.02.2011, There was a miscalculation of the file line last position in case it is the end of file
    
    */
    
    
       PROCEDURE upload (p_file_name VARCHAR2, p_collection_name VARCHAR2, p_enc_by IN VARCHAR2, p_sep_by IN VARCHAR2, p_rows NUMBER)
       IS
          v_blob_data    BLOB;
          v_clob_data    CLOB;
          v_clob_len     NUMBER;
          v_position     NUMBER;
          v_char         NCHAR (1);
          c_chunk_len    NUMBER           := 1;
          v_line         VARCHAR2 (32767) := NULL;
          v_data_array   vcarray;
          v_rows         NUMBER           := 0;
          n_seq          NUMBER           := 1;
          dest_offset    NUMBER           := 1;
          src_offset     NUMBER           := 1;
          amount         INTEGER          := DBMS_LOB.lobmaxsize;
          blob_csid      NUMBER           := DBMS_LOB.default_csid;
          lang_ctx       INTEGER          := DBMS_LOB.default_lang_ctx;
          warning        INTEGER;
          l_sep          VARCHAR2(100)    := CASE WHEN p_sep_by = '\t' THEN chr(9) ELSE p_sep_by END;
       BEGIN
          htmldb_collection.create_or_truncate_collection
                                          (p_collection_name      => p_collection_name);
    
          -- Read blob from wwv_flow_files
          SELECT blob_content
            INTO v_blob_data
            FROM wwv_flow_files
           WHERE NAME = p_file_name;
    
          v_position := 1;
          DBMS_LOB.createtemporary (lob_loc      => v_clob_data,
                                    CACHE        => TRUE,
                                    dur          => DBMS_LOB.SESSION
                                   );
          DBMS_LOB.converttoclob (v_clob_data,
                                  v_blob_data,
                                  amount,
                                  dest_offset,
                                  src_offset,
                                  blob_csid,
                                  lang_ctx,
                                  warning
                                 );
          v_clob_len := DBMS_LOB.getlength (v_clob_data);
          IF v_clob_len = 0 THEN
             RETURN;
          END IF;
          
          WHILE (v_position <= v_clob_len + 1)
          LOOP
             v_char := DBMS_LOB.SUBSTR (v_clob_data, c_chunk_len, v_position);
             v_line := v_line || v_char;
             v_position := v_position + c_chunk_len;
    
             -- When the whole line is retrieved and not end of file or end of file
             IF v_char = CHR (10) AND v_position < v_clob_len OR v_position = v_clob_len + 1
             THEN
               
                parse (p_str => v_line, p_enc_by => p_enc_by, p_sep => l_sep);
                v_data_array := g_words;
                FOR i IN 1..g_words.count LOOP
                
                   IF i <= 50 THEN
                   
                      v_data_array(i) := g_words(i);
                   ELSE
                      exit;
                   END IF;
                
                END LOOP;
                
                FOR i IN g_words.count + 1..50 LOOP
                   
                   v_data_array(i) := null;
    
                END LOOP;            
                v_rows := v_rows + 1;
                -- exit if uploaded specified number of rows
                IF p_rows IS NOT NULL AND v_rows > p_rows THEN
                   EXIT;
                END IF;
                -- Store data to collection
                n_seq :=
                   htmldb_collection.add_member
                                         (p_collection_name      => p_collection_name,
                                          p_c001                 => v_data_array
                                                                               (1),
                                          p_c002                 => v_data_array
                                                                               (2),
                                          p_c003                 => v_data_array
                                                                               (3),
                                          p_c004                 => v_data_array
                                                                               (4),
                                          p_c005                 => v_data_array
                                                                               (5),
                                          p_c006                 => v_data_array
                                                                               (6),
                                          p_c007                 => v_data_array
                                                                               (7),
                                          p_c008                 => v_data_array
                                                                               (8),
                                          p_c009                 => v_data_array
                                                                               (9),
                                          p_c010                 => v_data_array
                                                                               (10),
                                          p_c011                 => v_data_array
                                                                               (11),
                                          p_c012                 => v_data_array
                                                                               (12),
                                          p_c013                 => v_data_array
                                                                               (13),
                                          p_c014                 => v_data_array
                                                                               (14),
                                          p_c015                 => v_data_array
                                                                               (15),
                                          p_c016                 => v_data_array
                                                                               (16),
                                          p_c017                 => v_data_array
                                                                               (17),
                                          p_c018                 => v_data_array
                                                                               (18),
                                          p_c019                 => v_data_array
                                                                               (19),
                                          p_c020                 => v_data_array
                                                                               (20),
                                          p_c021                 => v_data_array
                                                                               (21),
                                          p_c022                 => v_data_array
                                                                               (22),
                                          p_c023                 => v_data_array
                                                                               (23),
                                          p_c024                 => v_data_array
                                                                               (24),
                                          p_c025                 => v_data_array
                                                                               (25),
                                          p_c026                 => v_data_array
                                                                               (26),
                                          p_c027                 => v_data_array
                                                                               (27),
                                          p_c028                 => v_data_array
                                                                               (28),
                                          p_c029                 => v_data_array
                                                                               (29),
                                          p_c030                 => v_data_array
                                                                               (30),
                                          p_c031                 => v_data_array
                                                                               (31),
                                          p_c032                 => v_data_array
                                                                               (32),
                                          p_c033                 => v_data_array
                                                                               (33),
                                          p_c034                 => v_data_array
                                                                               (34),
                                          p_c035                 => v_data_array
                                                                               (35),
                                          p_c036                 => v_data_array
                                                                               (36),
                                          p_c037                 => v_data_array
                                                                               (37),
                                          p_c038                 => v_data_array
                                                                               (38),
                                          p_c039                 => v_data_array
                                                                               (39),
                                          p_c040                 => v_data_array
                                                                               (40),
                                          p_c041                 => v_data_array
                                                                               (41),
                                          p_c042                 => v_data_array
                                                                               (42),
                                          p_c043                 => v_data_array
                                                                               (43),
                                          p_c044                 => v_data_array
                                                                               (44),
                                          p_c045                 => v_data_array
                                                                               (45),
                                          p_c046                 => v_data_array
                                                                               (46),
                                          p_c047                 => v_data_array
                                                                               (47),
                                          p_c048                 => v_data_array
                                                                               (48),
                                          p_c049                 => v_data_array
                                                                               (49),
                                          p_c050                 => v_data_array
                                                                               (50)                                                                           
                                         );
             
                -- Clear the line
                v_line := NULL;
             END IF;
          END LOOP;
       END;
    END;
    In my applications, I save these lines in a table rather than a collection of APEX because the number of columns can contain greater than 50.
    I want to know how can replace these newline within a column to a space.
    If anyone has any ideas, please let me know.

    Thank you very much in advance.
    Ann
  • How long the Messages keep history to Yosemite? I know for iDevices you can choose between 1 month or 1 year but I wonder about the way it manages the Mac...

    How long the Messages keep history to Yosemite? I know for iDevices you can choose between 1 month or 1 year but I wonder about the way it manages the Mac...

    Messages or e-mails?

  • Manually manage the?

    Can someone explain this "manually manage music and videos" checkbox how? It's under 'Options '.

    Rather than use the synchronize option to manage the music from iTunes to iOS device, you can click and drag the pieces of music and video. In the beginning, it is a little heavy, but if you want only a small amount of music on a device, it may be advantageous. However, changing the sync to manage manually will make it the entire library to remove from the iOS device, and even if you change to manually manage to synchronize.

  • In the dialog "Manage the list of search engine", the "Restore Defautls" button is grayed out!

    Hello

    I use Firefox 6.0.1 on Windows 7.

    I installed software player Free Desktop Clock 2.37 and then Firefox was hi-jacked, so I chose carefully the custom displays.

    Edit: Free Desktop Clock itself does not hi-jack Firefox. This is another program (forget the name) comes with Free Desktop Clock that made him, adding a toolbar, change the home page, change the default search engine, etc. In fact, these forced alterations can be changed easily, return as a reset of the "keyword.url" pref For example, "hi-jack" can be a description which is too strong.

    In any case, I managed to clean - toolbar requested, forced homepage, forced the default search engine, etc.

    But there is still a problem.

    In the dialog, to manage the search engine, listthat appears when you click the arrow to the left of the search bar and then click on manage search engines, the default button is disabled (grayed out).

    How can we reactivated this button?

    Thank you.

    Finally, I realize that the 'Restore Defaults' button is enabled only when the default search engine is removed. The purpose of this button is to add all the missing default search providers. She, as I misunderstood, does not serve to remove search providers added by the user.

    So, I was wrong to blame Free Desktop Clock, no matter how bad it is.

  • CLIQ: How to manage the files?

    Is there a way to manage the files of the phone? I want to be able to move the images from my camera to my memory card, etc.

    I need to download a file manager of the market?

    There is a little market.

    AndExplorer is good (and free).

Maybe you are looking for

  • The tables on Pages automatically become complete?

    I noticed that when I export my document Pages as PDF, tables of automatically becomes a PDF file (that's what I want). Is it an automatic thing in Pages or is it my version of Adobe software? -I want to make sure that when I send it to my clients, t

  • Update BIOS

    I've recently updated my BIOS on my laptop and it has changed some of the controls as I have to hold the Fn to set the volume and the brightness up and down. When I press the brightness button without holding the Fn, he acts as the arrows at the top

  • Cannot ping ip/dns no internet firefox/chrome/mail/teamviewer

    Hello I tried the following on a windows 2003 domain. XP pro customer. I can't connect to Internet through all Inc. chrome firefox IE 7 browsers and applications Inc. outlook (not Exchange) reset the IPstack Reset winsock Disabled the antivirus Ran m

  • Won't play Rhapsody channels

    Sansa E280R finally broken, then proceed to Fuze +. upgrade to latest firmware first thing. Connected rocket to the latest version of Rhapsody.  Authorized unit, transferred other titles and some channels. When I boot Fuze +, I have the ' expired sub

  • Transfer to warm CVP - keyword 'media' for the IP address of the Media Store?

    Greetings, There is a nice feature in the microapp normal CVP scripts where the ECC user.microapp.media_server as the 'media' string variable is defined, and inserted the expressions 'ip host media a.b.c.d' and "ip host media-backup l.m.n.o" on the c