Error_log procedure

Hi Friends,
I am struggling while making a generic proedure for error log.
I have a table error_log with columns err_code, err_msg, proc_name, application_user,proc_params
I have some procedures. whenever my procedure throws exception it should log in my error_log table with entries in respected columns.
Thanks in advance
Regards

Hi,
I'd suggest looking at Logger by Tyler Muth: https://logger.samplecode.oracle.com/
Martin
http://www.talkapex.com

Similar Messages

  • How to use bulk in multiple cursors !!

    Hello All,
    I am having a following program that perfectly runs but its taking very huge time to complete it.
    Can any one suggest how i can improve the performace of this code ..
    thanks in advance - appreciate your help .
    Here's the program.
    ==============
    procedure Proc_Fmly_VehicleTA_Cnt is
    CURSOR c_cur_fmly IS SELECT FAMID, NUM_AUTO, NUM_TVAN, VEHQ, VEHQL FROM FMLY;
    CURSOR c_cur_eovb_auto IS SELECT FAMID, VEHICIB ,VEHICYB FROM EOVB WHERE VEHICYB = gv_eovb_vehicyb_automobiles ;
    CURSOR c_cur_eovb_trucks IS SELECT FAMID, VEHICIB ,VEHICYB FROM EOVB WHERE VEHICYB = gv_eovb_vehicyb_trucks ;
    v_total_automobiles number := 0 ;
    v_total_trucks number := 0 ;
    v_procedure errorlog.procedure_name%TYPE default 'Proc_Fmly_VehicleTA_Cnt';
    v_location errorlog.location%TYPE;
    BEGIN
    v_location := 4 ;
    -- global variables gv_eovb_vehicyb_automobiles = 100 gv_eovb_vehicyb_trucks = 110
    -- <<Computing the owned vehicles - automobiles >>
    -- INNER BLOCK
    BEGIN
    FOR i IN c_cur_fmly LOOP
    FOR j IN c_cur_eovb_auto LOOP
    IF ( i.FAMID = j.FAMID ) THEN
    v_total_automobiles := v_total_automobiles + chk_notnull_blank( j.vehicib);
    END IF;
    END LOOP ;
    UPDATE FMLY SET NUM_AUTO = v_total_automobiles WHERE famid = i.famid ;
    v_total_automobiles := 0;
    END LOOP;
    EXCEPTION
    WHEN OTHERS THEN
    raise_application_error(-20001,'An error was encountered - '||SQLCODE||' -ERROR- '||SQLERRM);
    v_err_code := SQLCODE;
    v_err_msg := substr(SQLERRM, 1, 200);
    INSERT INTO audit_table (error_number, error_message) VALUES (v_err_code, v_err_msg);
    error_logging(p_error_code => substr(sqlerrm,1,9), p_error_message => substr(sqlerrm,12), p_package => 'PKG_FCI_APP',p_procedure => 'Proc_Fmly_VehicleTA_Cnt' , p_location => v_location);
    END;
    -- <<Computing the owned vehicles - trucks >>
    -- INNER BLOCK
    BEGIN
    FOR i IN c_cur_fmly LOOP
    FOR j IN c_cur_eovb_trucks LOOP
    IF ( i.FAMID = j.FAMID ) THEN
    v_total_trucks := v_total_trucks + chk_notnull_blank( j.vehicib);
    END IF;
    END LOOP ;
    UPDATE FMLY SET NUM_TVAN = v_total_trucks WHERE famid = i.famid ;
    v_total_trucks := 0;
    END LOOP;
    EXCEPTION
    WHEN OTHERS THEN
    raise_application_error(-20001,'An error was encountered - '||SQLCODE||' -ERROR- '||SQLERRM);
    v_err_code := SQLCODE;
    v_err_msg := substr(SQLERRM, 1, 200);
    INSERT INTO audit_table (error_number, error_message) VALUES (v_err_code, v_err_msg);
    error_logging(p_error_code => substr(sqlerrm,1,9), p_error_message => substr(sqlerrm,12), p_package => 'PKG_FCI_APP',p_procedure => 'Proc_Fmly_Vehicle_Cnt' , p_location => v_location);
    END;
    -- END OUTER BLOCK
    EXCEPTION
    WHEN OTHERS THEN
    raise_application_error(-20001,'An error was encountered - '||SQLCODE||' -ERROR- '||SQLERRM);
    v_err_code := SQLCODE;
    v_err_msg := substr(SQLERRM, 1, 200);
    INSERT INTO audit_table (error_number, error_message) VALUES (v_err_code, v_err_msg);
    error_logging(p_error_code => substr(sqlerrm,1,9), p_error_message => substr(sqlerrm,12), p_package => 'PKG_FCI_APP',p_procedure => 'Proc_Fmly_VehicleTA_Cnt ', p_location => v_location);
    END Proc_Fmly_VehicleTA_Cnt;
    -- ignore error_logging procedure ; its a part of package.
    thanks/kumar
    Edited by: kumar73 on Sep 17, 2010 9:36 AM
    Edited by: kumar73 on Sep 17, 2010 9:37 AM

    btw your exception handler has a couple of problems (I've formatted it for you):
    EXCEPTION
       WHEN OTHERS THEN
          RAISE_APPLICATION_ERROR
          ( -20001, 'An error was encountered - '||SQLCODE||' -ERROR- '||SQLERRM );
          v_err_code := SQLCODE;
          v_err_msg  := SUBSTR(SQLERRM, 1, 200);
          INSERT INTO audit_table (error_number, error_message) VALUES (v_err_code, v_err_msg);
          error_logging
          ( p_error_code => substr(sqlerrm,1,9)
          , p_error_message => substr(sqlerrm,12)
          , p_package => 'PKG_FCI_APP'
          , p_procedure => 'Proc_Fmly_VehicleTA_Cnt'
          , p_location => v_location ); When RAISE_APPLICATION_ERROR raises the exception, the procedure will terminate and the error logging steps below it won't get called.
    Also if you just want to re-raise an exception without adding any information or your own message etc, then you should use RAISE, not RAISE_APPLICATION_ERROR. If you're going to use RAISE_APPLICATION_ERROR it should be something like:
    RAISE_APPLICATION_ERROR
    ( -20001
    , 'Could not set automobile count to ' || v_total_automobiles || ' for family ' || i.famid
    , TRUE );Notice the last parameter, TRUE, which tells it to keep the existing error stack (i.e. whatever Oracle error made it fail), which will then appear underneath your custom error message. You should never concatenate SQLERRM into a RAISE_APPLICATION_ERROR message. (And SQLCODE is just the error number that is already part of SQLERRM so there is no point including that anyway.)
    Those changes give you something like:
    EXCEPTION
       WHEN OTHERS THEN
          INSERT INTO audit_table (error_number, error_message)
          VALUES (SQLCODE, SUBSTR(SQLERRM,1,200));  -- btw why SUBSTR? Why not log the entire message?
          error_logging
          ( p_error_code => substr(sqlerrm,1,9)
          , p_error_message => substr(sqlerrm,12)
          , p_package => 'PKG_FCI_APP'
          , p_procedure => 'Proc_Fmly_VehicleTA_Cnt'
          , p_location => v_location );
          RAISE_APPLICATION_ERROR
          ( -20001
          , 'Could not set automobile count to ' || v_total_automobiles || ' for family ' || i.famid
          , TRUE );

  • How to write errors in sqlplus script into logging table?

    Hi,
    I am having sqlplus script which do some DDL and DML statements.
    Now is there any way to logg errors which pop up when the script is esxecuting?
    For example something like:
    WHENEVER SQLERROR EXIT SQL.SQLCODE
    BEGIN
    /* SOME DDL OR DDL */
    CREATE TABLE A
    COL_1 NUMBER,
    COL_2 NUMBER
    /* Wrong sql statement */
    INSERT INTO TABLE_DOWS_NOT_EXISTS(....);
    EXCEPTION WHEN OTHERS THEN
    INSERT INTO logging_tbl (error_description) VALUES(SQL.SQLCODE);
    END;
    I know, this one will tell sqlplus to exit with sql error code without trapping into exception section, but is there any way to handle it?
    Thanks

    An approach would be to enable spooling in the beginning of your script. Wrap dbms_output into an error_log procedure. The error_log should simple write an errorcode + message to the prompt.<br>Afterwards - a search batchjob or manual search for errorcode occurances in the script spool file(s) should reveal the outcome.

  • When i created procedure for error_log its giving errors:

    please give a solution for below procedure...
    just check the procedure its giving errors ... rec is not an identifier in loop in the procedure....
    Step 1:
    Create a table MAP_ERROR_LOG.
    Script:
    CREATE TABLE MAP_ERROR_LOG
    ERROR_SEQ NUMBER,
    MAPPING_NAME VARCHAR2(32 BYTE),
    TARGET_TABLE VARCHAR2(35 BYTE),
    TARGET_COLUMN VARCHAR2(35 BYTE),
    TARGET_VALUE VARCHAR2(100 BYTE),
    PRIMARY_TABLE VARCHAR2(100 BYTE),
    ERROR_ROWKEY NUMBER,
    ERROR_CODE VARCHAR2(12 BYTE),
    ERROR_MESSAGE VARCHAR2(2000 BYTE),
    ERROR_TIMESTAMP DATE
    TABLESPACE DW_OWNER_DATA
    PCTUSED 0
    PCTFREE 10
    INITRANS 1
    MAXTRANS 255
    STORAGE (
    INITIAL 80K
    MINEXTENTS 1
    MAXEXTENTS 2147483645
    PCTINCREASE 0
    BUFFER_POOL DEFAULT
    LOGGING
    NOCOMPRESS
    NOCACHE
    NOPARALLEL
    MONITORING;
    Step 2:
    Create a sequence MAP_ERROR_LOG_SEQ
    CREATE SEQUENCE MAP_ERROR_LOG_SEQ START WITH 1 INCREMENT BY 1
    Step 3:
    Create a procedure PROC_MAP_ERROR_LOG through OWB.
    In this i have used 3 cursor, first cursor is used to check the count of error messages for the corresponding table(WB_RT_ERROR_SOURCES).
    The second cursor is used to get the oracle error and the primary key values.
    The third cursor is used for get the ORACLE DBA errors such as "UNABLE TO EXTEND THE TABLESPACE" for this type errors.
    CREATE OR REPLACE PROCEDURE PROC_MAP_ERROR_LOG(MAP_ID VARCHAR2) IS
    --initialize variables here
    CURSOR C1 IS
    SELECT COUNT(RTA_IID) FROM OWB_REP.WB_RT_ERROR_SOURCES
    WHERE RTA_IID =( SELECT MAX(RTA_IID) FROM OWB_REP.WB_RT_AUDIT WHERE RTA_PRIMARY_TARGET ='"'||MAP_ID||'"');
    V_COUNT NUMBER;
    CURSOR C2 IS
    SELECT A.RTE_ROWKEY ERR_ROWKEY,SUBSTR(A.RTE_SQLERRM,1,INSTR(A.RTE_SQLERRM,':')-1) ERROR_CODE,
    SUBSTR(A.RTE_SQLERRM,INSTR(A.RTE_SQLERRM,':')+1) ERROR_MESSAGE,
    C.RTA_LOB_NAME MAPPING_NAME,SUBSTR(B.RTS_SOURCE_COLUMN,(INSTR(B.RTS_SOURCE_COLUMN,'.')+1)) TARGET_COLUMN,
    B.RTS_VALUE TARGET_VALUE,C.RTA_PRIMARY_SOURCE PRIMARY_SOURCE,C.RTA_PRIMARY_TARGET TARGET_TABLE,
    C.RTA_DATE ERROR_TIMESTAMP
    FROM OWB_REP.WB_RT_ERRORS A,OWB_REP.WB_RT_ERROR_SOURCES B, OWB_REP.WB_RT_AUDIT C
    WHERE C.RTA_IID = A.RTA_IID
    AND C.RTA_IID = B.RTA_IID
    AND A.RTA_IID = B.RTA_IID
    AND A.RTE_ROWKEY =B.RTE_ROWKEY
    --AND RTS_SEQ =1
    AND B.RTS_SEQ IN (SELECT POSITION FROM OWB_REP.ALL_CONS_COLUMNS A, OWB_REP.ALL_CONSTRAINTS B
    WHERE A.TABLE_NAME = B.TABLE_NAME
    AND A.CONSTRAINT_NAME = B.CONSTRAINT_NAME
    AND A.TABLE_NAME =MAP_ID
    AND CONSTRAINT_TYPE ='P')
    AND A.RTA_IID =(
    SELECT MAX(RTA_IID) FROM OWB_REP.WB_RT_AUDIT WHERE RTA_PRIMARY_TARGET ='"'||MAP_ID||'"');
    CURSOR C3 IS
    SELECT A.RTE_ROWKEY ERR_ROWKEY,SUBSTR(A.RTE_SQLERRM,1,INSTR(A.RTE_SQLERRM,':')-1) ERROR_CODE,
    SUBSTR(A.RTE_SQLERRM,INSTR(A.RTE_SQLERRM,':')+1) ERROR_MESSAGE,
    C.RTA_LOB_NAME MAPPING_NAME,SUBSTR(B.RTS_SOURCE_COLUMN,(INSTR(B.RTS_SOURCE_COLUMN,'.')+1)) TARGET_COLUMN,
    B.RTS_VALUE TARGET_VALUE,C.RTA_PRIMARY_SOURCE PRIMARY_SOURCE,C.RTA_PRIMARY_TARGET TARGET_TABLE,
    C.RTA_DATE ERROR_TIMESTAMP
    FROM OWB_REP.WB_RT_ERRORS A,OWB_REP.WB_RT_ERROR_SOURCES B, OWB_REP.WB_RT_AUDIT C
    WHERE C.RTA_IID = A.RTA_IID
    AND A.RTA_IID = B.RTA_IID
    AND A.RTE_ROWKEY =B.RTE_ROWKEY
    AND A.RTA_IID =(
    SELECT MAX(RTA_IID) FROM OWB_REP.WB_RT_AUDIT WHERE RTA_PRIMARY_TARGET ='"'||MAP_ID||'"');
    -- main body
    BEGIN
    DELETE DW_OWNER.MAP_ERROR_LOG WHERE TARGET_TABLE ='"'||MAP_ID||'"';
    COMMIT;
    OPEN C1;
    FETCH C1 INTO V_COUNT;
    IF V_COUNT >0 THEN
    FOR REC IN C2
    LOOP
    INSERT INTO DW_OWNER.MAP_ERROR_LOG
    (Error_seq ,
    Mapping_name,
    Target_table,
    Target_column ,
    Target_value ,
    Primary_table ,
    Error_rowkey ,
    Error_code ,
    Error_message ,
    Error_timestamp)
    VALUES(
    DW_OWNER.MAP_ERROR_LOG_SEQ.NEXTVAL,
    REC.MAPPING_NAME,
    REC.TARGET_TABLE,
    REC.TARGET_COLUMN,
    REC.TARGET_VALUE,
    REC.PRIMARY_SOURCE,
    REC.ERR_ROWKEY,
    REC.ERROR_CODE,
    REC.ERROR_MESSAGE,
    REC.ERROR_TIMESTAMP);
    END LOOP;
    ELSE
    FOR REC IN C3
    LOOP
    INSERT INTO DW_OWNER.MAP_ERROR_LOG
    (Error_seq ,
    Mapping_name,
    Target_table,
    Target_column ,
    Target_value ,
    Primary_table ,
    Error_rowkey ,
    Error_code ,
    Error_message ,
    Error_timestamp)
    VALUES(
    DW_OWNER.MAP_ERROR_LOG_SEQ.NEXTVAL,
    REC.MAPPING_NAME,
    REC.TARGET_TABLE,
    REC.TARGET_COLUMN,
    REC.TARGET_VALUE,
    REC.PRIMARY_SOURCE,
    REC.ERR_ROWKEY,
    REC.ERROR_CODE,
    REC.ERROR_MESSAGE,
    REC.ERROR_TIMESTAMP);
    END LOOP;
    END IF;
    CLOSE C1;
    COMMIT;
    -- NULL; -- allow compilation
    EXCEPTION
    WHEN OTHERS THEN
    NULL; -- enter any exception code here
    END;

    Yah i got the solution...
    scrip is
    Step 1:
    Create a table MAP_ERROR_LOG.
    Script:
    CREATE TABLE MAP_ERROR_LOG
    ERROR_SEQ NUMBER,
    MAPPING_NAME VARCHAR2(32 BYTE),
    TARGET_TABLE VARCHAR2(35 BYTE),
    TARGET_COLUMN VARCHAR2(35 BYTE),
    TARGET_VALUE VARCHAR2(100 BYTE),
    PRIMARY_TABLE VARCHAR2(100 BYTE),
    ERROR_ROWKEY NUMBER,
    ERROR_CODE VARCHAR2(12 BYTE),
    ERROR_MESSAGE VARCHAR2(2000 BYTE),
    ERROR_TIMESTAMP DATE
    TABLESPACE DW_OWNER_DATA
    PCTUSED 0
    PCTFREE 10
    INITRANS 1
    MAXTRANS 255
    STORAGE (
    INITIAL 80K
    MINEXTENTS 1
    MAXEXTENTS 2147483645
    PCTINCREASE 0
    BUFFER_POOL DEFAULT
    LOGGING
    NOCOMPRESS
    NOCACHE
    NOPARALLEL
    MONITORING;
    Step 2:
    Create a sequence MAP_ERROR_LOG_SEQ
    CREATE SEQUENCE MAP_ERROR_LOG_SEQ START WITH 1 INCREMENT BY 1
    Step 3:
    Create a procedure PROC_MAP_ERROR_LOG through OWB.
    In this i have used 3 cursor, first cursor is used to check the count of error messages for the corresponding table(WB_RT_ERROR_SOURCES).
    The second cursor is used to get the oracle error and the primary key values.
    The third cursor is used for get the ORACLE DBA errors such as "UNABLE TO EXTEND THE TABLESPACE" for this type errors.
    CREATE OR REPLACE PROCEDURE PROC_MAP_ERROR_LOG(MAP_ID VARCHAR2) IS
    --initialize variables here
    CURSOR C1 IS
    SELECT COUNT(RTA_IID) FROM OWB_REP.WB_RT_ERROR_SOURCES1
    WHERE RTA_IID =( SELECT MAX(RTA_IID) FROM OWB_REP.WB_RT_AUDIT1 WHERE RTA_PRIMARY_TARGET ='"'||MAP_ID||'"');
    V_COUNT NUMBER;
    CURSOR C2 IS
    SELECT A.RTE_ROWKEY ERR_ROWKEY,SUBSTR(A.RTE_SQLERRM,1,INSTR(A.RTE_SQLERRM,':')-1) ERROR_CODE,
    SUBSTR(A.RTE_SQLERRM,INSTR(A.RTE_SQLERRM,':')+1) ERROR_MESSAGE,
    C.RTA_LOB_NAME MAPPING_NAME,SUBSTR(B.RTS_SOURCE_COLUMN,(INSTR(B.RTS_SOURCE_COLUMN,'.')+1)) TARGET_COLUMN,
    B.RTS_VALUE TARGET_VALUE,C.RTA_PRIMARY_SOURCE PRIMARY_SOURCE,C.RTA_PRIMARY_TARGET TARGET_TABLE,
    C.RTA_DATE ERROR_TIMESTAMP
    FROM OWB_REP.WB_RT_ERRORS1 A,OWB_REP.WB_RT_ERROR_SOURCES1 B, OWB_REP.WB_RT_AUDIT1 C
    WHERE C.RTA_IID = A.RTA_IID
    AND C.RTA_IID = B.RTA_IID
    AND A.RTA_IID = B.RTA_IID
    AND A.RTE_ROWKEY =B.RTE_ROWKEY
    --AND RTS_SEQ =1
    AND B.RTS_SEQ IN (SELECT POSITION FROM ALL_CONS_COLUMNS A, ALL_CONSTRAINTS B
    WHERE A.TABLE_NAME = B.TABLE_NAME
    AND A.CONSTRAINT_NAME = B.CONSTRAINT_NAME
    AND A.TABLE_NAME =MAP_ID
    AND CONSTRAINT_TYPE ='P')
    AND A.RTA_IID =(
    SELECT MAX(RTA_IID) FROM OWB_REP.WB_RT_AUDIT1 WHERE RTA_PRIMARY_TARGET ='"'||MAP_ID||'"');
    CURSOR C3 IS
    SELECT A.RTE_ROWKEY ERR_ROWKEY,SUBSTR(A.RTE_SQLERRM,1,INSTR(A.RTE_SQLERRM,':')-1) ERROR_CODE,
    SUBSTR(A.RTE_SQLERRM,INSTR(A.RTE_SQLERRM,':')+1) ERROR_MESSAGE,
    C.RTA_LOB_NAME MAPPING_NAME,SUBSTR(B.RTS_SOURCE_COLUMN,(INSTR(B.RTS_SOURCE_COLUMN,'.')+1)) TARGET_COLUMN,
    B.RTS_VALUE TARGET_VALUE,C.RTA_PRIMARY_SOURCE PRIMARY_SOURCE,C.RTA_PRIMARY_TARGET TARGET_TABLE,
    C.RTA_DATE ERROR_TIMESTAMP
    FROM OWB_REP.WB_RT_ERRORS A,OWB_REP.WB_RT_ERROR_SOURCES1 B, OWB_REP.WB_RT_AUDIT C
    WHERE C.RTA_IID = A.RTA_IID
    AND A.RTA_IID = B.RTA_IID
    AND A.RTE_ROWKEY =B.RTE_ROWKEY
    AND A.RTA_IID =(
    SELECT MAX(RTA_IID) FROM OWB_REP.WB_RT_AUDIT WHERE RTA_PRIMARY_TARGET ='"'||MAP_ID||'"');
    -- main body
    BEGIN
    DELETE DW_OWNER.MAP_ERROR_LOG WHERE TARGET_TABLE ='"'||MAP_ID||'"';
    COMMIT;
    OPEN C1;
    FETCH C1 INTO V_COUNT;
    IF V_COUNT >0 THEN
    FOR REC IN C2
    LOOP
    INSERT INTO DW_OWNER.MAP_ERROR_LOG
    (Error_seq ,
    Mapping_name,
    Target_table,
    Target_column ,
    Target_value ,
    Primary_table ,
    Error_rowkey ,
    Error_code ,
    Error_message ,
    Error_timestamp)
    VALUES(
    DW_OWNER.MAP_ERROR_LOG_SEQ.NEXTVAL,
    REC.MAPPING_NAME,
    REC.TARGET_TABLE,
    REC.TARGET_COLUMN,
    REC.TARGET_VALUE,
    REC.PRIMARY_SOURCE,
    REC.ERR_ROWKEY,
    REC.ERROR_CODE,
    REC.ERROR_MESSAGE,
    REC.ERROR_TIMESTAMP);
    END LOOP;
    ELSE
    FOR REC IN C3
    LOOP
    INSERT INTO DW_OWNER.MAP_ERROR_LOG
    (Error_seq ,
    Mapping_name,
    Target_table,
    Target_column ,
    Target_value ,
    Primary_table ,
    Error_rowkey ,
    Error_code ,
    Error_message ,
    Error_timestamp)
    VALUES(
    DW_OWNER.MAP_ERROR_LOG_SEQ.NEXTVAL,
    REC.MAPPING_NAME,
    REC.TARGET_TABLE,
    REC.TARGET_COLUMN,
    REC.TARGET_VALUE,
    REC.PRIMARY_SOURCE,
    REC.ERR_ROWKEY,
    REC.ERROR_CODE,
    REC.ERROR_MESSAGE,
    REC.ERROR_TIMESTAMP);
    END LOOP;
    END IF;
    CLOSE C1;
    COMMIT;
    -- NULL; -- allow compilation
    EXCEPTION
    WHEN OTHERS THEN
    NULL; -- enter any exception code here
    END;

  • Calling Procedure on Validation

    Hi
    I want to call a procedure that will insert some data like error_log in validation itself.(ie)
    I want to save the error messages in a database table can anyone help?If possible which type should be specified?

    Hi,
    I just test this again. My apex version is 3.2
    I did create new application and one blank page to it.
    Then I did create text item P1_NUMBER and submit button.
    And validation
    DECLARE
      n NUMBER;
    BEGIN
    n := :P1_NUMBER;
    RETURN NULL;
    EXCEPTION WHEN OTHERS THEN
      RETURN sqlerrm;
    END;And I get SQLERRM to notification and it do not navigate to error page.
    Could you test same ?
    Br,Jari
    Edited by: jarola on Jan 21, 2010 2:54 PM
    Are you sure that error not raised inside validation exception ?
    Check that code inside exception handler is ok

  • Using a dynamic table variable in a stored procedure

    SQL Server can do this where you declare a table variable and insert / modify / delete rows in that table without it ever being actually ON the database.
    Can Oracle do this?
    I know I can do things like pass in a unique user id, create the table in the procedure with the user ID appended, etc ...
    but this procedure is going to be accessed via two modes, a batch job as well as online. The batch job may run this procedure 500 times.
    What I'm trying to is figure out a way to return a recordset of errors that occured in the job, simple, 3 lines like so:
    LineNumber NUMBER,
    Severity VARCHAR(10),
    Error_Msg VARCHAR(200)
    is there any 3 dimensional way of storing these records when the errors occur, then returning them as a select statement at the end of the procedure?
    Thanks,

    Why not create a table
    CREATE TABLE error_log (
      job_id  NUMBER,
      line_number NUMBER,
      severity VARCHAR2(10),
      error_msg VARCHAR2(200)
    CREATE SEQUENCE seq_error_log_job_id
      START WITH 1
      INCREMENT BY 1
      CACHE 100;In your procedure, you would get a new job_id from the sequence, insert whatever records you want in the error log table using that job_id and then return a REF CURSOR where you select from the error_log table using the job_id.
    Justin
    Distributed Database Consulting, Inc.
    http://www.ddbcinc.com/askDDBC

  • Pass DB Link in procedure as parameter.

    Hi,
    I am using ORACLE Database 11g .
    I have a procedure in which i am already passing some parameters. The procedure contains few statements in which it has to refer to specific user for getting the data. So we use DB Link. As which user to connect is not sure so the DB LINK is also not constant. That is why i want to pass the DB link as a parameter to procedure. But if i don't give the db link name in procedure the procedure will not compile.
    A sample of my code is as follows :-
    create or replace procedure P_GET_TABLES(V_DBLINK in varchar2)
    as
    FOR I in (select s.TABLE_NAME
                    from user_tables@V_DBLINK s, dba_tables d          --- Obviously it gives me error that table does not exists.Due to variable V_DBLINK
                   where d.table_name = s.TABLE_NAME
                     and s.TABLE_NAME != 'ERROR_LOG'
                     and d.owner = V_SOURCE_SCHEMA_NAME
                  union (select s.TABLE_NAME
                          from user_tables@V_DBLINK s
                        minus
                        select TABLE_NAME
                          from dba_tables d
                         where owner = V_SOURCE_SCHEMA_NAME)) Loop
    -- other code for the process.....
    END LOOP;
    END;
    /Is their any method that i can pass a compiled procedure DB LINK as parameter or at run-time. ??
    Thanks in advance.

    VIRU wrote:
    Its a request can you just do the same thing with the FOR LOOP given by me in the first post. It will look something like this:
    create or replace procedure P_GET_TABLES
        (V_DBLINK in varchar2
          , V_SOURCE_SCHEMA_NAME  in varchar2)
    as
        rc sys_refcursor;
        l_table_name all_tables.table_name%type;
    begin
        open rc for 'select s.table_name
                    from user_tables@'||V_DBLINK||' s, dba_tables d
                   where d.table_name = s.table_name
                     and s.table_name != ''ERROR_LOG''
                     and d.owner = :1
                  union (select s.table_name
                          from user_tables@'||V_DBLINK||' s
                        minus
                        select table_name
                          from dba_tables d
                         where owner = :1)'
        using V_SOURCE_SCHEMA_NAME, V_SOURCE_SCHEMA_NAME;
       loop
            fetch rc into l_table_name;
            exit when rc%notfound;
            --  do your processing here....
       end loop;
       close rc;
    end P_GET_TABLES;
    /The Oracle online documentation covers dynamic SQL quite comprehensively. [url http://docs.oracle.com/cd/B19306_01/appdev.102/b14261/dynamic.htm#i14500]Find out more.
    I think you have some confusion with the data dictionary views you're using, USER_TABLES@remote_db will look for tables in a schema with the same name as the current user in the local database. The current user in the local database has the privileges to read the DBA_ level views in te local data dictionary but apparently isn't the account owning the tables in the remote database.
    Is that right? It sounds like a mess. I have to [url https://forums.oracle.com/forums/thread.jspa?messageID=10062119#10062119]agree with Billy that you might be trying to solve the wrong problem. Perhaps you need better configuration/release management processes?
    Cheers, APC
    Edited by: APC on Jan 2, 2012 9:52 AM

  • Union select as cursor in procedure

    Hi!
    With ref. to an earlier post from Sept. 11, 2009, I am facing the following problem:
    In my procedure I have this statement as a cursor:
    SELECT a.carrier_code, a.flight_no, a.from_city, a.origin, a.dept_time, a.to_city, a.destination, a.arr_time, a.flight_date,
    a.aircraft_type, a.booking_class, a.service_class, a.num_of_seats, a.checked_bag, a.fare_basis, a.fare_type, a.currency, a.rt_net_fare, a.tax, a.surcharges, a.fare_total
    FROM favailability a, main_related_flight b
    WHERE a.flight_leg_id = b.flight_leg_id_1
    AND a.from_city = 'London'
    AND a.service_class = 'Business'
    AND a.fare_type = 'Business Saver'
    AND a.flight_date = '27.09.09'
    UNION
    SELECT d.carrier_code, d.flight_no, d.from_city, d.origin, d.dept_time, d.to_city, d.destination, d.arr_time, d.flight_date,
    d.aircraft_type, d.booking_class, d.service_class, d.num_of_seats, d.checked_bag, d.fare_basis, d.fare_type, d.currency, d.rt_net_fare, d.tax, d.surcharges, d.fare_total
    FROM favailability d, main_related_flight e
    WHERE d.flight_leg_id = e.flight_leg_id_2
    AND d.from_city = 'Zurich'
    AND d.service_class = 'Business'
    AND d.fare_type = 'Business Flex'
    AND d.flight_date = '03.10.09'
    ORDER BY flight_date;
    ARRIER_CODE FLIGHT_NO              FROM_CITY                                                              ORIGIN DEPT_TIME TO_CITY                                                                DESTINATION ARR_TIME FLIGHT_DATE               AIRCRAFT_TYPE                            BOOKING_CLASS SERVICE_CLASS                  NUM_OF_SEATS           CHECKED_BAG          FARE_BASIS FARE_TYPE                      CURRENCY RT_NET_FARE            TAX                    SURCHARGES             FARE_TOTAL            
    LX           345                    London                                                                 LHR    06:00     Zurich                                                                 ZRH         08:40    27.09.09                  Airbus A320                              J             Business                       64                     30 kg                LXJ        Business Saver                 EUR      337                    30,01                  35,24                  402,25                
    LX           450                    Zurich                                                                 ZRH    07:00     London                                                                 LCY         07:35    03.10.09                  AVRO RJ100                               Z             Business                       37                     30 kg                LXZ        Business Flex                  EUR      740                    30,01                  21,24                  791,25                
    2 rows selectedworks fine when running the statement alone. However, when running the procedure, my exception appears:
    ORA-20022: Fare not found for flight from London to Zurich on 27-Sep-2009
    Please note that the fare type can be different for inbound and outbound flights.
    PROCEDURE  FLIGHT (p_ptc_adult IN NUMBER,
                      p_ptc_adult_rt       IN NUMBER,
                      p_ptc_adult_add      IN NUMBER,
                      p_ptc_adult_add_rt   IN NUMBER,
                      p_city_o             IN favailability.from_city%TYPE,
                      p_city_d             IN favailability.to_city%TYPE,
                      p_service_class      IN favailability.service_class%TYPE,
                      p_fare_type          IN favailability.fare_type%TYPE,
                      p_fare_type_rt       IN favailability.fare_type%TYPE,
                      p_flightdate         IN favailability.flight_date%TYPE,
                      p_flightdate_rt      IN favailability.flight_date%TYPE,
                      p_username           IN users.username%TYPE,
                      p_password           IN users.password%TYPE,
                      p_card_type          IN users_cc.card_type%TYPE,
                      p_creditcardnumber   IN VARCHAR2,
                      p_expiry_date        IN DATE,
                      p_first_name_add     IN VARCHAR2,
                      p_last_name_add      IN VARCHAR2) IS
    CURSOR c1 IS
    SELECT a.carrier_code, a.flight_no, a.from_city, a.origin, a.dept_time, a.to_city, a.destination, a.arr_time, a.flight_date,
    a.aircraft_type, a.booking_class, a.service_class, a.num_of_seats, a.checked_bag, a.fare_basis, a.fare_type, a.currency, a.rt_net_fare, a.tax, a.surcharges, a.fare_total
    FROM favailability a, main_related_flight b
    WHERE a.flight_leg_id = b.flight_leg_id_1
    AND a.from_city = p_city_o
    AND a.service_class = p_service_class
    AND a.fare_type = p_fare_type
    AND a.flight_date = p_flightdate
    UNION
    SELECT d.carrier_code, d.flight_no, d.from_city, d.origin, d.dept_time, d.to_city, d.destination, d.arr_time, d.flight_date,
    d.aircraft_type, d.booking_class, d.service_class, d.num_of_seats, d.checked_bag, d.fare_basis, d.fare_type, d.currency, d.rt_net_fare, d.tax, d.surcharges, d.fare_total
    FROM favailability d, main_related_flight e
    WHERE d.flight_leg_id = e.flight_leg_id_2
    AND d.from_city = p_city_d
    AND d.service_class = p_service_class
    AND d.fare_type = p_fare_type_rt
    AND d.flight_date = p_flightdate_rt
    ORDER BY flight_date;
    f_rec                 c1%ROWTYPE;
    v_num_of_seats        favailability.num_of_seats%TYPE;
    v_fare_type           favailability.fare_type%TYPE;
    v_fare_type_rt        favailability.fare_type%TYPE;
    v_net_fare            favailability.rt_net_fare%TYPE;
    v_currency            fl_itinerary_t.currency_t%TYPE;
    v_rid                 fl_itinerary_t.rid%TYPE;
    v_status              fl_itinerary_t.status%TYPE;
    v_ptc_adult           NUMBER;
    v_ptc_adult_rt        NUMBER;
    v_ptc_adult_add       NUMBER;
    v_ptc_adult_add_rt    NUMBER;
    e_no_passenger        EXCEPTION;
    e_no_available_fares  EXCEPTION;
    e_no_user             EXCEPTION;
    e_credit_card_expired EXCEPTION;
    v_error_code          error_log.err_code%TYPE;
    v_error_message       error_log.err_message%TYPE;
    v_error_date          error_log.err_date%TYPE;
    v_user_name           users.username%TYPE;
    v_password            users.password%TYPE;
    v_user_id             users.user_id%TYPE;
    v_first_name          users.first_name%TYPE;
    v_last_name           users.last_name%TYPE;
    v_dob                 users.dob%TYPE;
    v_country_code        users.country_code%TYPE;
    v_prefix              users.prefix%TYPE;
    v_mobile_phone        users.mobile_phone%TYPE;
    v_card_type           users_cc.card_type%TYPE;
    v_creditcardnumber    users_cc.card_number%TYPE;
    v_expiry_date         DATE;
    v_grand_total         NUMBER(10,2);
    v_first_name_add      VARCHAR2(40);
    v_last_name_add       VARCHAR2(40);
    v_booking_code        VARCHAR2(6);
    v_result              VARCHAR2(32);
    BEGIN
    v_ptc_adult        := p_ptc_adult;
    v_ptc_adult_rt     := p_ptc_adult_rt;
    v_ptc_adult_add    := p_ptc_adult_add;
    v_ptc_adult_add_rt := p_ptc_adult_add_rt;
    -- Check user input
        IF p_city_o = p_city_d THEN
         dbms_output.put_line ('Departure city cannot be arrival city!');
        ELSIF p_flightdate = p_flightdate_rt THEN
         dbms_output.put_line ('Departure date cannot be arrival date!');
        ELSIF p_flightdate > p_flightdate_rt THEN
         dbms_output.put_line ('Departure date cannot be after arrival date!');
        ELSIF p_flightdate < sysdate OR p_flightdate_rt < sysdate THEN
         dbms_output.put_line ('Departure and arrival date cannot be in the past!');
        ELSE
        IF nvl(trunc(p_ptc_adult), 0) = 0
        OR nvl(trunc(p_ptc_adult_rt), 0) = 0
        THEN
            RAISE e_no_passenger;
        END IF;
    -- Check outbound availability
        SELECT num_of_seats INTO v_num_of_seats
        FROM favailability
        WHERE v_ptc_adult = p_ptc_adult
        AND v_ptc_adult_add = p_ptc_adult_add
        AND from_city = p_city_o
        AND to_city = p_city_d
        AND service_class = p_service_class
        AND fare_type = p_fare_type
        AND fare_type = p_fare_type_rt
        AND flight_date = p_flightdate;
        IF p_ptc_adult > v_num_of_seats
         OR v_num_of_seats < 2 THEN
          dbms_output.put_line ('No seats available!');
        ELSE
         UPDATE favailability SET num_of_seats = num_of_seats - p_ptc_adult
         WHERE v_ptc_adult = p_ptc_adult
         AND from_city = p_city_o
         AND to_city = p_city_d
         AND service_class = p_service_class
         AND fare_type = p_fare_type
         AND fare_type = p_fare_type_rt
         AND flight_date = p_flightdate;
        END IF;
        IF p_ptc_adult_add > v_num_of_seats
         OR v_num_of_seats < 2 THEN
          dbms_output.put_line ('No seats available!');
        ELSE
         UPDATE favailability SET num_of_seats = num_of_seats - p_ptc_adult_add
         WHERE v_ptc_adult_add = p_ptc_adult_add
         AND from_city = p_city_o
         AND to_city = p_city_d
         AND service_class = p_service_class
         AND fare_type = p_fare_type
         AND fare_type = p_fare_type_rt
         AND flight_date = p_flightdate;
        END IF;
    -- Check inbound availability
        SELECT num_of_seats INTO v_num_of_seats
        FROM favailability
        WHERE v_ptc_adult_rt = p_ptc_adult_rt
        AND v_ptc_adult_add_rt = p_ptc_adult_add_rt
        AND from_city = p_city_d
        AND to_city = p_city_o
        AND service_class = p_service_class
        AND fare_type = p_fare_type_rt
        AND fare_type = p_fare_type
        AND flight_date = p_flightdate_rt;
        IF p_ptc_adult_rt > v_num_of_seats
         OR v_num_of_seats < 2 THEN
         dbms_output.put_line ('No seats available!');
        ELSE
         UPDATE favailability SET num_of_seats = num_of_seats - p_ptc_adult_rt
         WHERE v_ptc_adult_rt = p_ptc_adult_rt
         AND from_city = p_city_d
         AND to_city = p_city_o
         AND service_class = p_service_class
         AND fare_type = p_fare_type_rt
         AND fare_type = p_fare_type
         AND flight_date = p_flightdate_rt;
        END IF;
        IF p_ptc_adult_add_rt > v_num_of_seats
         OR v_num_of_seats < 2 THEN
         dbms_output.put_line ('No seats available!');
        ELSE
         UPDATE favailability SET num_of_seats = num_of_seats - p_ptc_adult_add_rt
         WHERE v_ptc_adult_add_rt = p_ptc_adult_add_rt
         AND from_city = p_city_d
         AND to_city = p_city_o
         AND service_class = p_service_class
         AND fare_type = p_fare_type_rt
         AND fare_type = p_fare_type
         AND flight_date = p_flightdate_rt;
        END IF;
      -- get credit info
        SELECT u.user_id, u.first_name, u.last_name, u.dob, u.country_code, u.prefix, u.mobile_phone, p_card_type, p_creditcardnumber, p_expiry_date
           INTO   v_user_id, v_first_name, v_last_name, v_dob, v_country_code, v_prefix, v_mobile_phone, v_card_type, v_creditcardnumber, v_expiry_date
           FROM   dual, users u, users_cc c
           WHERE  u.user_id = c.user_id
           AND u.username = p_username
           AND u.password = p_password
           AND c.card_type = p_card_type
           AND c.card_number = p_creditcardnumber
           AND c.expiry_date = p_expiry_date;
           IF SQL%ROWCOUNT = 0 THEN
                              RAISE e_no_user;
           END IF;
           IF p_expiry_date < sysdate THEN
                  RAISE e_credit_card_expired;
           END IF;
        v_result := booking_pkg.validatecreditcard(p_creditcardnumber);
    -- open cursor
    OPEN c1;
    LOOP
        FETCH c1 INTO f_rec;
        EXIT WHEN c1%notfound;
    -- insert records    
         INSERT INTO fl_itinerary_t (rid, carrier_t, fno_t, from_city_t, origin_t, dept_t, to_city_t, destination_t, arr_t, fdate_t, aircraft_type_t, booking_class_t, service_class_t,
                                     num_of_seats_t, checked_bag_t, fare_basis_t, fare_type_t, currency_t, fare_t, tax_t, surcharges_t, fare_total_t, grand_total_t, trans_date,
                                     status, user_id, first_name, last_name, dob, country_code, prefix, mobile_phone)
         VALUES (new_res_seq.nextval, f_rec.carrier_code, f_rec.flight_no, f_rec.from_city, f_rec.origin, f_rec.dept_time, f_rec.to_city, f_rec.destination, f_rec.arr_time, f_rec.flight_date, f_rec.aircraft_type, f_rec.booking_class,
                 f_rec.service_class, p_ptc_adult + p_ptc_adult_add, f_rec.checked_bag, f_rec.fare_basis, f_rec.fare_type, f_rec.currency, f_rec.rt_net_fare, f_rec.tax, f_rec.surcharges, f_rec.fare_total, f_rec.fare_total * (p_ptc_adult + p_ptc_adult_add), sysdate,
                 'Confirmed', v_user_id, v_first_name, v_last_name, v_dob, v_country_code, v_prefix, v_mobile_phone);
      -- additional traveller
         SELECT p_first_name_add, p_last_name_add
         INTO v_first_name_add, v_last_name_add
         FROM dual;
         IF v_ptc_adult_add = p_ptc_adult_add
         AND v_ptc_adult_add_rt = p_ptc_adult_add_rt
         AND v_first_name_add = p_first_name_add
         AND v_last_name_add = p_last_name_add
         THEN
           INSERT INTO fl_itinerary_add (trans_id, carrier, fno, from_city, to_city, fdate, first_name_2, last_name_2, dob_2, main_user_id, trans_date, status)
           VALUES (new_trans_seq.nextval, f_rec.carrier_code, f_rec.flight_no, f_rec.from_city, f_rec.to_city, f_rec.flight_date, v_first_name_add, v_last_name_add, null, v_user_id, sysdate, 'Confirmed');
         END IF;
      COMMIT;  
    END LOOP;
    CLOSE c1;
         -- show itinerary for main traveller
           dbms_output.put_line ('Itinerary completed!');
           dbms_output.put_line (v_ptc_adult || ' seat(s) reserved for ' || v_first_name ||', ' || v_last_name);
           dbms_output.put_line (v_ptc_adult_rt || ' seat(s) reserved for ' || v_first_name ||', ' || v_last_name);
         -- show itinerary for 2.traveller
           dbms_output.put_line (v_ptc_adult_add || ' seat(s) reserved for ' || v_first_name_add ||', ' || v_last_name_add);
           dbms_output.put_line (v_ptc_adult_add_rt || ' seat(s) reserved for ' || v_first_name_add ||', ' || v_last_name_add); 
    END IF;
           -- Create new booking
           INSERT INTO booking (booking_id,
                                rid,
                                e_ticket_no,
                                booking_code,
                                user_id,
                                first_name,
                                last_name,
                                dob,
                                credit_card_type,
                                credit_card_number,
                                currency, 
                                booking_date,
                                status)
           VALUES (new_booking_seq.nextval,
                   new_res_seq.currval,
                   dbms_random.value(1000000000000, 9999999999999),
                   dbms_random.string('X', 6), 
                   v_user_id,
                   v_first_name,
                   v_last_name,
                   v_dob,
                   v_card_type,
                   'xxxx-xxxx-xxxx-'||substr(v_creditcardnumber,-4),
                   f_rec.currency,
                   SYSDATE, 'Confirmed');
            SELECT booking_code
            INTO v_booking_code
            FROM booking;
             dbms_output.put_line ('Booking code: ' || v_booking_code);
    EXCEPTION
        WHEN e_no_available_fares THEN
          RAISE_APPLICATION_ERROR (-20021, 'There are no fares available for flight'||
                                           ' from '|| p_city_o||' to '|| p_city_d||' on '||TO_CHAR(p_flightdate, 'dd-Mon-yyyy'));
        WHEN no_data_found THEN
          RAISE_APPLICATION_ERROR (-20022, 'Fare not found for flight from '|| p_city_o||
                                           ' to '|| p_city_d||' on '||TO_CHAR(p_flightdate, 'dd-Mon-yyyy'));
        WHEN too_many_rows THEN
          RAISE_APPLICATION_ERROR (-20023, 'More than one fare found for flight from '||
                                            p_city_o||' to '|| p_city_d||' on '||
                                            TO_CHAR(p_flightdate, 'dd-Mon-yyyy'));
        WHEN e_no_passenger THEN
          RAISE_APPLICATION_ERROR(-20001, 'Please enter a valid number of travelers!');
        WHEN e_no_user THEN
          RAISE_APPLICATION_ERROR(-20002, 'User not found!');
        WHEN e_credit_card_expired THEN
          RAISE_APPLICATION_ERROR(-20003, 'Credit card has expired!');
        --WHEN OTHERS THEN
        --  v_error_code := SQLCODE;
        --  v_error_message := SUBSTR(SQLERRM, 1, 200);
         -- INSERT INTO error_log (err_code, err_message, err_date) VALUES
          --  (v_error_code, v_error_message, sysdate);
    END FLIGHT;Furthermore, only 1 booking can be inserted into the booking table.

    Hi!
    Thanks for the tip! Now inserting into the booking table works! Sorry for bothering again. In my package I have this function that should check the
    credit card number. Works alone, but not within the package (procedure). Please see above procedure too.
    FUNCTION VALIDATECREDITCARD (p_creditcardnumber IN VARCHAR2)
       RETURN VARCHAR2
    IS
       creditcardnumber    VARCHAR2 (32);
                --:= nosymbols (p_CreditCardNumber, LENGTH (p_CreditCardNumber));
       creditcardlength    NUMBER         := LENGTH (p_creditcardnumber);
       subtotal            NUMBER         := 0;
       t_value             NUMBER         := 0;
       c1                  NUMBER;
       c2                  NUMBER;
       c3                  NUMBER;
       c4                  NUMBER;
       cardtype            VARCHAR2 (160) := 'CARD';
       calculationmethod   VARCHAR2 (160) := 'UNKNOWN';
       RESULT              VARCHAR2 (160);
       v_expiry_date       DATE;
    BEGIN
       creditcardnumber := LTRIM(RTRIM(p_creditcardnumber));
       creditcardnumber := REPLACE(creditcardnumber, '-');
       creditcardnumber := REPLACE(creditcardnumber, '.');
    -- IF isnumber (CreditCardNumber) = 0 THEN
       c1 := TO_NUMBER (SUBSTR (creditcardnumber, 1, 1));
       c2 := TO_NUMBER (SUBSTR (creditcardnumber, 1, 2));
       c3 := TO_NUMBER (SUBSTR (creditcardnumber, 1, 3));
       c4 := TO_NUMBER (SUBSTR (creditcardnumber, 1, 4));
       IF creditcardlength = 13
       THEN
          IF c1 IN (4)
          THEN
             cardtype := 'VISA';
             calculationmethod := 'MOD10';
          END IF;
       ELSIF creditcardlength = 14
       THEN
          IF c2 IN (36, 38)
          THEN
             cardtype := 'DINERS CLUB';
             calculationmethod := 'MOD10';
          ELSIF c3 IN (300, 301, 302, 303, 304, 305)
          THEN
             cardtype := 'DINERS CLUB';
             calculationmethod := 'MOD10';
          END IF;
       ELSIF creditcardlength = 15
       THEN
          IF c2 IN (34, 37)
          THEN
             cardtype := 'AMEX';
             calculationmethod := 'MOD10';
          ELSIF c4 IN (2014, 2149)
          THEN
             cardtype := 'enROUTE';
             calculationmethod := 'ANY';
          ELSIF c4 IN (2131, 1800)
          THEN
             cardtype := 'JBC';
             calculationmethod := 'MOD10';
          END IF;
       ELSIF creditcardlength = 16
       THEN
          IF c1 IN (4)
          THEN
             cardtype := 'VISA';
             calculationmethod := 'MOD10';
          ELSIF c1 IN (3)
          THEN
             cardtype := 'JBC';
             calculationmethod := 'MOD10';
          ELSIF c2 IN (51, 52, 53, 54, 55)
          THEN
             cardtype := 'MASTERCARD';
             calculationmethod := 'MOD10';
          ELSIF c4 IN (6011)
          THEN
             cardtype := 'DISCOVER';
             calculationmethod := 'MOD10';
          END IF;
       END IF;
       IF calculationmethod = 'MOD10'
       THEN
          FOR i IN REVERSE 1 .. LENGTH (creditcardnumber)
          LOOP
                 IF cardtype = 'AMEX'
             THEN
                IF (TO_NUMBER (SUBSTR (TO_CHAR (i), LENGTH (i), 1)) NOT IN  (1, 3, 5, 7, 9))
                THEN
                   t_value := SUBSTR (creditcardnumber, i, 1) * 2;
                   subtotal := subtotal + SUBSTR (t_value, 1, 1);
                   subtotal := subtotal + NVL (SUBSTR (t_value, 2, 1), 0);
                ELSE
                   subtotal := subtotal + SUBSTR (creditcardnumber, i, 1);
                END IF;                       
             ELSE          
                IF (TO_NUMBER (SUBSTR (TO_CHAR (i), LENGTH (i), 1)) IN  (1, 3, 5, 7, 9))
                THEN
                   t_value := SUBSTR (creditcardnumber, i, 1) * 2;
                   subtotal := subtotal + SUBSTR (t_value, 1, 1);
                   subtotal := subtotal + NVL (SUBSTR (t_value, 2, 1), 0);
                ELSE
                   subtotal := subtotal + SUBSTR (creditcardnumber, i, 1);
                END IF;                       
             END IF;
          END LOOP;
          IF MOD (subtotal, 10) = 0
          THEN
             RESULT := 'VALID';
          ELSE
             RESULT := 'INVALID';
          END IF;
       ELSIF calculationmethod = 'ANY'
       THEN
          RESULT := 'VALID';
       ELSE
          RESULT := 'UNKNOWN';
       END IF;
       RESULT := RESULT || ', ' || cardtype;
       RETURN (RESULT);
    END VALIDATECREDITCARD;
    create or replace PACKAGE        "BOOKING_PKG"
    AS
      PROCEDURE  FLIGHT (p_ptc_adult IN NUMBER,
                      p_ptc_adult_rt       IN NUMBER,
                      p_ptc_adult_add      IN NUMBER,
                      p_ptc_adult_add_rt   IN NUMBER,
                      p_city_o             IN favailability.from_city%TYPE,
                      p_city_d             IN favailability.to_city%TYPE,
                      p_service_class      IN favailability.service_class%TYPE,
                      p_fare_type          IN favailability.fare_type%TYPE,
                      p_fare_type_rt       IN favailability.fare_type%TYPE,
                      p_flightdate         IN favailability.flight_date%TYPE,
                      p_flightdate_rt      IN favailability.flight_date%TYPE,
                      p_username           IN users.username%TYPE,
                      p_password           IN users.password%TYPE,
                      p_card_type          IN users_cc.card_type%TYPE,
                      p_creditcardnumber   IN VARCHAR2,
                      p_expiry_date        IN DATE,
                      p_first_name_add     IN VARCHAR2,
                      p_last_name_add      IN VARCHAR2);
      PROCEDURE  NEW_USER (p_username      IN users.username%TYPE,
                           p_password      IN users.password%TYPE,
                           p_salutation       users.salutation%TYPE,
                           p_academic_title   users.academic_title%TYPE,
                           p_first_name       users.first_name%TYPE,
                           p_last_name        users.last_name%TYPE,
                           p_dob              users.dob%TYPE,
                           p_street_address   users.street_address%TYPE,
                           p_company_name     users.company_name%TYPE,
                           p_street_address_2 users.street_address_2%TYPE,
                           p_country          users.country%TYPE,
                           p_postal_code      users.postal_code%TYPE,
                           p_city             users.city%TYPE,
                           p_e_mail_address   users.e_mail_address%TYPE,
                           p_country_code     users.country_code%TYPE,
                           p_prefix           users.prefix%TYPE,
                           p_mobile_phone     users.mobile_phone%TYPE,
                           p_home_phone       users.home_phone%TYPE,
                           p_language         users.language%TYPE,
                           p_newsletter       users.newsletter%TYPE,
                           p_specials         users.specials%TYPE,
                           p_membership       users.membership%TYPE,
                           p_remarks          users.remarks%TYPE);
      FUNCTION  VALIDATECREDITCARD (p_creditcardnumber IN VARCHAR2) RETURN VARCHAR2;
    END BOOKING_PKG;Thanks for your help!

  • ODI Procedure error log syntax

    hi
    I need to call an odi procedure and an error log needs to be stored on an error table.
    I have created an ODI procedure and in command on source select Oracle as technology and the logical schema
    here I put
    DECLARE
    ODI_VAR VARCHAR2(4000);
    BEGIN
    select ( '<%=odiRef.getPrevStepLog( "MESSAGE" )%>') into ODI_VAR from dual;
    END;
    and in target tab.
    Insert into ERROR_LOG (TASK_NAME,ERROR_DESCRIPTION)
    Values ('test','ODI_VAR');
    AFTER executing I am getting the below error
    900 : 42000 : java.sql.SQLSyntaxErrorException: ORA-00900: invalid SQL statement
    java.sql.SQLSyntaxErrorException: ORA-00900: invalid SQL statement
         at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:457)
         at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:397)
         at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:389)
         at oracle.jdbc.driver.T4CTTIfun.processError(T4CTTIfun.java:662)
         at oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:476)
         at oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:204)
         at oracle.jdbc.driver.T4C8Odscrarr.doODNY(T4C8Odscrarr.java:101)
         at oracle.jdbc.driver.T4CPreparedStatement.doDescribe(T4CPreparedStatement.java:848)
         at oracle.jdbc.driver.OracleStatement.describe(OracleStatement.java:5331)
         at oracle.jdbc.driver.OracleResultSetMetaData.<init>(OracleResultSetMetaData.java:58)
         at oracle.jdbc.driver.OracleResultSetImpl.getMetaData(OracleResultSetImpl.java:274)
         at oracle.odi.runtime.agent.execution.sql.concurrent.FastJDBCRecordSet.<init>(FastJDBCRecordSet.java:73)
         at oracle.odi.runtime.agent.execution.sql.SQLDataProvider.readData(SQLDataProvider.java:97)
         at oracle.odi.runtime.agent.execution.sql.SQLDataProvider.readData(SQLDataProvider.java:1)
         at oracle.odi.runtime.agent.execution.DataMovementTaskExecutionHandler.handleTask(DataMovementTaskExecutionHandler.java:67)
         at com.sunopsis.dwg.dbobj.SnpSessTaskSql.processTask(SnpSessTaskSql.java:2906)
         at com.sunopsis.dwg.dbobj.SnpSessTaskSql.treatTask(SnpSessTaskSql.java:2609)
         at com.sunopsis.dwg.dbobj.SnpSessStep.treatAttachedTasks(SnpSessStep.java:537)
         at com.sunopsis.dwg.dbobj.SnpSessStep.treatSessStep(SnpSessStep.java:453)
         at com.sunopsis.dwg.dbobj.SnpSession.treatSession(SnpSession.java:1740)
         at oracle.odi.runtime.agent.processor.impl.StartSessRequestProcessor$2.doAction(StartSessRequestProcessor.java:338)
         at oracle.odi.core.persistence.dwgobject.DwgObjectTemplate.execute(DwgObjectTemplate.java:214)
         at oracle.odi.runtime.agent.processor.impl.StartSessRequestProcessor.doProcessStartSessTask(StartSessRequestProcessor.java:272)
         at oracle.odi.runtime.agent.processor.impl.StartSessRequestProcessor.access$0(StartSessRequestProcessor.java:263)
         at oracle.odi.runtime.agent.processor.impl.StartSessRequestProcessor$StartSessTask.doExecute(StartSessRequestProcessor.java:822)
         at oracle.odi.runtime.agent.processor.task.AgentTask.execute(AgentTask.java:123)
         at oracle.odi.runtime.agent.support.DefaultAgentTaskExecutor$2.run(DefaultAgentTaskExecutor.java:82)
         at java.lang.Thread.run(Thread.java:662)
    Please help me to resolve this issue.

    Hi,
    Try like this :
    Command on source :
    select ( '<%=odiRef.getPrevStepLog( "MESSAGE" )%>')  ODI_VAR from dual
    Command on target:
    Insert into ERROR_LOG (TASK_NAME,ERROR_DESCRIPTION)
    Values ('test',:ODI_VAR)
    Use the above syntax as it is....it should work..........

  • "Stale connection error" in error_log when hitting "query" button on form

    I created a simple form on a view. It has only 3 buttons:
    next, previous, and query. I hit query and get a 404 error.
    Apache's error_log file says "Stale connection due to Oracle
    error 3114". Anybody seen this?

    Carol, I treid what you said but still can't get it to work.
    Here is the code I have it the after displaying page section.
    declare
    v_myvar varchar2(30);
    v_comp varchar2(30);
    blk varchar2(10):='DEFAULT';
    begin
    if 'a_territory' is not null then
    v_comp:=p_session.get_value_as_varchar2
    (p_block_name=>blk,p_attribute_name=>'A_company_name');
    select rowid into v_myvar from cs_custinfo_view where
    company_name = v_comp;
    bico.buttons_proc(v_myvar);
    end if;
    end;
    The procedure that is called uses the rowid to call a form from
    a button that is created by the procedure. The error I get when
    I first load the form is
    An unexpected error occurred: ORA-01403: no data found
    ORA-01403: no data found (WWV-16016)
    An unexpected error occurred: ORA-01403: no data found (WWV-
    16016)
    The preference path does not exist:
    ORACLE.WEBVIEW.PARAMETERS.1257633639 (WWC-51000)
    I assume this is because there is no rowid present yet?

  • HTTP 404: PROCEDURE DOESN'T EXIST upon login

    Hi all,
    running apex 2.2 and apache on red hat linux 6.
    After many http 403 errors (ORA-1017) I finally managed to get apex to connect to the DB fine.
    I now get an http 404 error: error_log shows:
    mod_plsql: /steve/index HTTP-404
    pex: PROCEDURE DOESN'T EXIST
    Notice that the 2nd line of the error mentions "pex" instead of apex. Whatever I put after the main "dad" url (which in my case is defined as ..../steve/) the error truncates the first letter from it and I get a 404 error.
    If I look in the DB in the FLOW_020200 schema, I can not see an htmldb_admin procedure.
    What do?????

    Earl, I get the error when I try to log in to the http://host:port/myapp/ URL
    I get a 404 error in the browser and the above error in the apache/logs/error.log
    my dads.conf:
    Alias /i/ "/u01/app/oracle/product/10.1.0/HTTP_1/Apache/Apache/images/"
    AddType text/xml xbl
    AddType text/x-component htc
    <Location /steve/>
    Order deny,allow
    PlsqlDocumentPath docs
    AllowOverride None
    PlsqlDocumentProcedure wwv_flow_file_manager.process_download
    PlsqlDatabaseConnectString [host.domain:1521:SID] ServiceNameFormat
    PlsqlNLSLanguage AMERICAN_AMERICA.AL16UTF16
    PlsqlAuthenticationMode Basic
    SetHandler pls_handler
    PlsqlDocumentTablename wwv_flow_file_objects$
    PlsqlDatabaseUsername APEX_PUBLIC_USER
    PlsqlDefaultPage apex
    PlsqlDatabasePassword "XXXXXXXXXXXXXXX"
    Allow from all
    </Location>
    The url:
    http://[host.domain]:7777/steve/
    The error log:
    [Mon Oct  9 16:14:51 2006] [error] [client 10.44.240.130] [ecid: 1160406891:10.44.12.35:32002:0:28,0] mod_plsql: /steve/apex HTTP-404
    pex: PROCEDURE DOESN'T EXIST

  • Difference between ERROR_LOGGING and SAVED EXCEPTION

    Hi All,
    greetings for the day.
    i would like to know the difference between SAVED EXCEPTION and ERROR_LOGGING.
    my requirement is like without interrupting the main procedure flow (although we got BAD file during the bulk collection, bulk insert )..?
    what should i proceed for this scenario?
    version is 10g..
    thanks in advance

    >
    i would like to know the difference between SAVED EXCEPTION and ERROR_LOGGING.
    my requirement is like without interrupting the main procedure flow (although we got BAD file during the bulk collection, bulk insert )..?
    what should i proceed for this scenario?
    >
    As already mentioned one is SQL the other is PL/SQL.
    So the first decision to make is whether you need PL/SQL to do what you are doing. Use SQL whenever possible.
    If you are using SQL then you can't use SAVE EXCEPTIONS so the choice between that and LOG ERRORS is made for you.
    There are some major difference between the two:
    1. SAVE EXCEPTIONS will work for all datatypes whereas the use of a log table has restrictions.
    2. SAVE EXCEPTIONS will not provide ANY indication (other than the error code) of which column(s) caused the exception. A log table can be used to check for problems in a user-specified list of columns
    3. SAVE EXCEPTIONS will not providing the offending value whereas a log table will log the offending value so you can examine it.
    4. SAVE EXCEPTIONS will not save any of the offending data you must save it yourself if you want it. The log table will save all of the offending data but you must then manage/delete it yourself.
    5. SAVE EXCEPTIONS will trap ALL errors whereas dml logging will not.
    See 'Error Logging Restrictions and Caveats' in the DBA guide
    http://docs.oracle.com/cd/B28359_01/server.111/b28310/tables004.htm
    >
    Some errors are not logged, and cause the DML operation to terminate and roll back. For a list of these errors and for other DML logging restrictions, see the discussion of the error_logging_clause in the INSERT section of Oracle Database SQL Language Reference.
    >
    And see Restrictions on DML Error Logging in the SQL doc
    http://docs.oracle.com/cd/B28359_01/server.111/b28286/statements_9014.htm#SQLRF01604
    One use of logging tables is in ETL and data cleansing processes. For example incoming data might be 'dirty': values out of range (i.e. CHECK contraint violations), null data when it must be NOT NULL and the like. If a log table is used this data can be filtered out and saved in the log table where it can be examined and/or fixed.
    If I have 5 columns that might be 'dirty' an error in ANY of the five can cause all five values to be recorded in the log table. Only one of the values actually CAUSED the error (the exception is raised as soon as there is an error) but the other four values will be recorded. Then when I examine the log table I check all five values to determine which ones are 'dirty'. I can then take appropriate action.
    If I were using SAVE EXCEPTIONS I would need to have code that identifies and saves the original source data so I can examine it later.

  • Pricing procedure of free goods

    Could anyone please tell me the effect of pricing procedure in free godds?And what is the difference between pricing procedure in free goods(IMG->Sales and Distribution->Basic Funcions->Free Goods) and pricing procedure in pricing(IMG->Sales and Distribution->Basic Funcions->Pricing)

    Hi Wei Zhang,
    When there are more than 2 materials say material A which is of some price, and material B which is Free of cost, then the item category will be different for those. TAN for Mat A and TANN for materail B.
    Pricing is depends upon the customer pricing procedure and document pricing procedure along with the Sales Area.
    When there are free Goods, Again yu have two conditions
    1. Give 100 % discount on free goods.
    2. Or charge 0 value for that.
    This pricing procedure you can do in free goods priocing procedure.
    Hope this will help.
    Thanks,
    Raja

  • Can not select from data dictionary view from a procedure

    Hi,
    I wonder, which privilege is missing here:
    my schema has this roles and privs:
    GRANT CONNECT, RESOURCE TO cb ;
    GRANT CREATE SESSION TO cb ;
    GRANT SELECT_CATALOG_ROLE TO cb ;
    GRANT CREATE SYNONYM TO CB;
    GRANT CREATE VIEW TO CB;
    I create a procedure:
    create or replace procedure dd_test as
    begin
         dbms_output.enable(2000000);
         for r in (select table_name from sys.dba_tab_partitions     where owner = 'CB') loop
                   dbms_output.put_line(r.table_name);
         end loop;
    end;
    sho err
    4/38 PL/SQL: ORA-00942: table or view does not exist
    When I run the core statement form sql prompt, it works !
    so what privilege is missing here ???
    thanks for any hint, Lao De

    Hi,
    thanks for that reply, after doing that I can not select this DD-view from sql-prompt anymore (which I don't wonder ;-). Can you tell me, what idea you had behind that test ?
    I found another instance, where the procedure works and I will compare those privileges, but it's hard to sort out that complex structure of nested roles and sys_privs.
    How ever, I will update here, when I found the missing privilege.
    regards LaoDe

  • Unable to capture the parameter values from a PL/SQL procedure

    hi.
    i'm trying to capture the parameter values of a PL/SQL procedure by calling inside a anonymous block but i'm getting a "reference to uninitialized collection error" ORA-06531.
    Please help me regarding.
    i'm using following block for calling the procedure.
    declare
    err_cd varchar2(1000);
    err_txt VARCHAR2(5000);
    no_of_recs number;
    out_sign_tab search_sign_tab_type:=search_sign_tab_type(search_sign_type(NULL,NULL,NULL,NULL,NULL));
    cntr_var number:=0;
    begin
         rt843pq('DWS','3000552485',out_sign_tab,no_of_recs,err_cd,err_txt);
         dbms_output.put_line('The error is ' ||err_cd);
         dbms_output.put_line('The error is ' ||err_txt);
         dbms_output.put_line('The cntr is ' ||cntr_var);
         for incr in 1 .. OUT_SIGN_TAB.count
         loop
         cntr_var := cntr_var + 1 ;
    Dbms_output.put_line(OUT_SIGN_TAB(incr).ref_no||','||OUT_SIGN_TAB(incr).ciref_no||','||OUT_SIGN_TAB(incr).ac_no||','||OUT_SIGN_TAB(incr).txn_type||','||OUT_SIGN_TAB(incr).objid);
    end loop;
    end;
    Error is thrown on "for incr in 1 .. OUT_SIGN_TAB.count" this line
    Following is some related information.
    the 3rd parameter of the procedure is a out parameter. it is a type of a PL/SQL table (SEARCH_SIGN_TAB_TYPE) which is available in database as follows.
    TYPE "SEARCH_SIGN_TAB_TYPE" IS TABLE OF SEARCH_SIGN_TYPE
    TYPE "SEARCH_SIGN_TYPE" AS OBJECT
    (ref_no VARCHAR2(22),
    ciref_no VARCHAR2(352),
    ac_no VARCHAR2(22),
    txn_type VARCHAR2(301),
    objid VARCHAR2(1024))............

    We don't have your rt843pq procedure, but when commenting that line out, everything works:
    SQL> create TYPE "SEARCH_SIGN_TYPE" AS OBJECT
      2  (ref_no VARCHAR2(22),
      3  ciref_no VARCHAR2(352),
      4  ac_no VARCHAR2(22),
      5  txn_type VARCHAR2(301),
      6  objid VARCHAR2(1024))
      7  /
    Type is aangemaakt.
    SQL> create type "SEARCH_SIGN_TAB_TYPE" IS TABLE OF SEARCH_SIGN_TYPE
      2  /
    Type is aangemaakt.
    SQL> declare
      2    err_cd varchar2(1000);
      3    err_txt VARCHAR2(5000);
      4    no_of_recs number;
      5    out_sign_tab search_sign_tab_type:=search_sign_tab_type(search_sign_type(NULL,NULL,NULL,NULL,NULL));
      6    cntr_var number:=0;
      7  begin
      8    -- rt843pq('DWS','3000552485',out_sign_tab,no_of_recs,err_cd,err_txt);
      9    dbms_output.put_line('The error is ' ||err_cd);
    10    dbms_output.put_line('The error is ' ||err_txt);
    11    dbms_output.put_line('The cntr is ' ||cntr_var);
    12    for incr in 1 .. OUT_SIGN_TAB.count
    13    loop
    14      cntr_var := cntr_var + 1 ;
    15      Dbms_output.put_line(OUT_SIGN_TAB(incr).ref_no||','||OUT_SIGN_TAB(incr).ciref_no||','||OUT_SIGN_TAB(incr).ac_no||','||OUT_SIGN
    TAB(incr).txntype||','||OUT_SIGN_TAB(incr).objid);
    16    end loop;
    17  end;
    18  /
    The error is
    The error is
    The cntr is 0
    PL/SQL-procedure is geslaagd.Regards,
    Rob.

Maybe you are looking for

  • Authorization: Prevent BP creation in CRM2007

    Hello, we are working in CRM 2007 and we would like to prevent some users to create Corporate Account. It cannot be solely achieved by removing the Logical Link from Account Management workcenter. Indeed, the functionality is embeded in the 'Search'

  • Creating SOD matrix with the help of Access control default ruleset

    I am creating the SOD matrix for the existing roles of CRM and HR modules.  As I am the security consultant therefore does not have the functional knowledge about the conflicts for CRM and HR transactions. My question is can I use the function/action

  • Ps to PDF problem

    Hello there, I've a little annoying problem with distiller. I'm using a linux program which is creating ps files than transferring into windows and converting to .pdf with distiller. But PS files have this string; stroke showpage savepage this causes

  • How to connect database using type4 driver(dsn or dsnless connection)

    please send any one reply answer

  • DVD Burning Shuts Off Computer

    Hello I'm trying to burn a DVD with just the normal burn folder. The file fits on a DVD(2.61 gb). The file is just a disk image of my Logic songs. I so far have wasted 5 DVD's trying to burn this thing. About half way through burning the computer tur