Oracle procedure

Friends and experts, DB: 11 GR 2

Can someone guide me how can I write the Oracle procedure to query data in a loop?

Sounds really complicated and do not know, even if it is possible.

Table contains 500 lines of millet

Basically, I try to find below in the output

1. what host/pid continuously for 5 minutes with more than 75% of cpu

2. get the average start and end with CPU time

3. get top 5 folders for each type of host by avg_cpu

Table: tab1

Data in the table:

Date server pid cpu_used

01/01/2015-02:00 75 1234 s1

01/01/2015-02:01 75 1234 s1

01/01/2015 s1 02:02 80 1234

01/01/2015 s1 02:03 75 1234

01/01/2015 02:04 90 1234 s1

01/01/2015 s1 02:05 1234 75

01/01/2015 s1 02:06 70 1111

01/01/2015 s2 02:04 85 5678

01/01/2015 s2 02:05 90 5678

01/01/2015 s2 02:06 75 5678

01/01/2015 s2 02:07 80 5678

01/01/2015 s2 02:08 90 5678

01/01/2015 s2 02:09 90 5678

01/01/2015 s1 02:09 60 1234

Example of output

Server pid start_date end_date avg_cpu

S1 1234 01/01/2015 02:00 01/01/2015 02:05 85

S2 01/01/2015 5678, 02; 04:00 01/01/2015 02:09 84

with

tab1 as

(select to_date (1 January 2015 02:00 "," mm/dd/yyyy hh) date_, 's1' server, 1234 pid, 75 cpu_used Union double all the)

Select to_date (1 January 2015 02:01 "," mm/dd/yyyy hh), "s1", 1234, 75 double Union all

Select to_date (1 January 2015 02:02 "," mm/dd/yyyy hh), "s1", 1234, 80 of double union all

Select to_date (1 January 2015 02:03 "," mm/dd/yyyy hh), "s1", 1234, 75 double Union all

Select to_date (1 January 2015 02:04 ',' dd/mm/yyyy hh), "s1", 1234, 90 double Union all

Select to_date (1 January 2015 02:05 ',' dd/mm/yyyy hh), "s1", 1234, 75 double Union all

Select to_date (1 January 2015 02:06 "," mm/dd/yyyy hh), "s1", 1234, 78 double Union all

Select to_date (1 January 2015 02:07 "," mm/dd/yyyy hh), "s1", 1234, 75 double Union all

Select to_date (January 1, 2015 08:02 "," mm/dd/yyyy hh), "s1", 1234, 80 of double union all

Select to_date (1 January 2015 02:09 "," mm/dd/yyyy hh), "s1", 1234, 75 double Union all

Select to_date (1 January 2015 02:10 "," mm/dd/yyyy hh), "s1", 1234, 90 double Union all

Select to_date (1 January 2015 02:11 "," mm/dd/yyyy hh), "s1", 1234, 75 double Union all

Select to_date (1 January 2015 02:12 "," mm/dd/yyyy hh), "s1", 1111, 70 double Union all

Select to_date (1 January 2015 02:04 ',' dd/mm/yyyy hh), 's2', 5678, 85 double Union all

Select to_date (1 January 2015 02:05 ',' dd/mm/yyyy hh), 's2', 5678, 90 double Union all

Select to_date (1 January 2015 02:06 "," mm/dd/yyyy hh), 's2', 5678, 75 double Union all

Select to_date (1 January 2015 02:07 "," mm/dd/yyyy hh), 's2', 5678, 80 of double union all

Select to_date (January 1, 2015 08:02 "," mm/dd/yyyy hh), 's2', 5678, 90 double Union all

Select to_date (1 January 2015 02:09 "," mm/dd/yyyy hh), 's2', 5678, 90 double Union all

Select to_date (1 January 2015 02:15 "," mm/dd/yyyy hh), "s1", 1234, 60 double

)

Select Server pid, start_date, end_date, avg_cpu

(select Server,

nest,

start_date to_char (min (date_), ' mm/dd/yyyy HH'),

End_date to_char (max (date_), ' mm/dd/yyyy HH'),

Round (AVG (cpu_used), 2) avg_cpu.

ROW_NUMBER() on rn (partition by order of servers by avg (cpu_used) desc)

(select date_, pid, cpu_used,

5 * ceil (row_number () over (partition by server, pid, case when cpu_used > = 75 then 1 by date_ end order) / 5) w,

ROW_NUMBER() over (partition by order of servers by pid, date_).

ROW_NUMBER() over (partition by server, pid, case when cpu_used > = 75 then 1 by date_ end order) g

of tab1

)

Group server, pid, g, w

having count (*) > = 5

and avg (cpu_used) > = 75

)

SERVER PID START_DATE END_DATE AVG_CPU
S1 1234 02:00 01/01/2015 02:04 01/01/2015 79
S1 1234 02:05 01/01/2015 02:09 01/01/2015 76.6
S2 5678 02:04 01/01/2015 02:08 01/01/2015 84

Concerning

Etbin

Tags: Database

Similar Questions

  • Open and close the connection in oracle procedure

    Here is the procedure I'm in I insert data into the table temp_soap_monitoring using the select statement. I have soap_monitoring table FONIC_RETAIL database where I want to take the data and insert into the table temp_soap_monitoring. I play the position of planner of all 5 minutes for this procedure so that I get always the latest data in soap_monitoring@fonic_retail table. The problem of this procedure is that it takes too much cost and the query execution time to perform this procedure. Whenever he tries to extract the data from db link and save my local database. I remember in Java, php, and other programming languages, we have method in order to open the db connection when we tried to extract data from db link and then once integration is complete, we can close the db connection. So the performance improves and also has no load on db link. In this method, we have to assign link db to retrieve the data. So I think is it possible to apply this logic in my oracle procedure. The question arises because at this moment I am hard code the link db, but now I have 3 db more links and I will not reproduce the same procedure by assigning diffferent db links.

    PROCEDURE  "EXT_SOAP_MONITORING" AS

    LAST_SM_ID Number
    := 0;
    LAST_CAPT_DATE DATE
    ;

    BEGIN

    SELECT LAST_TASK_ID INTO LAST_SM_ID FROM CAPTURING where DB_TABLE='TEMP_SOAP_MONITORING';

    insert into TEMP_SOAP_MONITORING(ID,REQUEST_XML,RESPONSE_XML,WEB_SERVICE_NAME,WEB_METHOD_NAME,CREATE_DATE,ERROR_CODE,ERROR_MESSAGE)
    select ID,REQUEST_XML,RESPONSE_XML,WEB_SERVICE_NAME,WEB_METHOD_NAME,CREATE_DATE,ERROR_CODE,ERROR_MESSAGE from
    SOAP_MONITORING
    @FONIC_RETAIL WHERE WEB_SERVICE_NAME ='RatorWebShopService'  and WEB_METHOD_NAME = 'placeShopOrder' and ID > LAST_SM_ID order by ID desc;

    update
    CAPTURING
    set LAST_TASK_ID=
    CASE WHEN ((SELECT MAX(ID) from TEMP_SOAP_MONITORING) IS NULL) AND (LAST_TASK_ID  IS NULL)  THEN (SELECT MAX(ID) from SOAP_MONITORING@FONIC_RETAIL)
    WHEN (SELECT MAX(ID) from TEMP_SOAP_MONITORING) IS NULL THEN LAST_TASK_ID + 1
    ELSE (SELECT MAX(ID) from TEMP_SOAP_MONITORING) END,
    CAPTURING_DATE
    = CURRENT_TIMESTAMP, LAST_CAPTURED_DATE = LAST_CAPT_DATE where DB_TABLE='TEMP_SOAP_MONITORING';

    END EXT_SOAP_MONITORING;

    I have it here is the procedure which I insert data in

    temp_soap_monitoring table by using the select statement. I have

    soap_monitoring table of FONIC_RETAIL database where I want to take the data and insert into the table temp_soap_monitoring.

    WHY? Why you are moving the data? Why not just use it table, is it already?

    The problem of this procedure is that it takes too much cost and the query execution time to perform this procedure.

    The solution is to FIND THE PROBLEM. Troubleshoot the code and find out where is the problem, if any.

    Based SOLELY on what you have posted the solution might be to add just an appropriate index.

    Whenever he tries to extract the data from db link and save my local

    database. I remember in Java, php, and other programming languages, we

    method to open the db connection when we tried to extract data of

    DB link and then once integration is complete, we can close the db

    connection.  So the performance improves and also has no load on db link.

    What? The LAST thing you want to do is keep the closing and opening of the connections. I don't know how 'remember you' from Java or other languages. The main reasons pools of connections were invented to AVOID have to repeatedly open and close connections.

    A db link not a NOT a "charge" - the "charge" is the query is made. If you write a poor query or have a poor data without the necessary index model, or have missing statistics, then you will get poor results.

    In this method, we have to assign link db to retrieve the data. So I have
    is it possible to apply this logic in my oracle procedure to belive. The
    question arises because at the moment, I'm hardcode db link but now I
    have more ties db 3 and I will not reproduce the same procedure by
    assigning diffferent db links.

    You can certainly write Java code to connect to each database with a direct connection. But all write code PL/SQL must include the database link. And the only way to avoid hard-coding the link is to keep the names of link in a table and use dynamic sql statements to build and run the query. This isn't what you want to do if you're looking for performance.

    SELECT LAST_TASK_ID INTO LAST_SM_ID FROM CAPTURING where DB_TABLE='TEMP_SOAP_MONITORING';

    For all we know which could be the WHOLE CAUSE of your problem. If there is no index on the table, you could do a full table to a table with lines scan 800 billion;

    We have NO WAY of knowing since you haven't posted info. Please read the faq to find out how to post a request for tuning and the info you provide.

    1. the query

    2. the table and index DDL

    3. the execution plan

    4 RowCounts for tables and query predicates

    5. the info on the stats: how you collected them and if they are up to date

    update
    CAPTURING set LAST_TASK_ID=
    CASE WHEN ((SELECT MAX(ID) from TEMP_SOAP_MONITORING) IS NULL) AND (LAST_TASK_ID  IS NULL)  THEN (SELECT MAX(ID) from SOAP_MONITORING@FONIC_RETAIL)
    WHEN (SELECT MAX(ID) from TEMP_SOAP_MONITORING) IS NULL THEN LAST_TASK_ID + 1
    ELSE (SELECT MAX(ID) from TEMP_SOAP_MONITORING) END,
    CAPTURING_DATE = CURRENT_TIMESTAMP, LAST_CAPTURED_DATE = LAST_CAPT_DATE where DB_TABLE='TEMP_SOAP_MONITORING';

    My guess is that TERRIBLE method of trying to get a 'LAST ID' is what's causing ALL your problems of performance. This method will not scale, and it will NOT properly work in a multiuser environment.

    You need create a good BATCH_CONTROL table that all processes use during the creation and execution of lots.

    The MASTER of the process batch:

    1 Gets a new BATCH_ID using a sequence

    2 locks the current row in the table control and uses / change the value "last".

    3 creates a new line in the control table for the new batch process

    4. the line of control to date with the start time, end time, result State, County, etc. for the batch

    Your likely PROBLEM of has NOTHING to do with the links of the db.

  • Call Oracle procedure with variable

    Experts,

    I pass arguments through script to Oracle procedure, use the input value and pass to the procedure.

    Oracle procedure Gets the input value, run the query, and all connect to the log file.

    I am facing a few challenges, seems to be the error of syntax or data type

    1. even if I pass all the script parameter still run complains of wrong number or type of arguments.

    There are three numbers followed by a date variable

    2. how to pass a variable value with the INTERVAL function, it should take the value of the variable lThird for example "" AND date > = date + INTERVAL '30' MINUTE; "but somehow, after trying different variants still get error like interavl not valid."

    3 see someone more changes to this?

    ! / bin/ksh

    $1 = 10;

    $2 = 30;

    3 = $50

    $4 = '20150113';

    echo "Oracle procedure in progress"

    (

    set linesize 100

    pkg.proc exec ($1, $2, $3, $4);

    ) > $logFile

    If [$? == 0]

    then

    EXIT_VAL = 0

    = Package/oracle procedure =.

    CREATE or REPLACE PACKAGE pkg

    AS

    procedure proc (lFirst in number,

    lSecond in numbers

    lThird in numbers

    date IN oven,

    curReturn to sys_refcursor);

    Pkg of END;

    /

    CREATE or REPLACE PACKAGE pkg BODY

    AS

    PROCEDURE proc (lFirst in number,

    lSecond in numbers

    lThird in numbers

    date IN oven,

    curReturn ON sys_refcursor)

    IS

    BEGIN

    OPEN FOR CurReturn

    SELECT date,

    emp_id,

    first name,

    last_name

    Employees

    WHERE Emp_id in (lFirst, lSecond)

    Date AND > = date + MINUTE INTERVAL "(lThird)"

    AND date = TO_DATE (oven, 'YYYYMMDD')-1;

    END proc;

    Pkg of END;

    /

    Error:

    PLS-306: wrong number or types of argument in the call to proc

    Hello

    With regard to your needs:

    My current problem is

    1. how to store the SELECT results in the log file, ask has several columns with multiple lines

    2. what happens when SELECT brings out no line?

    I have re-used, corrected and adapted to your procedure:

    Package:

    CREATE or REPLACE PACKAGE pkg

    AS

    PROCEDURE proc (lFirst in number,

    lSecond in numbers

    lThird IN varchar2,

    curReturn to sys_refcursor);

    Pkg of END;

    /

    CREATE or REPLACE PACKAGE pkg BODY

    AS

    PROCEDURE proc (lFirst in number,

    lSecond in numbers

    lThird IN varchar2,

    curReturn ON sys_refcursor)

    IS

    BEGIN

    OPEN FOR CurReturn

    SELECT *.

    WCP

    WHERE empno in (lFirst, lSecond)

    AND hiredate > = TO_DATE (lThird, 'YYYYMMDD');

    END proc;

    Pkg of END;

    /

    Shell script: test_sql.sh

    #! / bin/ksh

    V_user = scott

    V_pass = Tiger

    echo "Oracle procedure in progress"

    Req ='sqlplus-s $V_user / $V_pass<>

    var refcursor rc

    exec pkg.proc ($1, $2, $3,: rc)

    print the rc

    output

    EXPRESSIONS OF FOLKLORE"

    echo "$req" > logfile$ $

    PS:

    (1) you must put the name of your user/passwd name and table (I used the scott/tiger schema by default with emp table). This is just to show how to retrieve a refcursor output in a script.

    (2) I used logfile$ $ as output file; You can use any other file or method name to redirect the output to a file

    Call us at:

    19000101 7934 7900 test_sql.sh

    PS: As noted in the previous posts, you cannot define a VARIABLE of type DATE in sqlplus (or a Unix script); You can send a string and perform the conversion in the SQL section.

    If no line is not recovered, you get the following in the log file:

    PL/SQL procedure successfully completed.
    
    no rows selected
    

    HTH.

  • APEX - how to add a button to a page to run an oracle procedure

    I built a page of database with a display in a table on a database. The query table uses the user id to filter records. everything works very well.
    How can I add an independent button to the page that runs an oracle procedure when clicked.

    Create a button on your page to send the page. Now create a page process as follows:

    BEGIN
       your_proc_name;
    END;
    

    Make this process depends on what button and select above created button.

    Published by: Zahid Khan on May 26, 2011 15:32

  • Access to the Oracle procedure table

    Hi all

    I can pass the array as a parameter of procedure Oracle object?
    Application procedure for the environment to run Java and we pass the java array object as a parameter


    Thanks in advance...

    Kind regards...

    http://lmgtfy.com/?q=Java+pass+array+to+Oracle+procedure

  • How to debug the Oracle procedure

    Hi friends,

    I've migrated oracle procedure from Oracle 8.0.4 DB of NT to DB Oracle 9.2.0 on IBM AIX.
    When I test/execute the procedure on the Db 9.2.0, she still runs and did not end.

    How to debug an Oracle procedure to check if it's a loop on the same block foever, what "current" values is owner and what tables he read to, or procedure does never loops as if it is not to satisfy one of the conditions?

    Thank you very much

    Is coding "infinite loop" a bad habit of programming?

    Yes, you can call it such.
    Personally, I prefer to use loops.
    See http://tahiti.oracle.com for the different types of loops that you can use.

    How can I change this infinite loop in a "finite" without changing the logic of the program?

    You can use EXIT WHEN "certain conditions."
    For example, you can add OUTPUT WHEN cursorname % notfound, or some counter to reach a specific value in your loop, to 'force' the loop to stop.
    See the docs or do a search on this forum for more examples.

  • Best practices of Oracle procedure

    Hi all! I'm a SQL Server DBA, and I learn Oracle I intend to become an Oracle DBA for many reasons.

    I need the opinion of experts on something here. To give you a time frame: it is very common to use stored procedures in SQL Server to return result sets, rather than SQL ad hoc because it is handier and safer (and sometimes better performance).

    Can say the same for Oracle procedures, or is it totally different? I cringe at the idea of having to include ad hoc SQL in application layer instead of calling a procedure that runs the code that is stored inside the Oracle.

    Experts, how do you manage this? Do you have the actual SQL code in your applications? Is it true that Oracle procedures can return result sets with the sliders?

    Thank you for putting up with my novice questions. :)

    Justin

    Ok.

    To run the above procedure, you must use->

    exec Budget.usp_SpendingVsBudgetDetail(to_date('2009-04-01','YYYY-MM-DD'),to_date('2009-04-30','YYYY-MM-DD'));
    

    At the SQL prompt.

    Kind regards.

    LOULOU.

    An extra single quote was deleted...

    Published by: Satyaki_De on April 13, 2009 09:47

  • In passing the huge parameter to oracle procedure have a performance hit?

    I have a script attached, in which I am trying process/XML parsing in a table (STAGE_TBL) in the XMLTYPE column and insert the data analyzed in another table (PROCESSED_DATA_TBL). The XML file can be huge up to 2MB, which translates into approximately 2000 + lines of analyzed data. The issue I see is when I pass an XML object to a procedure (STAGE_TBL_PROCESS) to analyze its takes about 10 seconds per XML, but rather than from XML if I directly pick up table in the procedure (STAGE_TBL_PROCESS) passing the ID to be about 0.15 seconds. According to the document while params are passed by reference, so why is this variation of performance?

    Details of database Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64-bit version of PL/SQL Production 11.2.0.3.0 - Production "CORE 11.2.0.3.0 Production" TNS for Linux: Version 11.2.0.3.0 - Production NLSRTL Version 11.2.0.3.0 - Production

    Note: I could not perform SQL_TRACE or DBMS_STATS as I don't have access to them.

    /*
    This one is taking .15 seconds to process an XML with about 2000 rp_sendRow elements
    */

    DECLARE
     
    CURSOR NewStage IS
      
    SELECT *
      
    FROM STAGE_TBL
      
    WHERE  status = 'N'
      
    ORDER BY PUT_TIME ASC;
      SUBTYPE rt_NewStage
    IS NewStage % rowtype;

      ROW_COUNT INTEGER
    := 0;   -- Return value from calling the procedure
      READ_COUNT INTEGER
    := 0;   -- Number of rows read from the stage table
      INSERT_COUNT_TOTAL INTEGER
    := 0;   -- Number of Inserts Inven records
      ERROR_COUNT INTEGER
    := 0;   -- Number of Inven inserts that did inserted more then 1 row in Inven
      PROCESS_STATUS STATUS
    .MmsStatus;
      STATUS_DESCRIPTION STATUS
    .MmsStatusReason;
      ERRMSG VARCHAR2
    (500);

    PROCEDURE STAGE_TBL_PROCESS (IDDATA IN RAW, PROCESS_STATUS OUT VARCHAR2, STATUS_DESCRIPTION OUT VARCHAR2, ROW_COUNT OUT NUMBER) AS
    /*
      This procedure is to parse the XML from STAGE_TBL and populate the data from XML to PROCESSED_DATA_TBL table

      IN PARAMS
      ----------
      IDDATA - ID from STAGE_TBL
      xData - XMLType field from XML_DOCUMENT of STAGE_TBL

      OUT PARAMS
      -----------
      PROCESS_STATUS - The STATUS of parsing and populating PROCESSED_DATA_TBL
      STATUS_DESCRIPTION - The description of the STATUS of parsing and populating PROCESSED_DATA_TBL
      ROW_COUNT - Number of rows inserted into PROCESSED_DATA_TBL
    */

    BEGIN
      
    INSERT ALL INTO PROCESSED_DATA_TBL 
      
    (PD_ID, 
      STORE
    , 
      SALES_NBR
    , 
      UNIT_COST
    , 
      ST_FLAG
    , 
      ST_DATE
    , 
      ST
    , 
      START_QTY
    , 
      START_VALUE
    , 
      START_ON_ORDER
    , 
      HAND
    , 
      ORDERED
    , 
      COMMITED
    , 
      SALES
    , 
      RECEIVE
    , 
      VALUED
    , 
      ID_1
    , 
      ID_2
    , 
      ID_3
    , 
      UNIT_PRICE
    , 
      EFFECTIVE_DATE
    , 
      STATUS
    , 
      STATUS_DATE
    , 
      STATUS_REASON
    ) 
      
    VALUES (IDDATA 
      
    ,store 
      
    ,SalesNo 
      
    ,UnitCost 
      
    ,StWac 
      
    ,StDt 
      
    ,St 
      
    ,StartQty 
      
    ,StartValue 
      
    ,StartOnOrder 
      
    ,Hand 
      
    ,Ordered 
      
    ,COMMITED 
      
    ,Sales 
      
    ,Rec 
      
    ,Valued 
      
    ,Id1 
      
    ,Id2 
      
    ,Id3 
      
    ,UnitPrice 
      
    ,to_Date(EffectiveDate||' '||EffectiveTime, 'YYYY-MM-DD HH24:MI:SS') 
      
    ,'N'  
      
    ,SYSDATE 
      
    ,'XML PROCESS INSERT')  
      
    WITH T AS
      
    ( SELECT STG.XML_DOCUMENT FROM STAGE_TBL STG WHERE STG.ID = IDDATA)  
    -- This is to parse and fetch the data from XML 
      
    SELECT E.* FROM T, XMLTABLE('rp_send/rp_sendRow' PASSING T.XML_DOCUMENT COLUMNS
      store VARCHAR
    (20) PATH 'store'  
      
    ,SalesNo VARCHAR(20) PATH 'sales' 
      
    ,UnitCost NUMBER PATH 'cost' 
      
    ,StWac VARCHAR(20) PATH 'flag' 
      
    ,StDt DATE PATH 'st-dt' 
      
    ,St NUMBER PATH 'st' 
      
    ,StartQty NUMBER PATH 'qty' 
      
    ,StartValue NUMBER PATH 'value' 
      
    ,StartOnOrder NUMBER PATH 'start-on-order' 
      
    ,Hand NUMBER PATH 'hand' 
      
    ,Ordered NUMBER PATH 'order' 
      
    ,Commited NUMBER PATH 'commit' 
      
    ,Sales NUMBER PATH 'sales' 
      
    ,Rec NUMBER PATH 'rec' 
      
    ,Valued NUMBER PATH 'val' 
      
    ,Id1 VARCHAR(30) PATH 'id-1' 
      
    ,Id2 VARCHAR(30) PATH 'id-2' 
      
    ,Id3 VARCHAR(30) PATH 'id-3' 
      
    ,UnitPrice NUMBER PATH 'unit-pr' 
      
    ,EffectiveDate VARCHAR(30) PATH 'eff-dt' 
      
    ,EffectiveTime VARCHAR(30) PATH 'eff-tm' 
      
    ) E;  
      ROW_COUNT 
    := SQL%ROWCOUNT;  -- Not the # of all the rows inserted.
      PROCESS_STATUS 
    := STATUS.PROCESSED;
      
    IF ROW_COUNT < 1 THEN   -- The insert failed Row Count = 0 No exception thrown
      PROCESS_STATUS 
    := STATUS.ERROR;
      STATUS_DESCRIPTION 
    := 'ERROR Did not insert into Pos Inventory. Reason Unknown';
      
    END IF;
      EXCEPTION
      
    WHEN OTHERS THEN
      ROW_COUNT 
    := 0;
      PROCESS_STATUS 
    := STATUS.ERROR;
      STATUS_DESCRIPTION 
    := 'SqlCode:' || SQLCODE || ' SqlErrMsg:' || SQLERRM;
    END;


    BEGIN
      DBMS_OUTPUT
    .enable(NULL);
     
    FOR A_NewStage IN NewStage
      LOOP
      READ_COUNT
    := READ_COUNT + 1;
      STAGE_TBL_PROCESS
    (A_NewStage.ID, PROCESS_STATUS, STATUS_DESCRIPTION, ROW_COUNT);
      INSERT_COUNT_TOTAL
    := INSERT_COUNT_TOTAL + ROW_COUNT;
      
    IF(ROW_COUNT <= 0 OR PROCESS_STATUS = STATUS.ERROR) THEN
      ERROR_COUNT
    := ERROR_COUNT + 1;
      
    UPDATE STAGE_TBL
      
    SET status  = PROCESS_STATUS,
      status_DATE 
    = SYSDATE,
      status_DESCRIPTION 
    = STATUS_DESCRIPTION
      
    WHERE ID  = A_NewStage.ID;
      
    ELSE
      
    UPDATE STAGE_TBL
      
    SET status  = PROCESS_STATUS,
      status_DATE 
    = SYSDATE,
      status_DESCRIPTION 
    = STATUS_DESCRIPTION,
      SHRED_DT 
    = SYSDATE
      
    WHERE ID  = A_NewStage.ID;
      
    END IF;
      
    COMMIT;
     
    END LOOP;
     
    COMMIT;
     
    IF ERROR_COUNT > 0 THEN
      ERRMSG
    := '** ERROR: ' || ERROR_COUNT || ' Stage records did not insert in to the Processed table correctly';
      RAISE_APPLICATION_ERROR
    (-20001,ErrMsg); 
     
    END IF;
      EXCEPTION
      
    WHEN OTHERS THEN
      RAISE
    ;
    END ;

    /*
    This one is taking 10 seconds to process an XML with about 2000 rp_sendRow elements
    */

    DECLARE
     
    CURSOR NewStage IS
      
    SELECT *
      
    FROM STAGE_TBL
      
    WHERE  status = 'N'
      
    ORDER BY PUT_TIME ASC;
      SUBTYPE rt_NewStage
    IS NewStage % rowtype;

      ROW_COUNT INTEGER
    := 0;   -- Return value from calling the procedure
      READ_COUNT INTEGER
    := 0;   -- Number of rows read from the stage table
      INSERT_COUNT_TOTAL INTEGER
    := 0;   -- Number of Inserts Inven records
      ERROR_COUNT INTEGER
    := 0;   -- Number of Inven inserts that did inserted more then 1 row in Inven
      PROCESS_STATUS STATUS
    .MmsStatus;
      STATUS_DESCRIPTION STATUS
    .MmsStatusReason;
      ERRMSG VARCHAR2
    (500);

    PROCEDURE STAGE_TBL_PROCESS (IDDATA IN RAW, xData IN STAGE_TBL.XML_DOCUMENT%TYPE, PROCESS_STATUS OUT VARCHAR2, STATUS_DESCRIPTION OUT VARCHAR2, ROW_COUNT OUT NUMBER) AS
    /*
      This procedure is to parse the XML from STAGE_TBL and populate the data from XML to PROCESSED_DATA_TBL table

      IN PARAMS
      ----------
      IDDATA - ID from STAGE_TBL
      xData - XMLType field from XML_DOCUMENT of STAGE_TBL

      OUT PARAMS
      -----------
      PROCESS_STATUS - The STATUS of parsing and populating PROCESSED_DATA_TBL
      STATUS_DESCRIPTION - The description of the STATUS of parsing and populating PROCESSED_DATA_TBL
      ROW_COUNT - Number of rows inserted into PROCESSED_DATA_TBL
    */

    BEGIN
      
    INSERT ALL INTO PROCESSED_DATA_TBL 
      
    (PD_ID, 
      STORE
    , 
      SALES_NBR
    , 
      UNIT_COST
    , 
      ST_FLAG
    , 
      ST_DATE
    , 
      ST
    , 
      START_QTY
    , 
      START_VALUE
    , 
      START_ON_ORDER
    , 
      HAND
    , 
      ORDERED
    , 
      COMMITED
    , 
      SALES
    , 
      RECEIVE
    , 
      VALUED
    , 
      ID_1
    , 
      ID_2
    , 
      ID_3
    , 
      UNIT_PRICE
    , 
      EFFECTIVE_DATE
    , 
      STATUS
    , 
      STATUS_DATE
    , 
      STATUS_REASON
    ) 
      
    VALUES (IDDATA 
      
    ,store 
      
    ,SalesNo 
      
    ,UnitCost 
      
    ,StWac 
      
    ,StDt 
      
    ,St 
      
    ,StartQty 
      
    ,StartValue 
      
    ,StartOnOrder 
      
    ,Hand 
      
    ,Ordered 
      
    ,COMMITED 
      
    ,Sales 
      
    ,Rec 
      
    ,Valued 
      
    ,Id1 
      
    ,Id2 
      
    ,Id3 
      
    ,UnitPrice 
      
    ,to_Date(EffectiveDate||' '||EffectiveTime, 'YYYY-MM-DD HH24:MI:SS') 
      
    ,'N'  
      
    ,SYSDATE 
      
    ,'XML PROCESS INSERT')  
    -- This is to parse and fetch the data from XML 
      
    SELECT E.* FROM XMLTABLE('rp_send/rp_sendRow' PASSING xDATA COLUMNS
      store VARCHAR
    (20) PATH 'store'  
      
    ,SalesNo VARCHAR(20) PATH 'sales' 
      
    ,UnitCost NUMBER PATH 'cost' 
      
    ,StWac VARCHAR(20) PATH 'flag' 
      
    ,StDt DATE PATH 'st-dt' 
      
    ,St NUMBER PATH 'st' 
      
    ,StartQty NUMBER PATH 'qty' 
      
    ,StartValue NUMBER PATH 'value' 
      
    ,StartOnOrder NUMBER PATH 'start-on-order' 
      
    ,Hand NUMBER PATH 'hand' 
      
    ,Ordered NUMBER PATH 'order' 
      
    ,Commited NUMBER PATH 'commit' 
      
    ,Sales NUMBER PATH 'sales' 
      
    ,Rec NUMBER PATH 'rec' 
      
    ,Valued NUMBER PATH 'val' 
      
    ,Id1 VARCHAR(30) PATH 'id-1' 
      
    ,Id2 VARCHAR(30) PATH 'id-2' 
      
    ,Id3 VARCHAR(30) PATH 'id-3' 
      
    ,UnitPrice NUMBER PATH 'unit-pr' 
      
    ,EffectiveDate VARCHAR(30) PATH 'eff-dt' 
      
    ,EffectiveTime VARCHAR(30) PATH 'eff-tm' 
      
    ) E;  
      ROW_COUNT 
    := SQL%ROWCOUNT;  -- Not the # of all the rows inserted.
      PROCESS_STATUS 
    := STATUS.PROCESSED;
      
    IF ROW_COUNT < 1 THEN   -- The insert failed Row Count = 0 No exception thrown
      PROCESS_STATUS 
    := STATUS.ERROR;
      STATUS_DESCRIPTION 
    := 'ERROR Did not insert into Pos Inventory. Reason Unknown';
      
    END IF;
      EXCEPTION
      
    WHEN OTHERS THEN
      ROW_COUNT 
    := 0;
      PROCESS_STATUS 
    := STATUS.ERROR;
      STATUS_DESCRIPTION 
    := 'SqlCode:' || SQLCODE || ' SqlErrMsg:' || SQLERRM;
    END;


    BEGIN
      DBMS_OUTPUT
    .enable(NULL);
     
    FOR A_NewStage IN NewStage
      LOOP
      READ_COUNT
    := READ_COUNT + 1;
      STAGE_TBL_PROCESS
    (A_NewStage.ID, A_NewStage.XML_DOCUMENT, PROCESS_STATUS, STATUS_DESCRIPTION, ROW_COUNT);
      INSERT_COUNT_TOTAL
    := INSERT_COUNT_TOTAL + ROW_COUNT;
      
    IF(ROW_COUNT <= 0 OR PROCESS_STATUS = STATUS.ERROR) THEN
      ERROR_COUNT
    := ERROR_COUNT + 1;
      
    UPDATE STAGE_TBL
      
    SET status  = PROCESS_STATUS,
      status_DATE 
    = SYSDATE,
      status_DESCRIPTION 
    = STATUS_DESCRIPTION
      
    WHERE ID  = A_NewStage.ID;
      
    ELSE
      
    UPDATE STAGE_TBL
      
    SET status  = PROCESS_STATUS,
      status_DATE 
    = SYSDATE,
      status_DESCRIPTION 
    = STATUS_DESCRIPTION,
      SHRED_DT 
    = SYSDATE
      
    WHERE ID  = A_NewStage.ID;
      
    END IF;
      
    COMMIT;
     
    END LOOP;
     
    COMMIT;
     
    IF ERROR_COUNT > 0 THEN
      ERRMSG
    := '** ERROR: ' || ERROR_COUNT || ' Stage records did not insert in to the Processed table correctly';
      RAISE_APPLICATION_ERROR
    (-20001,ErrMsg); 
     
    END IF;
      EXCEPTION
      
    WHEN OTHERS THEN
      RAISE
    ;
    END ;

    My
    XML with just one rp_sendRow element, it can go upto 2000 rp_sendRow elements
    <?xml version = \"1.0\" encoding = \"UTF-8\"?> 
    <rp_send xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"> 
      
    <rp_sendRow> 
      
    <store>0123</store> 
      
    <sales>022399190</sales> 
      
    <cost>0.01</cost> 
      
    <flag>true</flag> 
      
    <st-dt>2013-04-19</st-dt> 
      
    <st>146.51</st> 
      
    <qty>13.0</qty> 
      
    <value>0.0</value> 
      
    <start-on-order>0.0</start-on-order> 
      
    <hand>0.0</hand> 
      
    <order>0.0</order> 
      
    <commit>0.0</commit> 
      
    <sales>0.0</sales> 
      
    <rec>0.0</rec> 
      
    <val>0.0</val> 
      
    <id-1/> 
      
    <id-2/> 
      
    <id-3/> 
      
    <unit-pr>13.0</unit-pr> 
      
    <eff-dt>2015-06-16</eff-dt> 
      
    <eff-tm>09:12:21</eff-tm> 
      
    </rp_sendRow> 
    </rp_send> 

    The issue I see is when I pass an XML object to a procedure (STAGE_TBL_PROCESS) to analyze its takes about 10 seconds per XML, but rather than from XML if I directly pick up table in the procedure (STAGE_TBL_PROCESS) passing the ID to be about 0.15 seconds.

    In version 11.1, Oracle introduced a new model of storage for the data type XMLType called XML binary.

    Binary XML become the default in 11.2.0.2, to disparage the old storage based on CLOB.

    Binary XML is a format optimized after analysis for the storage and treatment of the XQuery.

    When an XQuery expression is evaluated (through for example XMLTABLE) on an XMLType column stored as binary XML, Oracle can use an ongoing evaluation of XPath that surpasses the query even crushed a transitional XMLType of several order of magnitude.

    You can see that in the action plan of the explain command:

    SQL> SELECT E.*
      2  FROM stage_tbl t
      3     , XMLTABLE('rp_send/rp_sendRow' PASSING t.xml_document
      4         COLUMNS store VARCHAR(20) PATH 'store'
      5               , SalesNo VARCHAR(20) PATH 'sales'
      6               , UnitCost NUMBER PATH 'cost'
      7         ) E ;
    
    Execution Plan
    ----------------------------------------------------------
    Plan hash value: 1134903869
    
    --------------------------------------------------------------------------------
    | Id  | Operation          | Name      | Rows  | Bytes | Cost (%CPU)| Time     |
    --------------------------------------------------------------------------------
    |   0 | SELECT STATEMENT   |           |     1 |  2008 |    32   (0)| 00:00:01 |
    |   1 |  NESTED LOOPS      |           |     1 |  2008 |    32   (0)| 00:00:01 |
    |   2 |   TABLE ACCESS FULL| STAGE_TBL |     1 |  2002 |     3   (0)| 00:00:01 |
    |   3 |   XPATH EVALUATION |           |       |       |            |          |
    --------------------------------------------------------------------------------
    

    When the query is executed on a passenger XMLType (for example, a parameter, or a PL/SQL variable), Oracle cannot run the binary model and use a functional assessment based on memory of the XML DOM-like representation.

    You can see that in the plan to explain it by spoting a 'COLLECTION ITERATOR PICKLER FETCH' operation.

    So what explains the difference (in your version) between treatment from a column of XMLType (stored in binary XML format) or a variable or a parameter.

    From 11.2.0.4 and beyond, things have changed a bit with Oracle, introducing a new transitional level of optimization on XMLType.

    The plan of the explain command will show a "XMLTABLE ASSESSMENT' in this case.

  • The Oracle procedure update

    We have two tables.

    1 EMP_STAGE 2. FM3

    Finding the structure for the two tables above.

    EMP_STAGE                                                       EMP

    -----------------                                                       --------

    EMP_ID                                                                 ID

    PAN                                                                       EMP_PAN

    STATUS                                                                STATUS

    LAST_DAY                                                            EMP_FLAG

    END_DATE

    one of our table EMP_STAGE requests get data then the EMP_STAGE of the table data will be loaded into the EMP table.

    I need to write a procedure, based on the results of the table EMP_STAGE table EMPLOYEE should as update.

    1. If the employee is still with the organization that the STATE is 'Active' in the EMP_STAGE table if he resigns or terminated its status should be 'inactive' and LAST_DAY (date format) of data used has also updated in the EMP_STAG table.

    2. during the loading of data into the EMP table based on the data of EMP_STAGE, in the employee table employee STATUS = "ACTIVE/INACTIVE" and end_date = LAST_DAY (from table EMP_STAGE) based on both the EMP_FLAG column updates as EMP_FLAG = (If employee was then 'YES' else 'NO');

    Please give me your opinion on this.

    Thanks for posting the sample data, I'm unable to reproduce your problem. As Hoek said, it is because of duplicates in your data. You can check the link above to understand the issue.

    However, my illustration here is how to do it.

    Suppose that the emp table has only a single folder, if a new employee is in EMP_STAGE table, his information should be added in the transactional table EMP.

    Under scenario

    101 is the new employee, then inserted

    100 is used existing, as well as its details are updated.

    SQL >
    SQL > select * from v version $;

    BANNER
    --------------------------------------------------------------------------------
    Oracle Database 11 g Enterprise Edition Release 11.2.0.2.0 - 64 bit Production
    PL/SQL Release 11.2.0.2.0 - Production
    CORE Production 11.2.0.2.0
    AMT for Linux: Version 11.2.0.2.0 - Production
    NLSRTL Version 11.2.0.2.0 - Production

    SQL >
    SQL > DROP SEQUENCE emp_id_seq;

    Sequence has fallen.

    SQL > DROP TABLE emp;

    Deleted table.

    SQL > DROP TABLE emp_stage;

    Deleted table.

    SQL >
    SQL > CREATE SEQUENCE emp_id_seq
    2. START WITH 1
    MAXVALUE 3 100
    MINVALUE 4 0;

    Order of creation.

    SQL >
    SQL > CREATE TABLE emp
    () 2
    3 IDENTIFICATION NUMBER,
    NUMBER OF EMP_PAN 4.
    5 SITUATION VARCHAR2 (10),
    6 EMP_FLAG VARCHAR2 (1).
    End_date DATE 7
    8  );

    Table created.

    SQL >
    SQL > CREATE TABLE emp_stage
    () 2
    NO. 3,
    4 STATUS VARCHAR2 (10),
    5 LAST_DAY DATE
    6  );

    Table created.

    SQL >
    SQL >
    SQL > INSERT INTO emp
    2. SELECT 1 id,
    3 100 emp_pan,
    4 'active ',.
    5            'Y',
    6 SYSDATE - 1
    7 FROM DUAL;

    1 line of creation.

    SQL >
    SQL > INSERT INTO emp_stage
    2. SELECT 100 pan, 'Active', SYSDATE FROM DUAL;

    1 line of creation.

    SQL >
    SQL > INSERT INTO emp_stage
    2. SELECT pan 101, 'Active', NULL FROM DUAL;

    1 line of creation.

    SQL >
    SQL > MERGE IN emp e
    2 use emp_stage
    3 on (es. PAN = e.emp_PAN)
    4 WHEN MATCHED
    5 THEN
    6 UPDATE SET e.end_date =. LAST_DAY, e.status = es.status
    7 WHEN NOT MATCHED
    8 THEN
    9. INSERT (e.id,
    emp_pan 10,
    11 end_date
    12 status)
    13 VALUES (emp_id_seq. NEXTVAL,
    ES.Pan 14,
    15                 es. LAST_DAY,
    16 es.status);

    2 lines merged.

    SQL > commit;

    validation complete.
    SQL > SELECT * FROM emp;

    ID EMP_PAN STATUS E END_DATE
    ---------- ---------- ---------- - ---------
    1 100 Y active 27 August 13
    2 101 active

    SQL >
    SQL > SELECT * from emp_stage;

    PAN STATUS LAST_DAY
    ---------- ---------- ---------
    100 active 27 August 13
    Active 101

    Thank you

    GPU

  • How to compile procedure Oracle procedure throught ODI

    Hello

    Can someone help me how to compile procedure oracle through ODI11g

    I'm Aguerre, how to call the oracle in ODI procedure and run it.

    Please help me

    Kind regards
    Phanikanth

    Hello

    We can invoke step by odi procedure below.

    modify the procedure compile

    Thank you
    Anuradha

  • How to have an Oracle procedure send and receive the value of a java program.

    The procedure below is the place within a package. This "get_extract_ready_headers" procedure to select the columns store_number, terminal_number, tran_number, tran_date, cust_id in the REX_HEAD_EXTRACT of source table. This information is selected in a ref cursor The data were field cust_id which is encrypted. How can I change the get_extract_ready_headers procedure and accomplish 2 things?

    1. make this procedure the "cust_id" reading the table source and send the value of a Java program "getheaderinfo" (this java program decrypts the cust_id field).
    2. when we get the value unencrypted to the Java program, make the procedure to accept this decrypted value and use it to update the CUST_ID to the table TRAN_HEAD table value target. I use Oracle 11.2.0.2 and TOAD 10.5.1.3.





    -The code of procedure
    PROCEDURE get_extract_ready_headers (p_records OUT SYS_REFCURSOR)
    IS
    BEGIN
       OPEN p_records FOR 
       SELECT store_number, terminal_number, tran_number, tran_date, cust_id FROM REX_HEAD_EXTRACT;
          
    END;
    -Table Structure for the table source REX_HEAD_EXTRACT
    CREATE TABLE REX_HEAD_EXTRACT
    (
      REX_SEQ_NBR         NUMBER(20),
      REVISION_NUMBER         NUMBER,
      DAY                     NUMBER(3),
      RESA_TRAN_SEQ_NO        NUMBER(20),
      BUSINESS_DATE           DATE,
      TRAN_SEQ_NBR            NUMBER(12),
      ORG_NUMBER              NUMBER,
      STORE_NUMBER            NUMBER,
      TRAN_DATE               DATE,
      TERMINAL_NUMBER         NUMBER,
      TRAN_NUMBER             NUMBER,
      TRAN_TIME               DATE,
      BATCH_NUMBER            VARCHAR2(8 BYTE),
      BATCH_TYPE              VARCHAR2(4 BYTE),
      TRAN_TYPE               VARCHAR2(4 BYTE),
      SUB_TRAN_TYPE           VARCHAR2(4 BYTE),
      CLERK_CODE              VARCHAR2(15 BYTE),
      TRAN_TAXABLE_AMOUNT     NUMBER(12,2),
      TRAN_TAX_TOTAL          NUMBER(12,2),
      TRAN_GROSS_TOTAL        NUMBER(12,2),
      COUP_TOTAL              NUMBER(9,2),
      MKD_TOTAL               NUMBER(9,2),
      EMPLOYEE_NUMBER         VARCHAR2(15 BYTE),
      EMPLOYEE_NAME           VARCHAR2(40 BYTE),
      TRAN_ALTTAXABLE_AMOUNT  NUMBER(12,2),
      TRAN_ALTTAX_TOTAL       NUMBER(12,2),
      SALE_AMOUNT             NUMBER(9,2),
      RETURN_AMOUNT           NUMBER(9,2),
      RETURNED_AMOUNT         NUMBER(9,2),
      NETCASH                 NUMBER(12,2),
      TENDER_CODE             VARCHAR2(4 BYTE),
      MULT_RCPT               VARCHAR2(1 BYTE),
      SPLIT_TENDER            VARCHAR2(1 BYTE),
      RTN_WITH_PURCHASE       VARCHAR2(1 BYTE),
      RTN_WITH_RCPT           VARCHAR2(1 BYTE),
      REASON_CODE             VARCHAR2(4 BYTE),
      PASSWORD                VARCHAR2(10 BYTE),
      RINGTIME                DATE,
      CUST_NUMBER             VARCHAR2(12 BYTE),
      CUST_ID                 VARCHAR2(50 BYTE),
      ZIP_CODE                NUMBER,
      POSTAL_CODE             VARCHAR2(9 BYTE),
      PV_TIME_LAPSE           NUMBER,
      ORIG_STORE_NBR          NUMBER,
      ORIG_TRAN_DATE          DATE,
      ORIG_TRAN_TYPE          VARCHAR2(4 BYTE),
      ORIG_TERM_NBR           NUMBER,
      ORIG_TRAN_NBR           NUMBER,
      ORIG_SALE_AMT           NUMBER(12,2),
      ORIG_TENDER_CODE        VARCHAR2(4 BYTE),
      ORIG_CLERK_CODE         VARCHAR2(15 BYTE),
      PREV_TRAN_TYPE          VARCHAR2(4 BYTE),
      PREV_SUB_TRAN_TYPE      VARCHAR2(4 BYTE),
      GIFT_REGISTRY_ID        VARCHAR2(25 BYTE),
      NO_OF_ITEMS             NUMBER,
      TAX_EXEMPT_ID           VARCHAR2(18 BYTE),
      TRAN_RINGTIME           NUMBER,
      AUDITED                 VARCHAR2(1 BYTE),
      BATCH_VERSION           NUMBER(9,2),
      BATCH_SOURCE            VARCHAR2(5 BYTE),
      CREATE_DATE             DATE,
      CREATE_ID               VARCHAR2(32 BYTE),
      CREATE_PROC             VARCHAR2(32 BYTE),
      MOD_DATE                DATE,
      MOD_ID                  VARCHAR2(32 BYTE),
      MOD_PROC                VARCHAR2(32 BYTE),
      TERMINAL_GROUP          NUMBER,
      USER_DEF_1              NUMBER,
      USER_DEF_2              NUMBER,
      USER_DEF_3              NUMBER,
      USER_DEF_4              NUMBER(12,2),
      USER_DEF_5              NUMBER(12,2),
      USER_DEF_6              NUMBER(12,2),
      USER_DEF_7              VARCHAR2(50 BYTE),
      USER_DEF_8              VARCHAR2(50 BYTE),
      USER_DEF_9              VARCHAR2(50 BYTE),
      MANAGER_NUMBER          VARCHAR2(15 BYTE),
      MANAGER_REASON_CODE     VARCHAR2(10 BYTE),
      MANAGER_SWIPED          VARCHAR2(1 BYTE),
      PHONE_NO                NUMBER(11),
      KCPOS_KTH_USER_101      NUMBER,
      KCPOS_KTH_USER_102      NUMBER,
      KCPOS_KTH_USER_103      NUMBER,
      KCPOS_KTH_USER_104      NUMBER,
      KCPOS_KTH_USER_105      NUMBER,
      KCPOS_KTH_USER_106      NUMBER,
      KCPOS_KTH_USER_107      NUMBER,
      KCPOS_KTH_USER_108      NUMBER,
      KCPOS_KTH_USER_109      NUMBER,
      KCPOS_KTH_USER_110      NUMBER,
      KCPOS_KTH_USER_201      NUMBER(12,2),
      KCPOS_KTH_USER_202      NUMBER(12,2),
      KCPOS_KTH_USER_203      NUMBER(12,2),
      KCPOS_KTH_USER_204      NUMBER(12,2),
      KCPOS_KTH_USER_205      NUMBER(12,2),
      KCPOS_KTH_USER_206      NUMBER(12,2),
      KCPOS_KTH_USER_207      NUMBER(12,2),
      KCPOS_KTH_USER_208      NUMBER(12,2),
      KCPOS_KTH_USER_209      NUMBER(12,2),
      KCPOS_KTH_USER_210      NUMBER(12,2),
      KCPOS_KTH_USER_301      VARCHAR2(50 BYTE),
      KCPOS_KTH_USER_302      VARCHAR2(50 BYTE),
      KCPOS_KTH_USER_303      VARCHAR2(50 BYTE),
      KCPOS_KTH_USER_304      VARCHAR2(50 BYTE),
      KCPOS_KTH_USER_305      VARCHAR2(50 BYTE),
      KCPOS_KTH_USER_306      VARCHAR2(50 BYTE),
      KCPOS_KTH_USER_307      VARCHAR2(50 BYTE),
      KCPOS_KTH_USER_308      VARCHAR2(50 BYTE),
      KCPOS_KTH_USER_309      VARCHAR2(50 BYTE),
      KCPOS_KTH_USER_310      VARCHAR2(50 BYTE),
      KCPOS_KTH_USER_401      DATE,
      KCPOS_KTH_USER_402      DATE,
      KCPOS_KTH_USER_403      DATE,
      DISC_TOTAL              NUMBER(9,2)
    )
    
    CREATE INDEX REX_HEAD_EXTRACT_NDX ON REX_HEAD_EXTRACT
    (REX_SEQ_NBR, REVISION_NUMBER, STORE_NUMBER, TRAN_DATE, TERMINAL_NUMBER, TRAN_NUMBER)
    -Create table DDL for the target TRAN_HEAD table
    CREATE TABLE NAVISTOR.KCPOS_TRAN_HEADER_BASE
    (
      TRAN_SEQ_NBR            NUMBER(12),
      ORG_NUMBER              NUMBER,
      STORE_NUMBER            NUMBER,
      TRAN_DATE               DATE,
      TERMINAL_NUMBER         NUMBER,
      TRAN_NUMBER             NUMBER,
      TRAN_TIME               DATE,
      BATCH_NUMBER            VARCHAR2(8 BYTE),
      BATCH_TYPE              VARCHAR2(4 BYTE),
      TRAN_TYPE               VARCHAR2(4 BYTE),
      SUB_TRAN_TYPE           VARCHAR2(4 BYTE),
      CLERK_CODE              VARCHAR2(15 BYTE)     NOT NULL,
      TRAN_TAXABLE_AMOUNT     NUMBER(12,2),
      TRAN_TAX_TOTAL          NUMBER(12,2),
      TRAN_GROSS_TOTAL        NUMBER(12,2),
      COUP_TOTAL              NUMBER(9,2),
      MKD_TOTAL               NUMBER(9,2),
      EMPLOYEE_NUMBER         VARCHAR2(15 BYTE),
      EMPLOYEE_NAME           VARCHAR2(40 BYTE),
      TRAN_ALTTAXABLE_AMOUNT  NUMBER(12,2),
      TRAN_ALTTAX_TOTAL       NUMBER(12,2),
      SALE_AMOUNT             NUMBER(9,2),
      RETURN_AMOUNT           NUMBER(9,2),
      RETURNED_AMOUNT         NUMBER(9,2),
      NETCASH                 NUMBER(12,2),
      TENDER_CODE             VARCHAR2(4 BYTE),
      MULT_RCPT               VARCHAR2(1 BYTE),
      SPLIT_TENDER            VARCHAR2(1 BYTE),
      RTN_WITH_PURCHASE       VARCHAR2(1 BYTE),
      RTN_WITH_RCPT           VARCHAR2(1 BYTE),
      REASON_CODE             VARCHAR2(4 BYTE),
      PASSWORD                VARCHAR2(10 BYTE),
      RINGTIME                DATE,
      CUST_NUMBER             VARCHAR2(12 BYTE),
      CUST_ID                 VARCHAR2(50 BYTE) ENCRYPT USING 'AES256' NO SALT,
      ZIP_CODE                NUMBER,
      POSTAL_CODE             VARCHAR2(9 BYTE),
      PV_TIME_LAPSE           NUMBER,
      ORIG_STORE_NBR          NUMBER,
      ORIG_TRAN_DATE          DATE,
      ORIG_TRAN_TYPE          VARCHAR2(4 BYTE),
      ORIG_TERM_NBR           NUMBER,
      ORIG_TRAN_NBR           NUMBER,
      ORIG_SALE_AMT           NUMBER(12,2),
      ORIG_TENDER_CODE        VARCHAR2(4 BYTE),
      ORIG_CLERK_CODE         VARCHAR2(15 BYTE),
      PREV_TRAN_TYPE          VARCHAR2(4 BYTE),
      PREV_SUB_TRAN_TYPE      VARCHAR2(4 BYTE),
      GIFT_REGISTRY_ID        VARCHAR2(25 BYTE),
      NO_OF_ITEMS             NUMBER,
      TAX_EXEMPT_ID           VARCHAR2(18 BYTE),
      TRAN_RINGTIME           NUMBER,
      AUDITED                 VARCHAR2(1 BYTE),
      BATCH_VERSION           NUMBER(9,2),
      BATCH_SOURCE            VARCHAR2(5 BYTE),
      CREATE_DATE             DATE,
      CREATE_ID               VARCHAR2(32 BYTE),
      CREATE_PROC             VARCHAR2(32 BYTE),
      MOD_DATE                DATE,
      MOD_ID                  VARCHAR2(32 BYTE),
      MOD_PROC                VARCHAR2(32 BYTE),
      TERMINAL_GROUP          NUMBER,
      USER_DEF_1              NUMBER,
      USER_DEF_2              NUMBER,
      USER_DEF_3              NUMBER,
      USER_DEF_4              NUMBER(12,2),
      USER_DEF_5              NUMBER(12,2),
      USER_DEF_6              NUMBER(12,2),
      USER_DEF_7              VARCHAR2(50 BYTE),
      USER_DEF_8              VARCHAR2(50 BYTE),
      USER_DEF_9              VARCHAR2(50 BYTE),
      MANAGER_NUMBER          VARCHAR2(15 BYTE),
      MANAGER_REASON_CODE     VARCHAR2(10 BYTE),
      MANAGER_SWIPED          VARCHAR2(1 BYTE),
      PHONE_NO                NUMBER(11),
      KCPOS_KTH_USER_101      NUMBER,
      KCPOS_KTH_USER_102      NUMBER,
      KCPOS_KTH_USER_103      NUMBER,
      KCPOS_KTH_USER_104      NUMBER,
      KCPOS_KTH_USER_105      NUMBER,
      KCPOS_KTH_USER_106      NUMBER,
      KCPOS_KTH_USER_107      NUMBER,
      KCPOS_KTH_USER_108      NUMBER,
      KCPOS_KTH_USER_109      NUMBER,
      KCPOS_KTH_USER_110      NUMBER,
      KCPOS_KTH_USER_201      NUMBER(12,2),
      KCPOS_KTH_USER_202      NUMBER(12,2),
      KCPOS_KTH_USER_203      NUMBER(12,2),
      KCPOS_KTH_USER_204      NUMBER(12,2),
      KCPOS_KTH_USER_205      NUMBER(12,2),
      KCPOS_KTH_USER_206      NUMBER(12,2),
      KCPOS_KTH_USER_207      NUMBER(12,2),
      KCPOS_KTH_USER_208      NUMBER(12,2),
      KCPOS_KTH_USER_209      NUMBER(12,2),
      KCPOS_KTH_USER_210      NUMBER(12,2),
      KCPOS_KTH_USER_301      VARCHAR2(50 BYTE),
      KCPOS_KTH_USER_302      VARCHAR2(50 BYTE),
      KCPOS_KTH_USER_303      VARCHAR2(50 BYTE),
      KCPOS_KTH_USER_304      VARCHAR2(50 BYTE),
      KCPOS_KTH_USER_305      VARCHAR2(50 BYTE),
      KCPOS_KTH_USER_306      VARCHAR2(50 BYTE),
      KCPOS_KTH_USER_307      VARCHAR2(50 BYTE),
      KCPOS_KTH_USER_308      VARCHAR2(50 BYTE),
      KCPOS_KTH_USER_309      VARCHAR2(50 BYTE),
      KCPOS_KTH_USER_310      VARCHAR2(50 BYTE),
      KCPOS_KTH_USER_401      DATE,
      KCPOS_KTH_USER_402      DATE,
      KCPOS_KTH_USER_403      DATE,
      DISC_TOTAL              NUMBER(9,2),
      RTA_RTN_AUTCOD          VARCHAR2(4 BYTE),
      RTA_RTN_COMMID          NUMBER,
      RTA_RTN_EVNTID          NUMBER,
      RTA_RTN_QTY             NUMBER,
      RTA_RTN_RCPT_SCAN       VARCHAR2(1 BYTE),
      RTA_RTN_REFUND_AMT      NUMBER(9,2),
      RTA_RTN_TYPE_CODE       VARCHAR2(4 BYTE),
      RTA_RTN_WITH_RCPT       VARCHAR2(1 BYTE),
      RTA_RTN_COUNT           INTEGER,
      SDEDVAL1                VARCHAR2(50 BYTE)
    )
    -Samples
    REX_SEQ_NBR,REVISION_NUMBER,DAY,RESA_TRAN_SEQ_NO,BUSINESS_DATE,TRAN_SEQ_NBR,ORG_NUMBER,STORE_NUMBER,TRAN_DATE,TERMINAL_NUMBER,
    TRAN_NUMBER,TRAN_TIME
    478,1,11,12024005,6/11/2012,,1,692,6/11/2012,155,5,6/11/2012 12:57:17 PM,
    479,1,11,12024006,6/11/2012,,1,692,6/11/2012,155,6,6/11/2012 2:01:51 PM,
    480,1,11,12024007,6/11/2012,,1,692,6/11/2012,155,7,6/11/2012 2:47:10 PM

    Then you describe two stored procedures separated. One that has an OUTPUT parameter which is a SYS_REFCURSOR (that you posted initially). And will need you a second procedure that takes as a parameter IN the decrypted CUST_ID and whatever: key (s) is required for the UPDATE is generated.

    Justin

  • Oracle procedure-[wrong number or type

    can someone help me identify what Miss me here. I get the error when I run following the procedure below. I work with oracle 11g. Thank you
    [Error] PLS-00306 (43:15): PLS-00306: wrong number or types of arguments I
    CREATE TYPE string_state_table AS TABLE OF varchar2(100); 
    
    CREATE OR REPLACE PROCEDURE dbevendors1e (
       p_state                 IN     string_state_table,
       P_BUSINESSDESCRIPTION   IN     VARCHAR2,
       p_results                  OUT SYS_REFCURSOR)
    IS
       v_sql_text   VARCHAR2 (4000) := NULL;
    BEGIN
       v_sql_text :=
          'SELECT DISTINCT v.refvendor_id vendorId,
                    v.vendorname legalname,
                    v.CERTIFICATIONTYPE,
                    v.vendorshortname doingbusinessname,
                    s.naics_id naicscode,
                    (r.addressline1 ||'' ''|| r.addressline2) address,
                    r.city city,
                    o.gender gender,
                    o.officername officer,
                    v.ethnicgroup ethinic,
                    r.state state,
                    TRIM (INITCAP (g.vnlst1)) businessdesc,
                    r.zipcode zipcode,
                    r.telephonenum phone,
                    r.faxnum fax,
                    LOWER (r.email) email,
                    LOWER (v.website) website,
                    v.dbecertstatus status,
                    func_get_naics_desc (s.naics_id) naicscodedesc,
                    func_get_state_desc (r.state) statename
                                                                  
      FROM refvendor v,
           refvendor_gf g,
           refvendoraddress r,
           refvendornaics s,
           refvendorofficer o
           
     WHERE     (v.refvendor_id = r.refvendor_id)
           AND v.refvendor_id = s.refvendor_id
           AND v.refvendor_id = r.refvendor_id
           AND v.refvendor_id = o.refvendor_id(+)
           AND v.refvendor_id = g.refvendor_id(+)';
    
       IF p_state = '0' ---------------------this is where the error is
       THEN
          v_sql_text :=
                v_sql_text
             || 'AND R.STATE  IN  (SELECT COLUMN_VALUE FROM TABLE ('
             || p_state
             || ')) ';
       END IF;
    
       IF P_BUSINESSDESCRIPTION != 'ALL'
       THEN
          --v_sql_text := v_sql_text || 'AND TRIM (g.vnlst1) LIKE  % (' || P_BUSINESSDESCRIPTION  || ')';
          v_sql_text :=
                v_sql_text
             || 'AND TRIM (g.vnlst1) LIKE  '
             || ''''
             || '%'
             || P_BUSINESSDESCRIPTION
             || '''';
       END IF;
    
       v_sql_text :=
          v_sql_text
          || '  AND UPPER(v.CERTIFICATIONTYPE)=''DBE''  order by vendorId ';
    
       -- dbms_output.put_line(v_sql_text);
       OPEN p_results FOR v_sql_text;
    END;
    /

    Do not code like this a lot - difficult to read and understand. What makes it difficult to find bugs and difficult to maintain.

    The comparison is-string-in-set can be made by using a submultiset condition. Bed easier IMO. (remember to consult the execution plan so that these methods can do for execution of cursor and performance)

    The key however, is bind variable. It is a little one non-negotiable. Bind variables are essential for performance - reduce CPU overhead. It is also essential for effective use of the SQL Shared Pool (and not causing the fragmentation of memory and leading to the error of memory allocation for new SQLs).

    I wrote the following example of procedure - showing the basic approach that I would use for a problem like this.

    SQL> create or replace type TStrings as table of varchar2(4000);
      2  /
    
    Type created.
    
    SQL>
    SQL> create or replace procedure GetObjectsByType(
      2          c IN OUT sys_refcursor,                 -- cursor returned to caller for fetching rows
      3          objectTypes TStrings,                   -- list of object types to fetch (mandatory)
      4          objectOwner varchar2 default null       -- owner of the object (optional)
      5  ) is
      6          curSql  varchar2(32767);
      7  begin
      8          curSql :=
      9                  'select
     10                          object_name, object_type
     11                  from    all_objects
     12                  where   TStrings(object_type) submultiset of :0';
     13
     14          if objectOwner is not null then
     15                  curSql := curSql || ' and owner = :1';
     16          else
     17                  curSql := curSql || ' and owner = USER';
     18          end if;
     19
     20          -- how many bind parameters?
     21          case
     22                  when (instr(curSql,':0') > 0) and  (instr(curSql,':1') > 1) then
     23                          open c for curSql
     24                          using objectTypes, objectOwner;
     25
     26                  when (instr(curSql,':0') > 0) then
     27                          open c for curSql
     28                          using objectTypes;
     29          end case;
     30  end;
     31  /
    
    Procedure created.
    
    SQL>
    SQL> var c refcursor
    SQL> exec GetObjectsByType( :c, TStrings('TABLE','PROCEDURE') )
    
    PL/SQL procedure successfully completed.
    
    SQL> print c
    
    OBJECT_NAME                    OBJECT_TYPE
    ------------------------------ ------------------------------
    FOOTAB                         TABLE
    TESTTAB                        TABLE
    PROCB                          PROCEDURE
    PROCA                          PROCEDURE
    GETOBJECTSBYTYPE               PROCEDURE
    
    SQL>
    SQL> exec GetObjectsByType( :c, TStrings('EDITION','JOB CLASS'), 'SYS' )
    
    PL/SQL procedure successfully completed.
    
    SQL> print c
    
    OBJECT_NAME                    OBJECT_TYPE
    ------------------------------ ------------------------------
    ORA$BASE                       EDITION
    DEFAULT_JOB_CLASS              JOB CLASS
    DBMS_JOB$                      JOB CLASS
    

    If the dynamic part of the SQL is more dynamic in this example, I would use DBMS_SQL creates the cursor and bind the list dynamic of the bind variable. It's quite simple to do.

    With 11g one can change a reference cursor DBMS_SQL (number) in a handful of refcursor PL/SQL. Which means that after you create the cursor DBMS_SQL , the code can cast/convert that to a refcursor and move this refcursor to the appellant.

    The stakes are the use of bind variables and make the code (in spite of dynamic linking) easy to read and understand. Code that fall into this category has fewer bugs, easier to debug and much easier to maintain and modify. It must be so always try and keep things simple - while respecting the fundamental principles (such as bind variables).

  • Backup in Oracle procedures

    I'm trying to backup procedures for a number of research platforms and software and I was wondering if someone could help with the Oracle database with the following text:

    • For backups of Oracle databases, which is the default tool or utility that is used to back up the Oracle database and Oracle backup what file extension will have when the backup is created? Also, is there a default folder that will be written the backup too if the use of default tools?

    • Is more typical, an Oracle database will be saved using the default backup utilities in Oracle or do most people use a 3rd third party tool?

    • Too far do you go with backups of databases? You back up the database to another drive, then the backup to the backup media, once again? Extent to which channel are you going?

    • How do you feel about the use of backup utilities system including databases oracle on system within the backup volumes is common or it is essential to have a specific to the Oracle database backup procedure?

    • What audit connects or trails will be available to demonstrate to management or the Board of Auditors that the backup was performed in accordance with departmental policies? Where is this file and how much detail does show when you use the default oracle utilities?

    • As Oracle DBA are there any particular reasons why backups cannot be run on a specific day, that evening, if so could you give some details on what types of occurrence will prevent to be logical to run the backup that night? For example, if you saw, that she has been saved 6 days out of 7, why for the 7th day would be reasonable, as appropriate.

    Would prefer your comments and input as opposed to a load of links that the links I've read to date are not compatible.

    user599292 wrote:
    But the most popular / typical of utlitity used worldwide Oracle RMAN backup database? Are there other popular alternatives or is it used RMAN one more folk to backup Oracle databases?

    There is a very good thing that you should not forget. All that you can choose to use, if it is not supported by oracle, its of no use at all. And RMAN is the tool supported by oracle for making backups and recoveries. Another thing, is your own responsibility. In addition to RMAN, BCV backup are also very popular.

    The repository that you mention, which will provide us with 3 weeks backup days a, b, c but not d and z?

    Please excuse my ignorance, but I'm new on this.

    Please see th link mentioned by Centinul and read the books mentioned. It has tons of info.

    Aman...

  • How to run a database as oracle procedure

    Hello
    I created a database procedure, execute successfully alongside server, but I need to turn on the shape of the oracle, how do I do?
    Thank you
    Baldwin

    You only

    Just write the name of the procedure in the procedure or trigger or function.

  • Number of declaration in the oracle procedure

    Hi guys,.

    SELECT col1_name IN the host_name FROM tbl_name WHERE col2_name = 'XXX ';

    DECLARE

    l_url VARCHAR2 (256): = ' host_name? XXXX & xxxxx & xxxx';

    l_http_request UTL_HTTP.req;

    l_http_response UTL_HTTP.resp;

    BEGIN

    l_http_request: = UTL_HTTP.begin_request (l_url);

    l_http_response: = UTL_HTTP.get_response (l_http_request);

    Utl_http.end_response (l_http_response);

    END;

    Above is the my code. I am trying to set the value of col1_name in the host_name and call host_name in the query string. But iam unable to send the request such that it does not touch the host machine.

    value of HOST_NAME is already added inside the table_name.

    Help, please.

    Correct code

    DECLARE

    l_url VARCHAR2 (256);

    l_http_request UTL_HTTP.req;

    l_http_response UTL_HTTP.resp;

    BEGIN

    SELECT col1_name INTO host_name

    FROM col2_name WHERE table_name = 'XXX ';

    l_url: = host_name |'? xxxx xxxxx & &xxxx';

    l_http_request: = UTL_HTTP.begin_request (l_url);

    l_http_response: = UTL_HTTP.get_response (l_http_request);

    Utl_http.end_response (l_http_response);

    END;

    Obviously the SELECT statement must be IN a BEGIN END block, is not outside of the

    and you need concatenate the variable with the string hard-coded.

    -------------------

    Sybrand Bakker

    Senior Oracle DBA

Maybe you are looking for