Sleep Function in PL/SQL

Hi Guys,
I am creating a procedure which will check for the fileld in the database and if it returns NULL should go to sleep for 15 minutes and then will again check for the field. I am planning to use DBMS_LOCK.SLEEP function. Please can you suggest if the same is fine or advise if in case there is any other specific function which I require to use as I have read that the mentioned function is not accurate in calculating the SLEEP time.
[http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:6019886867656]
Best Regards,
Shaz

Summary of DBMS_LOCK Subprograms
Table 53-3 DBMS_LOCK Package Subprograms
Subprogram Description
ALLOCATE_UNIQUE Procedure
Allocates a unique lock ID to a named lock.
CONVERT Function
Converts a lock from one mode to another.
RELEASE Function
Releases a lock.
REQUEST Function
Requests a lock of a specific mode.
SLEEP Procedure
Puts a procedure to sleep for a specific time.
PL/SQL lock timer
Definition: This Wait-Event represents the amount of time a user or application has “slept” through the USER_LOCK.SLEEP or DBMS_LOCK.SLEEP procedures.
When investigating Oracle Wait-Events, the lion's share of time is spent looking at those events where applications consume precious system resources or are in direct contention with other users or applications. These resource waits revolve around excessive CPU, memory, or disk usage. Events that spin for Oracle internal structures such as latches or enqueues can also be of concern. As their name suggests, Wait-Events DO ‘wait’ on some event to complete before a user or application can continue with its work. Contention for system resources will overwhelm Oracle’s ability to immediately process the SQL and ultimately cause applications to accumulate time in resource specific Wait-Events.
On the flip-side of resource waits there are what are called idle events. These events do not wait for any specific resource but record the time Oracle is waiting for a work request from the application. Many practitioners of Oracle performance will not even look at these idle events because they do not consume resources and are not limiting what Oracle can do at any given point in time. Some will even go so far as to state that the idle events have no meaningful information. This is not necessarily true. Take for instance the idle event ‘SQL*Net message from client’. This idle event is not inhibiting the database server from performing work but, as many agree, is an indication of poor response from client to database server. While idle events are not the result of direct resource contention, they are an accurate measure of accumulated delays in the application imposed by Oracle.
The ‘idle’ event “PL/SQL lock timer” is worth watching because it points us in the direction of application response, throughput, and possible coding issues. The PL/SQL lock timer event is, as the command that issues it states, a sleep mandated by the application code. The application is idle and doing nothing. This means that if the application sleeps for a combined interval of 5 minutes, the response to the user or complete run of the application will take at least 5 minutes longer.
While this event does not require resources and thus is not an Oracle resource contention issue, it is our job to provide the quickest response to users and push applications through our system to increase the user’s perceived performance.
Most often, sleeps are put into an application for serialization of transactional events or spinning on queues until something happens. When the event occurs or a queue is populated, then the application continues its work. We should ask ourselves why an application is sleeping for any amount of time and provide alternatives if necessary to reduce this idle event. You will gain quicker responses if you trigger an action instead of the action waiting for an event.
How to look at the PL/SQL lock timer event
To initiate a sleep for the current session for five seconds.
SQL> execute sys.dbms_lock.sleep(5);
To take a look at current sessions that are using the SLEEP command. Notice that the column P1 in V$SESSION does not represent the amount of time the session has slept but in fact represents the duration this session will sleep. Also note that this column is in centiseconds and as such the five seconds issued for a sleep has been translated in to 500 centiseconds.
SQL> select osuser,event,p1 from v$session where event = 'PL/SQL lock timer'
OSUSER EVENT P1
Johnny Smith PL/SQL lock timer 500

Similar Messages

  • Need help in using sleep function in pl/sql

    Hi,
    need help:
    I have a condition where i want to validate total_pass=total_fail and
    I want to use the sleep function in a pl/sql where i want to wait for 2 minutes ie.checking
    whether total_pass=total_fail based upon class_id .
    I have the data in the table as:
    CLASS_ID TOT_PASS TOT_FAIL
    1 10 10
    2 5 4
    3 6 6
    4 7 5
    Any help will be needful for me

    I'm not quite sure what you are lookg for here, but whatever it is, your code as posted won't do it. You will never break out of the WHILE r_Class.Tot_Pass = r_Class.Tot_Fail loop, since these values will never change because you never get the next record form the cursor.
    From your original data, it looks like your cursor will return multiple rows which implies to me that you want to fetch the first row from the cursor, check if tot_pass = tot_fail, if they are equal, sleep for two minutes then get the next row. This does not make sense to me. Once the select in the cursor is executed, the data it returns will not change due to Oracle's read consistency model, so there seems to me no point in the sleep.
    The other alternative I can see is that you want to check all the returned rows, and if tot_pass = tot_fail for one of the rows (or possibly for all of the rows), then you want to sleep and try again.
    If you can explain in words what it is you are trying to accomplish, someone will be able to point you to a solution.
    John

  • Sleep function

    Hi,
    I have used sleep function in my pl/sql code. I have written the code as below:
    create or replace package ab is
    procedure def ;
    PROCEDURE TEST_SLEEP(TIME1 NUMBER);
    end ab;
    create or replace package body ab is
    PROCEDURE TEST_SLEEP
    TIME1 IN NUMBER
    ) IS
    BEGIN
    DBMS_LOCK.sleep(TIME1);
    END TEST_SLEEP;
    procedure def is
    begin
    for i in 1 .. 5 loop
    if i=5 then
    TEST_SLEEP(i);
    DBMS_OUTPUT.PUT_LINE(I);
    end if;
    if i=1 then
    TEST_SLEEP(i);
    DBMS_OUTPUT.PUT_LINE(I);
    end if;
    if i=3 then
    TEST_SLEEP(i);
    DBMS_OUTPUT.PUT_LINE(I);
    end if;
    if i=4 then
    TEST_SLEEP(i);
    DBMS_OUTPUT.PUT_LINE(I);
    end if;
    end loop;
    end def;
    end ab;
    and every time iam calling that procedure to sleep for some time and display the output through def procedure. But in this the output is displaying for all conditions at the end of execution.
    any one help me please.
    Regards,
    Bharat G.

    starter wrote:
    ya we can recode it to simplify the code. But my requirement is to print the output that shows the time difference of an execution. That does not mean that one can now forget about simplifying the code. The art of programming is to achieve the requirements with as few lines of code as possible. Simplicity is the ultimate form of elegance.
    At the end of procedure execution the output is displaying normally, but i want the output to display everytime it satisfies the condition. By this I can see that its delaying the execution everytime when it enters into the conditional statements.Do not really understand what the requirement is that you describe. Keep in mind that PL/SQL code is server-side code. It run inside a server process.
    So the client makes a PL/SQL: begin MyPackage.FooProc( :var1 ); end;
    This is received by the server. Is parsed. Is executed. And the COMPLETE call is executed. Including all DBMS_OUTPUT calls.
    The call is completed. The client gets the response code that says it was successful.
    The client now makes another call - it requests the DBMS_OUTPUT buffer from the session. It receives the contents from the server and renders it.
    DBMS_OUTPUT is NOT an interactive display device. It does NOT write to the client display.

  • Since I installed Lion on my macbook the LED light does not pulse when I close the screen - the sleep function does not work.

    Since I installed Lion on my macbook the LED light does not pulse when I close the screen - the sleep function does not work neither when chosen after pressing the button nor chosen in the apple menu..

    I have had the same problem but on another forum it was suggested that disabling internet sharing would solve this. This fix seems to work on my machine - why it works I do not understand

  • How to write procedure or function or any sql statement for requirement

    Hi,
    i have a table named letter,it contains 2 columns named as letter_id and letter_content.
    select * from letter;
    letter_id letter_content
    103 Dear MFR
    103 This is in regards to the attached DM List
    103 Please Credit us after reviewing it.
    103 Thanks
    103 Regards
    103 xxxx
    108 Dear customer
    108 This is to inform that ur DM List is as follows
    108 Credit us according to the Dm after reviewing it.
    108 Thanks
    108 Regards
    108 xxxx
    now my requirement is,i need send a parameter as letter_id to a procedure or function in pl/sql in oracle,the output should be as follows:
    if we will pass parameter(letter_id) = 103 then it displays as follows:
    Dear MFR
    This is in regards to the attached DM List.Please Credit us after reviewing it.
    Thanks
    Regards,
    XXXXX.
    if we will pass parameter(letter_id) = 108 then it should displays as follows:
    Dear customer,
    This is to inform that ur DM List is as follows. Credit us according to the Dm after reviewing it.
    Thanks
    Regards,
    XXXXX.
    ---------------------------------------------------------------------------------------------------------

    i am really appriciate ur help.
    thank u so much for ur suggestions.
    when i am uning line_seq its giving an error
    ORA-00904: "LINE_SEQ": invalid identifier
    so,in my table i had created a sequense named content_seq.
    select * from letter;
    content_seq letter_id letter_content
    1 103 Dear MFR
    2 103 This is in regards to the attached DM List
    3 103 Please Credit us after reviewing it.
    4 103 Thanks
    5 103 Regards
    6 103 xxxx
    7 108 Dear customer
    8 108 This is to inform that ur DM List is as follows
    9 108 Credit us according to the Dm after reviewing it.
    10 108 Thanks
    11 108 Regards
    12 108 xxxx
    then i had used ur code as follows:
    select linefrom ( select content_seq , letter_content || case content_seq when 2 then ' ' || lead(letter_content) over (partition by letter_id order by content_seq) end as line from letter where letter_id = 103 )where content_seq <> 3;
    LETTER_CONTENT
    Dear MFR
    this is in regards to the attached DM List Please credit us after reviewing it
    thanks
    Regards
    EXP
    but when i take letter_id = 108 the format is comming different.it was unable to combine 2lines.
    Message was edited by:
    user579585
    Message was edited by:
    user579585

  • PL/SQL function body returning SQL - report error:ORA-01403: no data found

    Hi,
    I am working on Application Express 4.0.2.00.06, and 11G database.
    I have a problem with classic report area of type - PL/SQL function body returning SQL query. Query works if I define region area as - Use Generic Column Names (parse query at runtime only), and does not when I define it - Use Query-Specific Column Names and Validate Query.
    I am getting error:
    report error:ORA-01403: no data found
    This is my query that is returned from function, and displayed with htp.p, and it works ok and returns data in SQL Developer and SQL Workshop (in Apex).
    <code>
    /* select 1 from dual */ SELECT SIFPRO, NAZIV, VODITELJ, DATPZA,SUM(DECODE(TJEDAN,'2010/46',BRDJEL,null)) as "2010/46" ,SUM(DECODE(TJEDAN,'2010/49',BRDJEL,null)) as "2010/49" ,SUM(DECODE(TJEDAN,'2010/50',BRDJEL,null)) as "2010/50" ,SUM(DECODE(TJEDAN,'2010/51',BRDJEL,null)) as "2010/51" ,SUM(DECODE(TJEDAN,'2010/52',BRDJEL,null)) as "2010/52" ,SUM(DECODE(TJEDAN,'2011/01',BRDJEL,null)) as "2011/01" ,SUM(DECODE(TJEDAN,'2011/02',BRDJEL,null)) as "2011/02" ,SUM(DECODE(TJEDAN,'2011/03',BRDJEL,null)) as "2011/03" ,SUM(DECODE(TJEDAN,'2011/04',BRDJEL,null)) as "2011/04" ,SUM(DECODE(TJEDAN,'2011/05',BRDJEL,null)) as "2011/05" ,SUM(DECODE(TJEDAN,'2011/06',BRDJEL,null)) as "2011/06" ,SUM(DECODE(TJEDAN,'2011/07',BRDJEL,null)) as "2011/07" ,SUM(DECODE(TJEDAN,'2011/08',BRDJEL,null)) as "2011/08" ,SUM(DECODE(TJEDAN,'2011/09',BRDJEL,null)) as "2011/09" ,SUM(DECODE(TJEDAN,'2011/10',BRDJEL,null)) as "2011/10" FROM (SELECT * FROM PMV_PLAN_TVRTKA) GROUP BY SIFPRO, NAZIV, VODITELJ, DATPZA ORDER BY SIFPRO, NAZIV, VODITELJ, DATPZA
    </code>
    As you can see, I even tried with workaround that I found on the previous post on the forum, and that is to put /* select 1 from dual */ to start query.
    Any help would be appriciated.

    /* select 1 from dual */ SELECT SIFPRO, NAZIV, VODITELJ, DATPZA,SUM(DECODE(TJEDAN,'2010/46',BRDJEL,null)) as "2010/46" ,SUM(DECODE(TJEDAN,'2010/49',BRDJEL,null)) as "2010/49" ,SUM(DECODE(TJEDAN,'2010/50',BRDJEL,null)) as "2010/50" ,SUM(DECODE(TJEDAN,'2010/51',BRDJEL,null)) as "2010/51" ,SUM(DECODE(TJEDAN,'2010/52',BRDJEL,null)) as "2010/52" ,SUM(DECODE(TJEDAN,'2011/01',BRDJEL,null)) as "2011/01" ,SUM(DECODE(TJEDAN,'2011/02',BRDJEL,null)) as "2011/02" ,SUM(DECODE(TJEDAN,'2011/03',BRDJEL,null)) as "2011/03" ,SUM(DECODE(TJEDAN,'2011/04',BRDJEL,null)) as "2011/04" ,SUM(DECODE(TJEDAN,'2011/05',BRDJEL,null)) as "2011/05" ,SUM(DECODE(TJEDAN,'2011/06',BRDJEL,null)) as "2011/06" ,SUM(DECODE(TJEDAN,'2011/07',BRDJEL,null)) as "2011/07" ,SUM(DECODE(TJEDAN,'2011/08',BRDJEL,null)) as "2011/08" ,SUM(DECODE(TJEDAN,'2011/09',BRDJEL,null)) as "2011/09" ,SUM(DECODE(TJEDAN,'2011/10',BRDJEL,null)) as "2011/10" FROM (SELECT * FROM PMV_PLAN_TVRTKA) GROUP BY SIFPRO, NAZIV, VODITELJ, DATPZA ORDER BY SIFPRO, NAZIV, VODITELJ, DATPZA

  • PL/SQL function body returning SQL query - ORA-06502: PL/SQL: numeric or value error

    I'm attempting to dynamically generate a rather large SQL query via the "PL/SQL function body returning SQL query" report region option.  The SQL query generated will possibly be over 32K.  When I execute my page, I sometimes receive the "ORA-06502: PL/SQL: numeric or value error" which points to a larger than 32K query that was generated.  I've seen other posts in the forum related to this dynamic SQL size limitation issue, but they are older (pre-2010) and point to the 32K limit of the DNS (EXECUTE IMMEDIATE) and DBMS_SQL.  I found this post (dynamic sql enhancements in 11g) which discusses 11g no longer having the 32K size limitation for generating dynamic SQL.  Our environment is on 11gR2 and using ApEx 4.2.1.  I do not know which dynamic SQL method -- DNS or DBMS_SQL -- ApEx 4.2.1 is using.  Can someone clarify for me which dynamic SQL method ApEx uses to implement the "PL/SQL function body returning SQL query" option?
    As a test, I created a page on apex.oracle.com with a report region with the following source:
    declare
      l_stub varchar2(25) := 'select * from sys.dual ';
      l_sql  clob := l_stub || 'union all ';
      br     number(3) := 33;
    begin
      while length ( l_sql ) < 34000 loop
        l_sql := l_sql || l_stub || 'union all ';
      end loop;
      l_sql := l_sql || l_stub;
      for i in 1 .. ceil ( length ( l_sql ) / br ) loop
        dbms_output.put_line ( dbms_lob.substr ( l_sql, br, ( ( i - 1 ) * br ) + 1 ) );
      end loop;
      return l_sql;
    end;
    The dbms_output section is there to be able to run this code in SQL*Plus and confirm the size of the SQL is indeed larger than 32K.  When running this in SQL*Plus, the procedure is successful and produces a proper SQL statement which can be executed.  When I put this into the report region on apex.oracle.com, I get the ORA-06502 error.
    I can certainly implement a work-around for my issue by creating a 'Before Header' process on the page which populates an ApEx collection with the data I am returning and then the report can simply select from the collection, but according to documentation, the above 32K limitation should be resolved in 11g.  Thoughts?
    Shane.

    What setting do you use in your report properties - especially in Type and in Region Source?
    If you have Type="SQL Query", then you should have a SELECT statement in the Region Source. Something like: SELECT .... FROM ... WHERE
    According to the ERR-1101 error message, you have probably set Type to "SQL Query (PL/SQL function body returning SQL query)". In this situation APEX expects you to write a body of a PL/SQL function, that will generate the text of a SQL query that APEX should run. So it can be something like:
    declare
    mycond varchar2(4000);
    begin
    if :P1_REPORT_SEARCH is not null THEN
    mycond:='WHERE LAST_NAME like :P1_REPORT_SEARCH ||''%''';
    end if;
    return 'select EMPLOYEE_ID, FIRST_NAME, LAST_NAME from EMPLOYEES ' ||mycond;
    end;
    And for escaping - are you interested in escaping the LIKE wildcards, or the quotes?
    For escaping the wildcards in LIKE function so that when the user enters % you will find a record with % and not all functions, look into the SQL Reference:
    http://download-uk.oracle.com/docs/cd/B19306_01/server.102/b14200/conditions007.htm
    (You would than need to change the code of your function accordingly).
    If you are interested in escaping the quotes, try to avoid concatenating the values entered by the user into the SQL. If you can, use bind variables instead - as I have in my example above. If you start concatenating the values into the text of SQL, you are open to SQLInjection - user can enter anything, even things that will break your SQL. If you really need to allow users to choose the operator, I would probably give them a separate combo for operators and a textfield for values, than you could check if the operator is one of the allowed ones and create the condition accordingly - and than still use bind variable for inserting the filtering value into the query.

  • Error in report when executing pl/sql function body returning sql query.

    Hi,
    I have used the pl/sql function body returning sql query for creating a report. I have created a datepicker(
    P10_TASK_DATE) which can be submitted.The code is as below
    DECLARE
    v_sql varchar2(3000);
    BEGIN
    if :P10_TASK_DATE is not null THEN
    v_sql:='select
          * from tasks';
    return v_sql;
    else
    v_sql:='select * from discovery';
    return v_sql;
    END IF;
    END;if the date field is empty "select * from discovery" is executed and report is getting generated. But when we give a
    date using date picker the page is submitted and i get "report error: ORA-01403: no data found" even
    though the "tasks" table has data in it. Plz help
    Thanks,
    TJ

    hi
    Please try this
    1. Create 2 region
    1st region source=
    select * from tasks'
    go to the tab -> condition =
    item NOT NULL
    EXpression1 =:P10_TASK_DATE
    this will run whenever the item have any date
    2. open your 2 nd region source code= select * from discovery
    put the condition
    item is  NULL
    EXpression1 =:P10_TASK_DATE
    thanks
    Mark Wyatt

  • Region source (PL/SQL function body returning SQL query)

    Hi, guys.
    Here is what i try to do:
    Create a region of type SQL Query (PL/SQL function body returning SQL query). In the source area i tried to put this:
    DECLARE
    v_new VARCHAR2(10);
    v_SQL varchar2(32000);
    BEGIN
    v_new := :P102_HDN_NEW;
    -- htp.p(v_new);
    IF v_new = 'N-Set' THEN
    v_SQL := 'select ' ||
    ELSIF v_new = 'Y-Set' THEN
    v_SQL := 'select ' ||
    END IF;
    RETURN v_SQL;
    END;
    And here is the reply from APEX:
    1 error has occurred
    Query cannot be parsed within the Builder. If you believe your query is syntactically correct, check the ''generic columns'' checkbox below the region source to proceed without parsing. The query can not be parsed, the cursor is not yet open or a function returning a SQL query returned without a value.
    Now.
    1. Variable is set with the right value.
    2. Each statement (separately) returns SQL that works with no problems
    3. Problem occures if i try to put IF statement around the SQL creation.
    4. If i select "Use Generic Column Names (parse query at runtime only)" instead of "Use Query-Specific Column Names and Validate Query" then the script returns SQL properly, however report's column names are set to Col1, Col2,Col3 ......
    Thnks in advence
    Mike

    OK. Here is enire statement:
    DECLARE
    v_new VARCHAR2(10);
    v_SQL varchar2(32000);
    BEGIN
    v_new := :P102_HDN_NEW;
    htp.p(v_new);
    IF v_new = 'N-Set' THEN
    v_SQL := 'select ' ||
    'APEX_ITEM.DISPLAY_AND_SAVE(10,c.sdescr) descr, ' ||
    'APEX_ITEM.DISPLAY_AND_SAVE(12,DECODE(ld.level,''All'', ''All Categories'',ld.level)) level, ' ||
    'apex_item.checkbox(1, ld.opt_in_auto_flag, decode(ld.opt_in_auto_flag,NULL,''disabled'',''Y'',''checked'')) auto_in, ' ||
    'apex_item.checkbox(2, ld.opt_in_manual_flag, decode(ld.opt_in_manual_flag,NULL,''disabled'',''Y'',''checked'')) manual_in, ' ||
    'apex_item.checkbox(3, ld.opt_out_auto_flag, decode(ld.opt_out_auto_flag,NULL,''disabled'',''Y'',''checked'')) auto_out, ' ||
    'apex_item.checkbox(4, ld.opt_out_manual_flag, decode(ld.opt_out_manual_flag,NULL,''disabled'',''Y'',''checked'')) manual_out, ' ||
    'DECODE(c.code, ''NMBR'', NULL,''Change to '' || DECODE(ld.level,''All'',''Categories'',''All Categories'')) link_change, ' ||
    'APEX_ITEM.DISPLAY_AND_SAVE(11,c.code) code ' ||
    'from ' ||
    'tbl1 c, ' ||
    'tbl2 ld ' ||
    'where c.code = ld.code ' ||
    'and c.type = ''TYPE1'' ' ||
    'and c.active = ''Y'' ' ||
    'order by c.sorting ';
    ELSIF v_new = 'Y-Set' THEN
    v_SQL := 'select ' ||
    'APEX_ITEM.DISPLAY_AND_SAVE(10,c.sdescr) descr, ' ||
    'APEX_ITEM.DISPLAY_AND_SAVE(12,''All Categories'') level, ' ||
    'apex_item.checkbox(1, c.option_1, decode(c.option_1,NULL,''disabled'',''Y'',''checked'')) auto_in, ' ||
    'apex_item.checkbox(2, c.option_3, decode(c.option_3,NULL,''disabled'',''Y'',''checked'')) manual_in, ' ||
    'apex_item.checkbox(3, c.option_2, decode(c.option_2,NULL,''disabled'',''Y'',''checked'')) auto_out, ' ||
    'apex_item.checkbox(4, c.option_4, decode(c.option_4,NULL,''disabled'',''Y'',''checked'')) manual_out, ' ||
    'DECODE(c.code, ''AAA'', NULL,''Options by AAA'') link_change, ' ||
    'APEX_ITEM.DISPLAY_AND_SAVE(11,c.code) code ' ||
    'from ' ||
    'tbl1 c ' ||
    'where 1 = 1 ' ||
    'and c.type = ''TYPE1'' ' ||
    'and c.active = ''Y'' ' ||
    'order by c.sorting ';
    END IF;
    RETURN v_SQL;
    END;
    If i put just this
    DECLARE
    v_new VARCHAR2(10);
    v_SQL varchar2(32000);
    BEGIN
    v_new := :P102_HDN_NEW;
    htp.p(v_new);
    v_SQL := 'select ' ||
    'APEX_ITEM.DISPLAY_AND_SAVE(10,c.sdescr) descr, ' ||
    'APEX_ITEM.DISPLAY_AND_SAVE(12,DECODE(ld.level,''All'', ''All Categories'',ld.level)) level, ' ||
    'apex_item.checkbox(1, ld.opt_in_auto_flag, decode(ld.opt_in_auto_flag,NULL,''disabled'',''Y'',''checked'')) auto_in, ' ||
    'apex_item.checkbox(2, ld.opt_in_manual_flag, decode(ld.opt_in_manual_flag,NULL,''disabled'',''Y'',''checked'')) manual_in, ' ||
    'apex_item.checkbox(3, ld.opt_out_auto_flag, decode(ld.opt_out_auto_flag,NULL,''disabled'',''Y'',''checked'')) auto_out, ' ||
    'apex_item.checkbox(4, ld.opt_out_manual_flag, decode(ld.opt_out_manual_flag,NULL,''disabled'',''Y'',''checked'')) manual_out, ' ||
    'DECODE(c.code, ''NMBR'', NULL,''Change to '' || DECODE(ld.level,''All'',''Categories'',''All Categories'')) link_change, ' ||
    'APEX_ITEM.DISPLAY_AND_SAVE(11,c.code) code ' ||
    'from ' ||
    'tbl1 c, ' ||
    'tbl2 ld ' ||
    'where c.code = ld.code ' ||
    'and c.type = ''TYPE1'' ' ||
    'and c.active = ''Y'' ' ||
    'order by c.sorting ';
    RETURN v_SQL;
    END;
    it works fune...

  • Timing of Report (function body returning sql) w/ pagination

    Hey -
    Wondered if someone can provide some insight here...
    I have a report that is dynamically created by calling a function that returns sql. Since it may return a few hundred results I have pagination turned on allowing the user to choose rows per page, and am showing X-Y with next/prev links.
    Before displaying the report the user has to choose some criteria to narrow down the result set - I'm finding something that I think is a bit strange in that it takes more time for the page to render when zero results are found vs. 100's of results. If I run the function and take the sql it creates, I can return 0 rows in .2 seconds and 508 rows in .5 seconds so I think the sql itself is fine. Other than debugging timings, how can I find out what is taking so long?
    Debug for 0 results:
    0.07: Region: Program Forecast (viewing SAVED values)
    5.14: show report
    5.15: determine column headings
    5.15: parse query as: ####
    5.15: print column headings
    5.15: rows loop: 15 row(s)
    10.32: Computation point: AFTER_BOX_BODY
    Debug for 508 results (in chunks of 15):
    0.07: Region: Program Forecast (viewing SAVED values)
    2.76: show report
    2.76: determine column headings
    2.77: parse query as: ####
    2.94: print column headings
    2.94: rows loop: 15 row(s)
    6.52: Computation point: AFTER_BOX_BODY
    So it took only 6.5 seconds to pull 508 rows, look at my pagination and pull the first x rows, but 10.32 seconds to pull 0 rows and show me the no data found message. Even stranger is that in the 0 rows result it looped and took 5 seconds before it hit the next point (5 seconds doing what??)
    Any ideas? I'm a little baffled here...I guess the next step is to trace it but I wanted to see if anyone had any ideas in the interim.

    Where is the embarrassed icon?
    After painstakingly copying over each item to a new page to test, I figured out performance starting sucking big time once I put a button out there that apparently had a less than optimal exists clause in it.
    D'oh!

  • ORA-12899 error from function invoked from SQL*Loader

    I am getting the above error when I call a function from my SQL*Loader script, and I am not seeing what the problem is. As far as I can see, there should be no problem with the field lengths, unless the length of the automatic variable within my function is somehow being set at 30? Here are the details (in the SQL*Loader script, the field of interest is the last one):
    ====
    Error:
    ====
    Record 1: Rejected - Error on table TESTM8.LET_DRIVE_IN_FCLTY, column DIF_CSA_ID.
    ORA-12899: value too large for column "TESTM8"."LET_DRIVE_IN_FCLTY"."DIF_CSA_ID" (actual: 30, maximum: 16)
    =======
    Function:
    =======
    CREATE OR REPLACE FUNCTION find_MCO_id (di_oid_in DECIMAL)
    RETURN CHAR IS mco_id CHAR;
    BEGIN
    SELECT AOL_MCO_LOC_CD INTO mco_id
    FROM CONV_DI_FLCTY
    WHERE DIF_INST_ELMNT_OID = di_oid_in;
    RETURN TRIM(mco_id);
    END;
    ==============
    SQL*Loader Script:
    ==============
    LOAD DATA
    INFILE 'LET_DRIVE_IN_FCLTY.TXT'
    BADFILE 'LOGS\LET_DRIVE_IN_FCLTY_BADDATA.TXT'
    DISCARDFILE 'LOGS\LET_DRIVE_IN_FCLTY_DISCARDDATA.TXT'
    REPLACE
    INTO TABLE TESTM8.LET_DRIVE_IN_FCLTY
    FIELDS TERMINATED BY '~' OPTIONALLY ENCLOSED BY '"'
    DIF_DRIVE_IN_OID DECIMAL EXTERNAL,
    DIF_FCLTY_TYPE_OID DECIMAL EXTERNAL NULLIF DIF_FCLTY_TYPE_OID = 'NULL',
    DIF_INST_ELMNT_OID DECIMAL EXTERNAL,
    DIF_PRI_PERSON_OID DECIMAL EXTERNAL NULLIF DIF_PRI_PERSON_OID = 'NULL',
    DIF_SEC_PERSON_OID DECIMAL EXTERNAL NULLIF DIF_SEC_PERSON_OID = 'NULL',
    DIF_CREATE_TS TIMESTAMP "yyyy-mm-dd-hh24.mi.ss.ff6",
    DIF_LAST_UPDATE_TS TIMESTAMP "yyyy-mm-dd-hh24.mi.ss.ff6",
    DIF_ADP_ID CHAR NULLIF DIF_ADP_ID = 'NULL',
    DIF_CAT_CLAIMS_IND CHAR,
    DIF_CAT_DIF_IND CHAR,
    DIF_DAYLT_SAVE_IND CHAR,
    DIF_OPEN_PT_TM_IND CHAR,
    DIF_CSA_ID CONSTANT "find_MCO_id(:DIF_DRIVE_IN_OID)"
    ============
    Table Definitions:
    ============
    SQL> describe CONV_DI_FLCTY;
    Name Null? Type
    DIF_INST_ELMNT_OID NOT NULL NUMBER(18)
    AOL_MCO_LOC_CD NOT NULL VARCHAR2(3)
    SQL> describe LET_DRIVE_IN_FCLTY;
    Name Null? Type
    DIF_DRIVE_IN_OID NOT NULL NUMBER(18)
    DIF_INST_ELMNT_OID NOT NULL NUMBER(18)
    DIF_FCLTY_TYPE_OID NUMBER(18)
    DIF_ADP_ID VARCHAR2(10)
    DIF_CAT_DIF_IND NOT NULL VARCHAR2(1)
    DIF_CAT_CLAIMS_IND NOT NULL VARCHAR2(1)
    DIF_CSA_ID VARCHAR2(16)
    DIF_DAYLT_SAVE_IND NOT NULL VARCHAR2(1)
    DIF_ORG_ENTY_ID VARCHAR2(16)
    DIF_OPEN_PT_TM_IND NOT NULL VARCHAR2(1)
    DIF_CREATE_TS NOT NULL DATE
    DIF_LAST_UPDATE_TS NOT NULL DATE
    DIF_ITM_FCL_MKT_ID NUMBER(18)
    DIF_PRI_PERSON_OID NUMBER(18)
    DIF_SEC_PERSON_OID NUMBER(18)
    =========================
    Thanks for any help with this one!

    I changed one line of the function to:
    RETURN CHAR IS mco_id VARCHAR2(16);
    But I still get the same error:
    ORA-12899: value too large for column "TESTM8"."LET_DRIVE_IN_FCLTY"."DIF_CSA_ID" (actual: 30, maximum: 16)
    I just am not seeing what is being defined as 30 characters. Any ideas much appreciated!

  • Unable to edit some functions in APEX Sql Workshop

    Hi
    Users are able to edit some procedures/functions in APEX SQL Work shop. ( Object Browser - functions - EDIT)
    When we press edit we get cursor in the code area and can edit some procedures, But for some procedures when we click edit we don't get cursor in the code area and we are not able to edit the functions/procedures.
    I am using fairfox browser.This is happening with only some. Is there any security.grants issue???
    Thanks
    Sree

    Hi
    This is happening with some procedures, For others this works fine.In IE I get red block in code area.
    EDIT is working for some procedures so I think may not be the browser issue.
    Thanks
    Sree

  • External FW/USB Western Digital, Seagate Disk Drives and 'Sleep' function

    As you are aware, most external disk drives be they FW or USB (and irrespective of the manufacturer, save for LaCie) have a 'sleep' function built into their Firmware. In the case of the Western Digital and Seagate Ext FW drives I have, this function cannot be disabled and this per both WD and Seagate.
    Unfortunately this is extremely annoying if using Photoshop and Bridge...it takes about ten seconds for each disk to spin up while the latter programs search the drives. (In Windows this can be enabled/disabled. Not so with the Mac O/S I have been told). Multiply this by six of the aforementioned drives and it can be quite time consuming.
    Is there an OS-X workaround for this?
    Thanks again,
    Lyman

    I always avoid vendor cases. Might want to look at an Oxford 912 etc, or better yet, why use Firewire when eSATA works so well?

  • Use of ROW_NUMBER() function in PL/SQL

    I have a Table Emp with the following Structure
    SQL> desc emp
    Name Null? Type
    EMPNO NUMBER(2)
    ENAME VARCHAR2(50)
    HIREDATE DATE
    DEPTNO NUMBER(2)
    If I write a following query on this table
    SQL> SELECT deptno, hiredate, record_id
    2 FROM (SELECT deptno, ename, hiredate, ROW_NUMBER()
    3 OVER (ORDER BY hiredate) AS record_id
    4 FROM emp)
    5 WHERE record_id >= 2
    6 AND record_id <=5;
    The Result I get is
    DEPTNO HIREDATE RECORD_ID
    10 22-NOV-01 2
    10 22-NOV-01 3
    10 22-NOV-01 4
    10 22-NOV-01 5
    But if I put this query in a cursor in a PL/SQL block. The
    pl/sql does not compiles and gives me the following address
    SQL> DECLARE
    2 CURSOR c_my IS
    3 SELECT deptno, hiredate, record_id
    4 FROM (SELECT deptno, ename, hiredate, ROW_NUMBER()
    5 OVER (ORDER BY hiredate) AS record_id
    6 FROM emp)
    7 WHERE record_id >= 2
    8 AND record_id <=5;
    9 BEGIN
    10 FOR c_rec IN c_my LOOP
    11 dbms_output.put_line(c_rec.ename);
    12 END LOOP;
    13 END;
    14 /
    OVER (ORDER BY hiredate) AS record_id
    ERROR at line 5:
    ORA-06550: line 5, column 13:
    PLS-00103: Encountered the symbol "(" when expecting one of the
    following:
    , from
    Question: Can you please tell me how I can use the ROW_NUMBER()
    function in PL/SQL. I need to use this for selecting the correct
    range of records for Pagination on a website.
    Thanks in advance
    Prashant

    As Andrew said, PL/SQL hasn't caught up with the newer bits of
    SQL.  I have heard that in 9i, they will be the same, but in 8i
    there are still things that you can do in SQL that you cannot do
    directly in PL/SQL, such as the new functions like ROW_NUMBER. 
    However, you can use NDS as a work around.  The following does
    the same as what you posted:
    SET SERVEROUTPUT ON
    DECLARE
      TYPE c_my_type  IS REF CURSOR;
      c_my               c_my_type;
      TYPE c_rec_type IS RECORD
        (deptno          emp.deptno%TYPE,
         ename           emp.ename%TYPE,
         hiredate        emp.hiredate%TYPE,
         record_id       INTEGER);
      c_rec              c_rec_type;
      v_sql              VARCHAR2 (4000);
    BEGIN
      v_sql :=
      'SELECT deptno, ename, hiredate, record_id
       FROM   (SELECT deptno, ename, hiredate,
                      ROW_NUMBER() OVER
                        (ORDER BY hiredate)
                        AS record_id
              FROM    emp)
       WHERE  record_id >= 2
       AND    record_id <= 5';
      OPEN c_my FOR v_sql;
      LOOP
        FETCH c_my INTO c_rec;
        EXIT WHEN c_my%NOTFOUND;
        DBMS_OUTPUT.PUT_LINE (c_rec.ename);
      END LOOP;
    END;
    However, you stated that you need it for selecting the correct
    range of records for pagination on a website.  For that, you
    will want something more like this:
    CREATE OR REPLACE PACKAGE package_name
    AS
      TYPE c_my_type     IS     REF cursor;
      PROCEDURE procedure_name
        (c_my            IN OUT c_my_type,
         p_record_id1    IN     NUMBER DEFAULT 1,
         p_record_id2    IN     NUMBER DEFAULT 4);
    END package_name;
    CREATE OR REPLACE PACKAGE BODY package_name
    AS
      PROCEDURE procedure_name
        (c_my            IN OUT c_my_type,
         p_record_id1    IN     NUMBER DEFAULT 1,
         p_record_id2    IN     NUMBER DEFAULT 4)
      IS
        v_sql                   VARCHAR2 (4000);
      BEGIN
        v_sql :=
            'SELECT deptno, ename, hiredate, record_id'
        || ' FROM   (SELECT deptno, ename, hiredate,'
        ||                ' ROW_NUMBER() OVER'
        ||                  ' (ORDER BY hiredate)'
        ||                  ' AS record_id'
        || ' FROM    emp)'
        || ' WHERE  record_id >= :a'
        || ' AND    record_id <= :b';
        OPEN c_my FOR v_sql
        USING p_record_id1, p_record_id2;   
      END procedure_name;
    END package_name;

  • SQL Query (pl/sql function body returning Sql query)

    Hi All,
    I have created a region of "SQL Query (pl/sql function body returning Sql query)" type and it is working fine , but when I am migrating(export /import) this application from development to systest environment ,
    It gives error for this region :
    Error ERR-1101 Unable to process function body returning query.
    OK
    ORA-06550: line 1, column 52: PLS-00306: wrong number or types of arguments in call to 'FU_TRADE_REPORT_QUERY' ORA-06550: line 1, column 45: PL/SQL: Statement ignored
    Any pointer ...why this is happening.
    Thanks
    Dikshit

    If your function is a stored function that is called from within APEX (function body not coded into the app itself), have you made sure that the function has been created and compiles ok prior to installing your apex app.
    If there are some dependency issues between other PL/SQL units or database objects that are causing your function not to be compiled, you apex install will fail as you are trying to reference an uncompelled bit of pl/sql.
    Let me know how you get on
    Regards
    Duncan

Maybe you are looking for