Using pipelined functions with bind variables in Apex...

Hy all:
I have a table which has about 10 million records and it is hanging up the system when it is trying to retrieve the data from that table... so what I have done is I created a pripelined
function and then trying to retrieve data using an SQL statement ... when I try to use a bind variable to filter by the date and location it is binding according to the location
but not by date ... can anyone help me in this please!!
Help greatly appreciated !
Thanks in advance !

Hi Denes:
Create or replace type ohe1 as object (
IMLITM NCHAR(50), IMAITM NCHAR(50), IMDSC1 NCHAR(60), COUNCS NUMBER(22), LIPQOH NUMBER(22),
LIMCU NCHAR(24), LILOCN NCHAR(40), LILOTN NCHAR(60), LILOTS NCHAR(2), IOMMEJ NUMBER(22))
CREATE OR REPLACE TYPE OHE AS TABLE OF Ohe1
CREATE OR REPLACE FUNCTION GET_ohe
return OHE PIPELINED
IS
m_rec ohe1:= ohe1 (NULL,NULL,NULL,0,0,NULL,NULL,NULL,NULL,0);
begin
for c in (select f1.LITM LITM, F1.AITM AITM, F1.DSC1 DSC1, F5.UNCS UNCS,
F21.QOH QOH, F21.MCU MCU, F21.LOCN LOCN, F21.LOTN LOTN, F21.LOTS LOTS,
F8.MEJ MEJ FROM F1 F1, F2 F2, F21 F21, F5 F5, F8 F8
WHERE (F5.EDG='07') AND (F21.QOH != 0) AND F2.IBITM = F1.IMITM
AND F21.ITM = F2.ITM AND F21.ITM = F5.ITM AND F21.MCU = F5.MCU
AND F21.MCU = F2.MCU AND F21.LOTN = F8.LOTN AND F21.MCU = F8.MCU)
loop
m_rec.LITM:=c.LITM;
m_rec.AITM:=c.AITM;
m_rec.DSC1:=c.DSC1;
m_rec.UNCS:=c.UNCS;
my_record.QOH:=c.QOH;
my_record.MCU:=c.MCU;
my_record.LOCN:=c.LOCN;
my_record.LOTN:=c.LOTN;
my_record.LOTS:=c.LOTS;
my_record.MEJ:=c.MEJ;
PIPE ROW (my_record);
end loop;
return;
end;
select LITM , AITM , DSC1 , UNCS*.0001 UNCS, QOH*.0001 QOH, (UNCS*.0001)*(QOH*.0001) AMOUNT,
MCU MCU, LOCN LOCN, LOTN LOTN, LOTS LOTS, jdate(DECODE(MEJ,0,100001,MEJ)) MEJ FROM
TABLE (GET_ohe)
WHERE trim(LIMCU)= TRIM(:OHE_BRANCHID)
AND (jdate(DECODE(MEJ,0,10001,MEJ)) >=:FROMEXPDT
AND jdate(DECODE(MEJ,0,10001,MEJ)) <=:TOEXPDATE)
The MEJ is a julian date and I am trying to convert it into a date ..... using the function jdate! and the pipelined function is created without any errors
and I am able to get the data with correct branch location bind variable but only problem is it is not binding the date filters in the sql.....
Thanks
Edited by: user10183758 on Oct 16, 2008 8:17 AM

Similar Messages

  • Attempting to test Function with Bind Variable --- What am I doing wrong?

    When I try to test a function (ComputeFreight) with a bind variable, I get an error, returned.....
    "SQL> EXEC :ComputeFreight :=V_ComputeFreight;
    BEGIN :ComputeFreight :=V_ComputeFreight; END;
    ERROR at line 1:
    ORA-06550: line 1, column 25:
    PLS-00201: identifier 'V_COMPUTEFREIGHT' must be declared
    ORA-06550: line 1, column 7:
    PL/SQL: Statement ignored"
    What am I doing wrong?
    Below is my code with description ----
    create or replace function "ComputeFreight"(p_ORDERNUMBER IN C_ORDER.ORDERNUMBER%TYPE) -- Passing Ordernumber into Function
    return NUMBER
    is
    -- Declaring Variables
    v_ComputeFreight NUMBER(10,2);
    v_low number (10,2) := 0.05;
    v_high number (10,2) := 0.07;
    v_SUBTOTAL NUMBER(10,2);
    begin
    -- Computing order subtotal (Retrieving Item cost and qty from two different tables, multiplying and adding total order cost)
    SELECT SUM(O.QUANTITY * I.ITEMPRICE) INTO v_subtotal
    FROM ORDER_LINE O JOIN INV_ITEM I
         ON (O.ITEMNUMBER = I.ITEMNUMBER)
    WHERE O.ORDERNUMBER = P_ORDERNUMBER;
    -- Testing to see which freight charge rate to use
    IF
    v_subtotal < 300.00 THEN
    v_computefreight := v_subtotal * v_low;
    ELSE
    v_computefreight := v_subtotal * v_high;
    END IF;
    -- Returning Freight Charge
    RETURN v_ComputeFreight;
    end "ComputeFreight";
    -----------------------------------

    You have made at least 2 errors.
    The first one is the name of your function:
    create or replace function "ComputeFreight" (You use double quotas and the mixed case in the function name - it means you
    make your function name case-sensitive. In the call of your function you have to use double-quoted form "ComputeFreight", nothing else.
    If you your function name has to be case-insensitive, don't use double quotas or
    use upper-case form: "COMPUTEFREIGHT".
    The next mistake is how your call you function. You have to do the following:
    var V_ComputeFreight number
    EXEC :V_ComputeFreight := <your function name>
    V_ComputeFreight is a bind variable and you have to read more about this.
    Rgds.
    P.S. and as Dave fairly remarked above you have to pass the argument into the function.
    Message was edited by:
    dnikiforov

  • Using a query with bind variable with columns defined as raw

    Hi,
    We are on Oracle 10.2.0.4 on Solaris 8. I have a table that has 2 columns defined as raw(18). I have a query from the front end that queries these two raw columns and it uses bind vairables. The query has a performance issue that I need to reproduce but my difficulty is that how to test the query in sqlplus using bind variables (the syntax for bind vairables fails for columns with raw datatype).
    SQL> DESC TEST
    Name                                      Null?    Type
    ID1                                                RAW(18)
    ID2                                                RAW(18)
    SQL> variable b1  RAW(18);
    Usage: VAR[IABLE] [ <variable> [ NUMBER | CHAR | CHAR (n [CHAR|BYTE]) |
                        VARCHAR2 (n [CHAR|BYTE]) | NCHAR | NCHAR (n) |
                        NVARCHAR2 (n) | CLOB | NCLOB | REFCURSOR |
                        BINARY_FLOAT | BINARY_DOUBLE ] ]
    The above is the error I get - i cant declare a variable as raw.
    SQL> variable b2  RAW(18);
    Usage: VAR[IABLE] [ <variable> [ NUMBER | CHAR | CHAR (n [CHAR|BYTE]) |
                        VARCHAR2 (n [CHAR|BYTE]) | NCHAR | NCHAR (n) |
                        NVARCHAR2 (n) | CLOB | NCLOB | REFCURSOR |
                        BINARY_FLOAT | BINARY_DOUBLE ] ]
    SQL> variable b3  RAW(18);
    Usage: VAR[IABLE] [ <variable> [ NUMBER | CHAR | CHAR (n [CHAR|BYTE]) |
                        VARCHAR2 (n [CHAR|BYTE]) | NCHAR | NCHAR (n) |
                        NVARCHAR2 (n) | CLOB | NCLOB | REFCURSOR |
                        BINARY_FLOAT | BINARY_DOUBLE ] ]
    --now the actual query below
    SQL> SELECT * FROM TEST WHERE ID1=:B1 AND ID2 BETWEEN :B2 AND :B3;
    SP2-0552: Bind variable "B3" not declared.
    (this fails due to the errors earlier)Also this is a third party app schema so that we don't have the option of modifying the data type of the columns.
    Thanks,
    Edited by: orausern on May 10, 2011 11:30 AM

    Try anonymous PL/SQL block:
    declare
    b1 RAW(18);
    b2 RAW(18);
    b3 RAW(18);
    begin
    b1:=..;
    b2:=..;
    b3:=..;
    SELECT col1, col2, ..
    INTO ...
    FROM TEST
    WHERE ID1=:B1
    AND ID2 BETWEEN :B2 AND :B3;
    end;
    /

  • How to Use SPOOL Command with Bind Variables

    For the Following SPOOL I want the GEN_DATE to be entered by the User at the time of execution of the SQL Script. Is it possible in SPOOL Command.
    set colsep , -- separate columns with a comma
    set pagesize 1000 -- get rid of disturbing ---- between pages
    set heading on -- Print column heading
    set trimspool on -- remove trailing blanks. eliminating the spaces up to eol
    set linesize 700 -- line size should be the sum of the column widths
    spool spool_results.csv
    SELECT *
    FROM GUI_SITE_JOURNAL
    WHERE GENDATE_ BETWEEN '2012-11-01 00:00:00:00000' AND '2012-11-02 00:00:00:00000'* ORDER BY GEN_DATE;
    spool off;
    The reason is to give the ability to user so that he can enter any range without modifying the code of the script.
    Can Any one help me please.
    Edited by: user10903866 on Feb 18, 2013 7:44 PM

    Hi,
    user10903866 wrote:
    For the Following SPOOL I want the GEN_DATE to be entered by the User at the time of execution of the SQL Script. Is it possible in SPOOL Command.Do you want the user input in the SPOOL command, or do you want it in the query?
    set colsep , -- separate columns with a comma
    set pagesize 1000 -- get rid of disturbing ---- between pages
    set heading on -- Print column heading
    set trimspool on -- remove trailing blanks. eliminating the spaces up to eol
    set linesize 700 -- line size should be the sum of the column widths
    spool spool_results.csv
    SELECT *
    FROM GUI_SITE_JOURNAL
    WHERE GENDATE_ BETWEEN '2012-11-01 00:00:00:00000' AND '2012-11-02 00:00:00:00000'* ORDER BY GEN_DATE;What is the data type oif gen_date?
    If it's a string, that's a big mistake. Information about dates belongs in DATE columns.
    If it's a DATE, then don't try to compare it to strings, such as '2012-11-01 00:00:00:00000' .
    spool off;
    The reason is to give the ability to user so that he can enter any range without modifying the code of the script.
    Can Any one help me please.One way to do that is with substitution variables:
    SET     VERIFY  OFF
    ACCEPT  start_gen_date     PROMPT "Starting date (e.g., 2013-02-18 23:00:00.00000): "
    ACCEPT  end_gen_date     PROMPT "Ending date   (e.g., 2013-02-18 23:59:59.99999): "
    SPOOL  spool_results.csv
    SELECT    *
    FROM        gui_site_journal
    WHERE        gen_date  BETWEEN '&start_gen_date'
                    AND     '&end_gen_date'
    ORDER BY  gen_date;
    SPOOL  OFFThere are security considerations. Substitution variables give devious users the power to issue any SQL command, such as DROP TABLE. Users that have SQL*Plus access already have that power, anyway.

  • How to querie with bind variable in findMode?

    Hallo,
    is it possible to use a querie with bind variable in findMode? And when how is it possible to initialize the bind variable?
    Any help is appreciated.

    Hi,
    bind variables can be linked from teh ADF binding to e.g. a managed bean, the sessionScope or other binding attributes via EL. So when you go into findMode and execute the query, the EL will grab the bindVariable values automatically.
    Frank

  • Detail view with bind variable. TreeTable not showing all detail result.

    I’m having trouble with treeTable using detail view with bind variables and where clause defined in VO definition.
    Both, master and detail view objects, base on the same entity and have the same condition in where clause. The view objects also have bind variables, which are set in prepareRowSetForQuery() method.
    Again, these are two different views, that get different result, based on value of one of the bind variable.
    When I show results in two different tables on jsf page, where master table has "RowSelection" set on "single", all results are displayed in detail table.
    But when I use treeTable, only the first result of the detail is shown.

    I tested it in applicationModule and it works, but i think that's the same as two tables on a jsf page.
    This is the order in which overridden methods are called in ADF BC or two tables on jsf page
    when clicking on row in master table.
    PrepareRowSetForQueryDetail
    executeQueryForCollection_Detail user param: 2
       Object 2: class [Ljava.lang.Object;  -> print of the object2[] parameter in executeQueryForCollection
         List 0: Bind_ChildId -> viewLink parameter
         List 1: 400035313 -> viewLink parameter value
    getEstimatedRowCount_Detail
    count: 2
    getEstimatedRowCount_Detail
    count: 2 And when i click on "expand node" in tree table:
    getEstimatedRowCount_Root
    count: 2
    PrepareRowSetForQuery_Detail
    executeQueryForCollection_Detail user param: 2
       Object 2: class [Ljava.lang.Object;
         List 0: Bind_ChildId -> viewLink parameter
         List 1: 400035321
    PrepareRowSetForQueryDetail
    executeQueryForCollection_Detail user param: 2
       Object 2: class [Ljava.lang.Object;
         List 0: Bind_ChildId -> viewLink parameter
         List 1: 400035313
    getEstimatedRowCount_Root
    count: 2
    getEstimatedRowCount_Root
    count: 2
    getEstimatedRowCount_Root
    count: 2
    PrepareRowSetForQueryDetail
    executeQueryForCollection_Detail user param: 2
       Object 2: class [Ljava.lang.Object;
         List 0: Bind_ChildId -> viewLink parameter
         List 1: 400035313
    PrepareRowSetForQueryDetail
    executeQueryForCollection_Detail user param: 2
       Object 2: class [Ljava.lang.Object;
         List 0: Bind_ChildId -> viewLink parameter
         List 1: 400035321
    getEstimatedRowCount_Root
    count: 2
    getEstimatedRowCount_Root
    count: 2Values of user parameters are OK. Is there another method that i should override?
    I also noticed, that if detail view doesn't have user bind variables, the tree works fine and is shown even in ADF BC (aplication module).
    I guess we loose a tree, when using bind variables in detail view object.
    Is there a way around it?

  • Pipelined function with lagre amount of data

    We would like to use pipelined functions as source of the select statements instead of tables. Thus we can easily switch from our tables to the structures with data from external module due to the need for integration with other systems.
    We know these functions are used in situations such as data warehousing to apply multiple transformations to data but what will be the performance in real time access.
    Does anyone have any experience using pipelined function with large amounts of data in the interface systems?

    It looks like you have already determined that the datatable object will be the best way to do this. When you are creating the object, you must enter the absolute path to your spreadsheet file. Then, you have to create some type of connection (i.e. a pushbutton or timer) that will send a true to the import data member of the datatable object. After these two things have been done, you will be able to access the data using the A3 - K133 data members.
    Regards,
    Michael Shasteen
    Applications Engineering
    National Instruments
    www.ni.com/ask
    1-866-ASK-MY-NI

  • Query with bind variable, how can use it in managed bean ?

    Hi
    I create query with bind variable (BindControlTextValue), this query return description of value that i set in BindControlTextValue variable, how can i use this query in managed bean? I need to set this value in String parameter in managed bean.
    Thanks

    Put the query in a VO and execute it the usual way.
    If you need to, you can write a parameterized method in VOImpl that executes the VO query with the parameter and then call that method from the UI (as a methodAction binding) either through the managed bean or via a direct button click on the page.

  • How to use ApplicationModuleImpl.createViewObject for VO with bind variable

    I need to implement a AM method to create VO instance from a generic VODef with bind variables.
    The createViewObject() will trigger the executeQuery of the VO before I can set up the bind variables for the query.
    What is the proper way to create view object instance with bind variables?

    I am using JDeveloper 11.1.1.2.
    I have a ViewObjectA declared with some bind variables which determine what business data to be retrieved at runtime via a service method of the ApplicationModule.
    As the ViewObjectA is only referenced internally within ApplicationModule and I need more than one instance of the ViewObjectA for different conditions at runtime,
    I use ApplicationModuleImpl.createViewObject() to create an instance of ViewObjectA instead of adding ViewObjectA to the data model of the ApplicationModule.
    Currently, when the ViewObjectA is instantiated, it also trigger an executeQuery() which will not retrieve correct data until I set up the bind variables.
    However, the createViewObject() method doesn't let me pass in the values of the binding variables.
    Currenlty, I just call the createViewObject() and then set the binding variables values and call executeQuery() again.
    Just checking if there is a better way to do so...

  • SLOW report performance with bind variable

    Environment: 11.1.0.7.2, Apex 4.01.
    I've got a simplified report page where the report runs slowly compared to running the same query in sqldeveloper. The report region is based on a pl/sql function returning a query. If I use a bind variable in the query inside apex it takes 13 seconds to run, and if I hard code a string it takes only a few hundredths of a second. The query returns one row from a table which has 1.6 million rows. Statistics are up-to-date and the columns in the joins and where clause are indexed.
    I've run traces using p_trace=YES from Apex for both the bind variable and hard coded strings. They are below.
    The sqldeveloper explain plan is identical to the bind variable plan from the trace, yet the query runs in 0.0x seconds in sqldeveloper.
    What is it about bind variable syntax in Apex that is causing the bad execution plan? Apex Bug? 11g bug? Ideas?
    tkprof output from Apex trace with bind variable is below...
    select p.master_id link, p.first_name||' '||p.middle_name||' '||p.last_name||' '||p.suffix personname,
    p.gender||' '||p.date_of_birth g_dob, p.master_id||'*****'||substr(p.ssn,-4) ssn, p.status status
    from persons p
    where
       p.person_id in (select ps.person_id from person_systems ps where ps.source_key  like  LTRIM(RTRIM(:P71_SEARCH_SOURCE1)))
    order by 1
    call     count       cpu    elapsed       disk      query    current        rows
    Parse        1      0.00       0.00          0          0          0           0
    Execute      1      0.00       0.01          0          1         27           0
    Fetch        2     13.15      13.22      67694      72865          0           1
    total        4     13.15      13.23      67694      72866         27           1
    Misses in library cache during parse: 0
    Optimizer mode: ALL_ROWS
    Parsing user id: 62  (ODPS_PRIVACYVAULT)   (recursive depth: 1)
    Rows     Row Source Operation
          1  SORT ORDER BY (cr=72869 pr=67694 pw=0 time=0 us cost=29615 size=14255040 card=178188)
          1   FILTER  (cr=72869 pr=67694 pw=0 time=0 us)
          1    HASH JOIN RIGHT SEMI (cr=72865 pr=67694 pw=0 time=0 us cost=26308 size=14255040 card=178188)
          1     INDEX FAST FULL SCAN IDX$$_0A300001 (cr=18545 pr=13379 pw=0 time=0 us cost=4993 size=2937776 card=183611)(object id 68485)
    1696485     TABLE ACCESS FULL PERSONS (cr=54320 pr=54315 pw=0 time=21965 us cost=14958 size=108575040 card=1696485)
    Rows     Execution Plan
          0  SELECT STATEMENT   MODE: ALL_ROWS
          1   SORT (ORDER BY)
          1    FILTER
          1     HASH JOIN (RIGHT SEMI)
          1      INDEX   MODE: ANALYZED (FAST FULL SCAN) OF
                     'IDX$$_0A300001' (INDEX)
    1696485      TABLE ACCESS   MODE: ANALYZED (FULL) OF 'PERSONS' (TABLE)
    Elapsed times include waiting on following events:
      Event waited on                             Times   Max. Wait  Total Waited
      ----------------------------------------   Waited  ----------  ------------
      db file scattered read                       1276        0.00          0.16
      db file sequential read                       812        0.00          0.02
      direct path read                             1552        0.00          0.61
    ********************************************************************************Here's the tkprof output with a hard coded string:
    select p.master_id link, p.first_name||' '||p.middle_name||' '||p.last_name||' '||p.suffix personname,
    p.gender||' '||p.date_of_birth g_dob, p.master_id||'*****'||substr(p.ssn,-4) ssn, p.status status
    from persons p
    where
       p.person_id in (select ps.person_id from person_systems ps where ps.source_key  like  LTRIM(RTRIM('0b')))
    order by 1
    call     count       cpu    elapsed       disk      query    current        rows
    Parse        1      0.02       0.04          0          0          0           0
    Execute      1      0.00       0.00          0          0         13           0
    Fetch        2      0.00       0.00          0          8          0           1
    total        4      0.02       0.04          0          8         13           1
    Misses in library cache during parse: 1
    Optimizer mode: ALL_ROWS
    Parsing user id: 62  (ODPS_PRIVACYVAULT)   (recursive depth: 1)
    Rows     Row Source Operation
          1  SORT ORDER BY (cr=10 pr=0 pw=0 time=0 us cost=9 size=80 card=1)
          1   FILTER  (cr=10 pr=0 pw=0 time=0 us)
          1    NESTED LOOPS  (cr=8 pr=0 pw=0 time=0 us)
          1     NESTED LOOPS  (cr=7 pr=0 pw=0 time=0 us cost=8 size=80 card=1)
          1      SORT UNIQUE (cr=4 pr=0 pw=0 time=0 us cost=5 size=16 card=1)
          1       TABLE ACCESS BY INDEX ROWID PERSON_SYSTEMS (cr=4 pr=0 pw=0 time=0 us cost=5 size=16 card=1)
          1        INDEX RANGE SCAN IDX_PERSON_SYSTEMS_SOURCE_KEY (cr=3 pr=0 pw=0 time=0 us cost=3 size=0 card=1)(object id 68561)
          1      INDEX UNIQUE SCAN PK_PERSONS (cr=3 pr=0 pw=0 time=0 us cost=1 size=0 card=1)(object id 68506)
          1     TABLE ACCESS BY INDEX ROWID PERSONS (cr=1 pr=0 pw=0 time=0 us cost=2 size=64 card=1)
    Rows     Execution Plan
          0  SELECT STATEMENT   MODE: ALL_ROWS
          1   SORT (ORDER BY)
          1    FILTER
          1     NESTED LOOPS
          1      NESTED LOOPS
          1       SORT (UNIQUE)
          1        TABLE ACCESS   MODE: ANALYZED (BY INDEX ROWID) OF
                       'PERSON_SYSTEMS' (TABLE)
          1         INDEX   MODE: ANALYZED (RANGE SCAN) OF
                        'IDX_PERSON_SYSTEMS_SOURCE_KEY' (INDEX)
          1       INDEX   MODE: ANALYZED (UNIQUE SCAN) OF 'PK_PERSONS'
                      (INDEX (UNIQUE))
          1      TABLE ACCESS   MODE: ANALYZED (BY INDEX ROWID) OF
                     'PERSONS' (TABLE)

    Patrick, interesting insight. Thank you.
    The optimizer must be peeking at my bind variables with it's eyes closed. I'm the only one testing and I've never passed %anything as a bind value. :)
    Here's what I've learned since my last post:
    I don't think that sqldeveloper is actually using the explain plan it says it is. When I run explain plan in sqldeveloper (with a bind variable) it shows me the exact same plan as Apex with a bind variable. However, when I run autotrace in sqldeveloper, it takes a path that matches the hard coded values, and returns results in half a second. That autotrace run is consistent with actually running the query outside of autotrace. So, I think either sqldeveloper isn't really using bind variables, OR it is using them in some other way that Apex does not, or maybe optimizer peeking works in sqldeveloper?
    Using optimizer hints to tweak the plan helps. I've tried both /*+ FIRST_ROWS */ and /*+ index(ps pk_persons) */ and both drop the query to about a second. However, I'm loath to use hints because of the very dynamic nature of the query (and Tom Kyte doesn't like them either). The hints may end up hurting other variations on the query.
    I also tested the query by wrapping it in a select count(1) from ([long query]) and testing the performance in sqldeveloper and in Apex. The performance in that case is identical with both bind variables and hard coded variables for both Apex and SqlDeveloper. That to me was very interesting and I went so far as to set up two bind variable report regions on the same page. One region wrapped the long query with select count(1) from (...) and the other didn't. The wrapped query ran in 0.01 seconds, the unwrapped took 15ish seconds with no other optimizations. Very strange.
    To get performance up to acceptable levels I have changed my function returning query to:
    1) Set the equality operator to "=" for values without wildcards and "like" for user input with wildcards. This makes a HUGE difference IF no wildcard is used.
    2) Insert a /*+ FIRST_ROWS */ hint when users chose the column that requires the sub-query. This obviously changes the optimizer's plan and improves query speed from 15 seconds to 1.5 seconds even with wildcards.
    I will NOT be hard coding any user supplied values in the query string. As you can probably tell by the query, this is an application where sql injection would be very bad.
    Jeff, regarding your question about "like '%' || :P71_SEARCH_SOURCE1 || '%'". I've found that putting wildcards around values, particularly at the beginning will negate any indexing on the column in question and slows performance even more.
    I'm still left wondering if there isn't something in Apex that is breaking the optimizer "peeking" that Patrick describes. Perhaps something in the way it switches contexts from apex_public_user to the workspace schema?

  • Report Performance with Bind Variable

    Getting some very odd behaviour with a report in APEX v 3.2.1.00.10
    I have a complex query that takes 5 seconds to return via TOAD, but takes from 5 to 10 minutes in an APEX report.
    I've narrowed it down to one particular bind. If I hard code the date in it returns in 6 seconds, but if I let the date be passed in from a parameter it takes 5+ minutes again.
    Relevant part of the query (an inline view) is:
    ,(select rglr_lect lect
    ,sum(tpm) mtr_tpm
    ,sum(enrols) mtr_enrols
    from ops_dash_meetings_report
    where meet_ev_date between to_date(:P35_END_DATE,'DD/MM/YYYY') - 363 and to_date(:P35_END_DATE,'DD/MM/YYYY')
    group by rglr_lect) RPV
    I've tried replacing the "to_date(:P35_END_DATE,'DD/MM/YYYY') - 363" with another item which is populated with the date required (and verified by checking session state). If I replace the :P35_END_DATE with an actual date the performance is fine again.
    The weird thing is that a trace file shows me exactly the same Explain Plan as the TOAD Explain where it runs in 5 seconds.
    Another odd thing is that another page in my application has the same inline view and doesn't hit the performance problem.
    The trace file did show some control characters (circumflex M) after each line of this report's query where these weren't anywhere else on the trace queries. I wondered if there was some sort of corruption in the source?
    No problems due to pagination as the result set is only 31 records and all being displayed.
    Really stumped here. Any advice or pointers would be most welcome.
    Jon.

    Don't worry about the Time column, the cost and cardinality are more important to see whther the CBO is making different decisions for whatever reason.
    Remember that the explain plan shows the expected execution plan and a trace shows the actual execution plan. So what you want to do is compare the query with bind variables from an APEX page trace to a trace from TOAD (or sqlplus or whatever). You can do this outside APEX like this...
    ALTER SESSION SET EVENTS '10046 trace name context forever, level 1';Enter and run your SQL statement...;
    ALTER SESSION SET sql_trace=FALSE;This will create a a trace file in the directory returned by...
    SELECT value FROM v$parameter WHERE name = 'user_dump_dest' Which you can use tkprof to format.
    I am assuming that your not going over DB links or anything else slightly unusual?
    Cheers
    Ben

  • LOV(af:selectOneChoice) with bind variable in af:table

    Hi All,
    I have a table where a column is defined as dropdown(af:selectOneChoice). The query for selectOneChoice has a bind variable which needs to be set as a value from the base view Object corresponding row.
    Suppose a table Employee
    EmpId EmpName EmpType Authorization
    101 John Temp No
    The above table is created as af:table and 'Authorization' is implemented as dropdown(af:selectOneChoice) . The selectOneChoice has a query(AuthorizationLovVVO) with bind variable . For each row of af:table(EmployeeVO) , af:selectOneChoice query(AuthorizationLovVVO) requires
    the corresponding row(EmployeeVO) 'EmpType' to be set as value of bind variable.
    Can you please suggest how can we achieve this functionality.
    Edited by: 907302 on Oct 17, 2012 7:22 AM
    Edited by: 907302 on Oct 17, 2012 7:22 AM

    I have checked the following post where it has been suggested to access the the current row value as groovy expression.
    groovy for bind variable
    Suppose my AM name is 'TestAM' , i have tried the below expressions for value of bind variable but it does not work :
    1) adf.object.TestAM.findViewObject('EmployeeVO1').currentRow.EmpType
    2) adf.object.TestAMDataControl.findViewObject('EmployeeVO1').currentRow.EmpType
    None of the above expressions work and i get the error while running the page as 'Variable NotesAM is not recognized.' / 'Variable NotesAMDataControl is not recognized.' .
    Can you please suggest if we can achieve the functionality using this approach . Also let me know if i am missing something in the above expression.

  • RESTful service and BLOB with bind variable

    Hi,
    Has anyone successfully created a RESTful service with bind variable to retrieve a BLOB field and render it in an Apex app? I can create RESTful web service and render BLOB field for a record with no bind variable (single row). As soon as I add bind variable my RESTful service fails -- I get 404 Error. Without bind variable it renders both in TEST tool of Workspace and direct URL. As soon as I add a bind variable it fails either way. I have reported this in an SR to Oracle support, but thought I would post here too.
    I would also like to retrieve the photo into an Apex application. Any hints would be appreciated.
    Thanks,
    Pat

    Hi Fateh -
    Good question. You would identify the source type as a Media Resource, and use an SQL statement with the primary key and the BLOB column. When you use Media Resource, you are essentially telling your Database Cloud Service not to marshall the data, just to send it - which is exactly what you are looking for.
    With this implementation, you would have to have a separate SQL call for each BLOB retrieval. However, you might be able to use a PL/SQL block as the end point for the RESTful Service and take care of multiple BLOB processing in the block.
    Hope this helps.
    - Rick Greenwald

  • Create collection from query with bind variable

    Apex 4.0.2
    Per Joel Re: Collection with bind variable the apex_collection.create_collection_from_query_b supports queries containing bind variable references (:P1_X) but I am not sure how to use this feature, the documentation doesn't have an example, just the API signature for the overloaded version has changed.
    If the query contains 2 bind variable references to session state (:P1_X and :P1_Y), can someone please show an example of what to pass in for the p_names and p_values parameters to the API?
    Thanks
    procedure create_collection_from_query_b(
        -- Create a named collection from the supplied query using bulk operations.  The query will
        -- be parsed as the application owner.  If a collection exists with the same name for the current
        -- user in the same session for the current Flow ID, an application error will be raised.
        -- This procedure uses bulk dynamic SQL to perform the fetch and insert operations into the named
        -- collection.  Two limitations are imposed by this procedure:
        --   1) The MD5 checksum for the member data will not be computed
        --   2) No column value in query p_query can exceed 2,000 bytes
        -- Arguments:
        --     p_collection_name   =  Name of collection.  Maximum length can be
        --                            255 bytes.  Note that collection_names are case-insensitive,
        --                            as the collection name will be converted to upper case
        --     p_query             =  Query to be executed which will populate the members of the
        --                            collection.  If p_query is numeric, it is assumed to be
        --                            a DBMS_SQL cursor.
        -- example(s):
        --     l_query := 'select make, model, caliber from firearms';
        --     apex_collection.create_collection_from_query_b( p_collection_name => 'Firearm', p_query => l_query );
        p_collection_name in varchar2,
        p_query           in varchar2,
        p_names           in wwv_flow_global.vc_arr2,
        p_values          in wwv_flow_global.vc_arr2,
        p_max_row_count   in number default null)
        ;

    VANJ wrote:
    Apex 4.0.2
    Per Joel Re: Collection with bind variable the apex_collection.create_collection_from_query_b supports queries containing bind variable references (:P1_X) but I am not sure how to use this feature, the documentation doesn't have an example, just the API signature for the overloaded version has changed.
    If the query contains 2 bind variable references to session state (:P1_X and :P1_Y), can someone please show an example of what to pass in for the p_names and p_values parameters to the API?Not tried it, but guessing something like
    apex_collection.create_collection_from_query_b(
        p_collection_name => 'foobar'
      , p_query => 'select f.foo_id, b.bar_id, b.baz from foo f, bar b where f.foo_id = b.foo_id and f.x = to_number(:p1_x) and b.y = :p1_y'
      , p_names => apex_util.string_to_table('p1_x:p1_y')
      , p_values => apex_util.string_to_table(v('p1_x') || ':' || v('p1_y')))

  • Problem with Bind Variable in 11.2

    Hi
    I have a slow statement with bind Variables. With literals it works fine. Is there a way to replace the bind by literal in advanced ? I use Release 11.2.0.2.3
    Thank you

    904062 wrote:
    I have a slow statement with bind Variables. With literals it works fine. Is there a way to replace the bind by literal in advanced ? I use Release 11.2.0.2.3This specific scenario is very much an exception to the rule - and you need to back your statement up with execution plans of the SQL with bind variables and with literals, and run stats that show the difference between these two execution plans.
    See the {message:id=9360003} from the {forum:id=75} forum's FAQ for details on how to post a SQL performance tuning question.

Maybe you are looking for

  • Error while building  the eclipse using exadel tool

    hi all i m facing a problem while building project using eclipse tool called(exadel ).it gives error like "integarted external building tool error - : variable references non existent resource :${workspace_loc:/my project not found}". so if anybody h

  • Ipod touch library restore! HELP PLEASE!

    Someone help please! I have an ipod touch, my pc stoped working so my entire library got erased. Is it possible to somehow bring up my old library on my newly restored computer? -Im using the same computer now as I was when I had my original itunes l

  • Withholding tax type FE is not defined for country MY

    When I assign cocd to Fe (Withholding tax type for us-1099 fedral withholding tax) to us and unit 100. i get an error Withholding tax type FE is not defined for country MY.. pls help

  • Service Method trouble

    I'm having trouble calling upon a service Class method (Convert.java)i've created which: 1. Receives an Uppercase String 2. Converts the Uppercase String to a lowercase String. 3. Converts the now lowercase string into a single char. 4. Returns the c

  • Transactions missing from reports

    I am having major issues with reports on paypal. Lots of transactions aren't included on the reports. What is on one report may or may not show up on a different report. Inpossible to balance account at the end of the month. Sometimes it comes up wit