Passing a query with a variable to a function

I have a procedure that builds a query and passes it to a function to dump the results to a csv file. I now need to add a parameter to the procedure to allow the number of days in the past to be passed in and used as a variable in the query (it was previously hardcoded to "sysdate-7" and worked fine). So I have added the parameter "p_days_back", but as soon as I put "sysdate - p_days_back" in the query, it fails with "Invalid Query". I'm hoping there's someway to format this parameter to be acceptable to this quoted query string. Procedure snippet below:
CREATE OR REPLACE PROCEDURE EXTRACT_PS_EMPS
(p_days_back IN NUMBER DEFAULT 7)
AS
v_query VARCHAR2(4000);
v_separator VARCHAR2(1) := ',';
v_dir VARCHAR2(500) := '/export/home/oracle';
v_filename VARCHAR2(100) := 'emp_data.csv';
l_rows NUMBER(4) := 0;
BEGIN
v_query :=
'SELECT user_access_id,
jobcode,
orig_hire_dt,
empl_status,
company
FROM ps_empl_view
WHERE company in (''TP'',''SS'',''UE'',''UG'')
AND orig_hire_dt <= sysdate
     AND (empl_status in (''P'',''A'',''L'',''S'')
or (empl_status NOT in (''P'',''A'',''L'',''S'') AND effdt >= sysdate - p_days_back))
ORDER BY user_access_id';
l_rows := uns_pf_dump_csv(v_query, v_separator, v_dir, v_filename);
dbms_output.put_line('Rows created: ' || l_rows);
IF l_rows < 0 THEN
IF l_rows = -1 THEN
dbms_output.put_line('File Open Error');
v_text := 'Error from EXTRACT_PS_EMPS: ' || l_rows || ' = ' || 'File Open Error';
ELSIF l_rows = -2 THEN
dbms_output.put_line('Query Error');
v_text := 'Error from EXTRACT_PS_EMPS: ' || l_rows || ' = ' || 'Query Error';
ELSIF l_rows = -3 THEN
dbms_output.put_line('Invalid Path');
v_text := 'Error from EXTRACT_PS_EMPS: ' || l_rows || ' = ' || 'Invalid Path';
ELSIF l_rows = -4 THEN
dbms_output.put_line('Invalid Mode');
v_text := 'Error from EXTRACT_PS_EMPS: ' || l_rows || ' = ' || 'Invalid Mode';
ELSIF l_rows = -5 THEN
dbms_output.put_line('Invalid Filehandle');
v_text := 'Error from EXTRACT_PS_EMPS: ' || l_rows || ' = ' || 'Invalid Filehandle';
ELSIF l_rows = -6 THEN
dbms_output.put_line('Invalid Operation');
v_text := 'Error from EXTRACT_PS_EMPS: ' || l_rows || ' = ' || 'Invalid Operation';
ELSIF l_rows = -7 THEN
dbms_output.put_line('Write Error');
v_text := 'Error from EXTRACT_PS_EMPS: ' || l_rows || ' = ' || 'Write Error';
ELSIF l_rows = -8 THEN
dbms_output.put_line('Internal Error');
v_text := 'Error from EXTRACT_PS_EMPS: ' || l_rows || ' = ' || 'Internal Error';
ELSIF l_rows = -9 THEN
dbms_output.put_line('Other Error');
v_text := 'Error from EXTRACT_PS_EMPS: ' || l_rows || ' = ' || 'Other Error';
END IF;
END IF;
EXCEPTION
WHEN OTHERS THEN
dbms_output.put_line('Proc Error from EXTRACT_PS_EMPS: ' || SQLERRM);
END;
Thanks in advance for your help.

In the future please post the following:
1. Oracle version (example: 10.2.0.4)
2. Post any code in fixed format using \ tags.
One question, do you have the ability to modify your function that dumps data to CSV?                                                                                                                                                                                                                                                                                                                                                                                                                                                               

Similar Messages

  • 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.

  • SQL query with Bind variable with slower execution plan

    I have a 'normal' sql select-insert statement (not using bind variable) and it yields the following execution plan:-
    Execution Plan
    0 INSERT STATEMENT Optimizer=CHOOSE (Cost=7 Card=1 Bytes=148)
    1 0 HASH JOIN (Cost=7 Card=1 Bytes=148)
    2 1 TABLE ACCESS (BY INDEX ROWID) OF 'TABLEA' (Cost=4 Card=1 Bytes=100)
    3 2 INDEX (RANGE SCAN) OF 'TABLEA_IDX_2' (NON-UNIQUE) (Cost=3 Card=1)
    4 1 INDEX (FAST FULL SCAN) OF 'TABLEB_IDX_003' (NON-UNIQUE)
    (Cost=2 Card=135 Bytes=6480)
    Statistics
    0 recursive calls
    18 db block gets
    15558 consistent gets
    47 physical reads
    9896 redo size
    423 bytes sent via SQL*Net to client
    1095 bytes received via SQL*Net from client
    3 SQL*Net roundtrips to/from client
    1 sorts (memory)
    0 sorts (disk)
    55 rows processed
    I have the same query but instead running using bind variable (I test it with both oracle form and SQL*plus), it takes considerably longer with a different execution plan:-
    Execution Plan
    0 INSERT STATEMENT Optimizer=CHOOSE (Cost=407 Card=1 Bytes=148)
    1 0 TABLE ACCESS (BY INDEX ROWID) OF 'TABLEA' (Cost=3 Card=1 Bytes=100)
    2 1 NESTED LOOPS (Cost=407 Card=1 Bytes=148)
    3 2 INDEX (FAST FULL SCAN) OF TABLEB_IDX_003' (NON-UNIQUE) (Cost=2 Card=135 Bytes=6480)
    4 2 INDEX (RANGE SCAN) OF 'TABLEA_IDX_2' (NON-UNIQUE) (Cost=2 Card=1)
    Statistics
    0 recursive calls
    12 db block gets
    3003199 consistent gets
    54 physical reads
    9448 redo size
    423 bytes sent via SQL*Net to client
    1258 bytes received via SQL*Net from client
    3 SQL*Net roundtrips to/from client
    1 sorts (memory)
    0 sorts (disk)
    55 rows processed
    TABLEA has around 3million record while TABLEB has 300 records. Is there anyway I can improve the speed of the sql query with bind variable? I have DBA Access to the database
    Regards
    Ivan

    Many thanks for your reply.
    I have run the statistic already for the both tableA and tableB as well all the indexes associated with both table (using dbms_stats, I am on 9i db ) but not the indexed columns.
    for table I use:-
    begin
    dbms_stats.gather_table_stats(ownname=> 'IVAN', tabname=> 'TABLEA', partname=> NULL);
    end;
    for index I use:-
    begin
    dbms_stats.gather_index_stats(ownname=> 'IVAN', indname=> 'TABLEB_IDX_003', partname=> NULL);
    end;
    Is it possible to show me a sample of how to collect statisc for INDEX columns stats?
    regards
    Ivan

  • From Clause query with form variables

    forms 9.0.4 rdbms 9.2
    Is it possible to create a From Clause query with form variables generated from another block (but in the same form)? I am not having any success.
    I searched Metalink. It appears that according to DOC ID # 69884.1, in Forms 6i, this is not possible. Metalink suggest in DOC ID 104771.1 implementating a dynamic From Clause, but when I duplicate the example on my system, I receive an Oracle error. Further investigation from the web form (DISPLAY ERROR) indicates that the system does not see the dynamic value.
    Has anyone else run into this error? Has this been fixed in forms 9.0.4 and I am just missing something? Does a dynamic from clause query work? Can anyone point me to an example or post an example or offer any advise.
    thanks in advance

    As far as I know it is not possible to use block items in a from clause query in forms 9.0.4. Here is my solution for a From-Clause-Query via the 'Query-Data-Source-Name-Property':
    To use the values of the block items in my from clause query I implemented a database package with getter and setter routines for the block item values I needed for the query.
    In the Key-Exeqry-Trigger of the From-Clause-Query-Block I set the global package variables with values of the block-items I am interested in. In the From-Clause-Query I used the values in the where-clause via package functions which return the global package variables.
    Hope my solution will work for your problem.

  • Query with 2 variables

    I have a query with two variables (Employee and Date). The query is working fine if both of the variables are check and values assigned. But if only one variable is checked and a value assigned then the query will return 0 results. Is it possible that the query cannot work with only one variable out of the 2? Do I need a workaround or am i doing something wrong?
    Here is the query:
    SELECT T0.DocNum, T0.DocDate, T0.DocDueDate, T0.CardCode, T0.CardName, T0.Address, T0.DocTotal, T0.U_Employee, T1.firstName,T1.lastName,  T0.Comments FROM OVPM T0 LEFT JOIN OHEM T1 ON T0.U_EMPLOYEE = T1.FIRSTNAME' 'T1.LASTNAME WHERE T0.DocType = 'A' AND T0.U_EMPLOYEE = [%0] AND T0.DocDate =[%1].
    Thank you so much for your help,
    Irina Stanca

    AFAIK, at least with 'complex queries' unchecked parameter gets
    some default/blank value. Therefore, you should allow default values in your
    WHERE clause.
    You want: WHERE T0.COL = @VAR
    You write: WHERE (T0.COL = @VAR OR [logical test for @VAR is a default value])
    Snippets like this may help you in finding out that default value:
    -- snip --
    /SELECT FROM [dbo].[OHEM] T9/
    declare @VAR_EMPL as char(20)
    /* WHERE */
    set @VAR_EMPL = /* T9.lastName */ '[%0]'
    /SELECT FROM [dbo].[OVPM] T8/
    declare @VAR_DATE as char(20)
    /* WHERE */
    set @VAR_DATE = /* T8.DocDate */ '[%1]'
    SELECT '@VAR_EMPL: ' + '|' + @VAR_EMPL + '|' +  '@VAR_DATE: ' + @VAR_DATE + ' DATEDIFF: ' + cast(DATEDIFF(day, CAST('1900-01-01' as datetime), CAST(@VAR_DATE as datetime)) as varchar)
    [/code]
    -- snip --
    Yes, it looks like the default value for dates is '1900-01-01'.
    Therefore, you may want to code this way
    .. WHERE (DocDate = @VAR_DATE OR DATEDIFF(day, CAST('1900-01-01' as datetime), CAST(@VAR_DATE as datetime)) > 0)
    I also noticed a date-related issue that may cause problems in complex queries
    if you work with dates from last century AND if your date format in B1 is YY instead of CCYY:
    you enter 1907 and B1 interprets it as 2007.
    HTH
    Juha

  • ODT Query Window. Query with binding variable?

    I have the ODT 11.1.0.7.20 installed.
    In "Query Window", I execute an SQL with binding variables. But I only get ORA-01008 errors. How do I do that?
    I want to double click an SQL and load it in "Query Window". How do I do that?
    I want to right click an SQL and select "Open with Query Window". How do I do that?
    In Query Window I want to load an SQL either by drag and drop or by select a function "Open SQL". How do I do that?
    Why none of these functionalities work as you could expect?
    Thanks,
    Tobias

    Finally i found the problem..
    The problem was that i had to remove one line from the properties of my table departments, the property: selectedrowkeys, because it only passed the last selected row.
    Still, i apreciate the help and i had to replace some code in the bean.java , because of the exception error and you didn't had to do that. Maybe i did some configuration in the wrong way and it went wrong.
    Thanks for the help.
    Regards,
    Frederico.

  • How to add '%' to a query with bind variables

    Hi,
    I am using oracle jdeveloper 11g.
    I am trying to create a table to display rows using the below query in a jspx page,
    select * from ade_txns where series='WORKPLACE_PT.11.1.1.8.0_GENERIC' and transaction like 'rkumara%'
    I am using a view with query and binding variables as below,
    select * from ade_txns where series= :p_series and transaction like :p_QAEngineer
    I will be passing p_QAEngineer using binding variable using 'ExecuteWithParams' using a dropdown(eg: 'rkumara'). But I need to add a '%' to this value as I am using a 'LIKE' clause in my query.
    I tried using,
    select * from ade_txns where series= :p_series and transaction like :p_QAEngineer+'%'
    But this is not working for me.
    Can someone please tell me how i can solve this.
    Thanks,
    Ranjeet

    does this help also?
    How to add regular expression in viewobject bind variables
    ~Abhijit

  • 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')))

  • Report query with bind variable

    Trying to create a report query for xsl-fo print. For output format I pick "derive from item" then pick the item name from the list, on the next screen, I paste the query with the bind variable. on the next step test query, I always get "data not found" regardless what value I type in. This is the same query that I ran under sql commands without any issues.
    Does anyone run into the same issue as I have when attempted to create a query with bind var ? There is no problem creating a query without bind varibles. . thanks.
    Munshar

    Hi, please did you get any solution to this issue? I am having similar challenge right now.
    select     EMP.DEPTNO as DEPTNO,
         DEPT.DNAME as DNAME,
         EMP.EMPNO as EMPNO,
         EMP.ENAME as ENAME,
         EMP.JOB as JOB,
         EMP.MGR as MGR,
         EMP.HIREDATE as HIREDATE,
         EMP.SAL as SAL
    from     SCOTT.DEPT DEPT,
         SCOTT.EMP EMP
    where EMP.DEPTNO=DEPT.DEPTNO
    and      DEPT.DNAME =upper(:dname)
    This run perfectly in sql developer, toad, and even inside publisher if I login directly to publisher to create report.
    Generating this same query in shared component query builder and testing it returns no data found. If I remove the last line, it works. but with the last line, it return no data found. It seems no one has been able to provide solution to this issue

  • Issue with SQL Query with Presentation Variable as Data Source in BI Publisher

    Hello All
    I have an issue with creating BIP report based on OBIEE reports which is done using direct SQL. There is this one report in OBIEE dashboard, which is written using direct SQL. To create the pixel perfect version of this report, I am creating BIP data model using SQL Query as data source. The physical query that is used to create OBIEE report has several presentation variables in its where clause.
    select TILE4,max(APPTS), 'Top Count' from
    SELECT c5 as division,nvl(DECODE (C2,0,0,(c1/c2)*100),0) AS APPTS,NTILE (4) OVER ( ORDER BY nvl(DECODE (C2,0,0,(c1/c2)*100),0))  AS TILE4,
    c4 as dept,c6 as month FROM 
    select sum(case  when T6736.TYPE = 'ATM' then T7608.COUNT end ) as c1,
         sum(case  when T6736.TYPE in ('Call Center', 'LSM') then T7608.CONFIRMED_COUNT end ) as c2,
         T802.NAME_LEVEL_6 as c3,
         T802.NAME_LEVEL_1 as c4,
         T6172.CALENDARMONTHNAMEANDYEAR as c5,
         T6172.CALENDARMONTHNUMBERINYEAR as c6,
         T802.DEPT_CODE as c7
    from
         DW_date_DIM T6736 /* z_dim_date */ ,
         DW_MONTH_DIM T6172 /* z_dim_month */ ,
         DW_GEOS_DIM T802 /* z_dim_dept_geo_hierarchy */ ,
         DW_Count_MONTH_AGG T7608 /* z_fact_Count_month_agg */
    where  ( T802.DEpt_CODE = T7608.DEPT_CODE and T802.NAME_LEVEL_1 =  '@{PV_D}{RSD}' 
    and T802.CALENDARMONTHNAMEANDYEAR = 'July 2013'
    and T6172.MONTH_KEY = T7608.MONTH_KEY and T6736.DATE_KEY = T7608.DATE_KEY
    and (T6172.CALENDARMONTHNUMBERINYEAR between substr('@{Month_Start}',0,6)  and substr('@{Month_END}',8,13))
    and (T6736.TYPE in ('Call Center', 'LSM')) )
    group by T802.DEPT_CODE, T802.NAME_LEVEL_6, T802.NAME_LEVEL_1, T6172.CALENDARMONTHNAMEANDYEAR, T6172.CALENDARMONTHNUMBERINYEAR
    order by c4, c3, c6, c7, c5
    ))where tile4=3 group by tile4
    When I try to view data after creating the data set, I get the following error:
    Failed to load XML
    XML Parsing Error: mismatched tag. Expected: . Location: http://172.20.17.142:9704/xmlpserver/servlet/xdo Line Number 2, Column 580:
    Now when I remove those Presention variables (@{PV1}, @{PV2}) in the query with some hard coded values, it is working fine.
    So I know it is the PV that's causing this error.
    How can I work around it?
    There is no way to create equivalent report without using the direct sql..
    Thanks in advance

    I have found a solution to this problem after some more investigation. PowerQuery does not support to use SQL statement as source for Teradata (possibly same for other sources as well). This is "by design" according to Microsoft. Hence the problem
    is not because different PowerQuery versions as mentioned above. When designing the query in PowerQuery in Excel make sure to use the interface/navigation to create the query/select tables and NOT a SQL statement. The SQL statement as source works fine on
    a client machine but not when scheduling it in Power BI in the cloud. I would like to see that the functionality within PowerQuery and Excel should be the same as in Power BI in the cloud. And at least when there is a difference it would be nice with documentation
    or more descriptive errors.
    //Jonas 

  • Af:query with bind variables and Saved Search

    I have a VO and view criteria(VC).
    VC has a criteria item ObsoleteDate with range specified as bindVariables "dateFrm" and "dateTo" I dragged & dropped the named criteria as af:Query with table. Table toolbar has 2 buttons in which I set & clear the bind variables. Data is fetched as per as expected based on the VC & bind variables.
    The problem is,
    If I save my search with bind variables set and swap between the saved searches , all works fine. But the moment I clear bind variables & swap between searches.. "dateFrm" is populated and "dateTo" is null and I get an Exception oracle.jbo.AttrValException: JBO-27035: Attribute Obsolete Date: is required.
    Why is this happening?? Saved search is supposed to save the VC with all the bind values set while saving and clearing bind variables shouldn't affect the saved search, right?? Or I have understood it wrong?
    I am using JDeveloper 11.1.2.3.0
    Thanks

    Try
    like ? || '%'

  • Repeated rows resulting from executeWithParams on query with bind variable

    hi
    Please consider this example application created using JDeveloper 11.1.1.3.0
    at http://www.consideringred.com/files/oracle/2010/RepeatedRowsIssueApp-v0.01.zip
    It has a View Object "EmployeesVO" based on a SQL query with a bind variable "EmailBVar".
    The page "findEmployees.jspx" has executeWithParams dropped as an "ADF Parameter Form..." and the "EmployeesVOVI" collection as a table.
    On "EmployeesVOVIIterator" the RangeSize has been modified from the default 25 to 10.
    So, all straightforward stuff.
    A scenario (sc1), running the page "findEmployees.jspx", specifying a value and clicking the "ExecuteWithParams" button results in repeated rows shown in the table, that is the first row (and subsequent rows) are repeated at row 11 (and subsequent rows),
    as can be seen in the screencast at http://screencast.com/t/bn9QvV0qt
    question:
    - (q1) How can the repeated rows in scenario (sc1) be explained/avoided?
    many thanks
    Jan Vervecken

    Thanks for your reply Nick Haralabidis.
    it can be avoided by setting the EmployeesVO Access Mode to Range Paging and setting the Range Size to 10. Indeed, that does seem to avoid the repeating rows.
    Now why you get this behavior when you don't specify Range Paging on the VO I don't know. It could be because: 1) it is a bug - the obvious answer ;) , 2) because setting the RangeSize on the EmployeesVOVIIterator without setting the Access Mode on the EmployeesVO to Range Paging is conflicting - but then again there is no warning or error produced by JDeveloper, 3) ...It does look like unintended behaviour, for a "default approach" like this.
    In documentation section "39.1.5 Efficiently Scrolling Through Large Result Sets Using Range Paging " ...
    at http://download.oracle.com/docs/cd/E14571_01/web.1111/b31974/bcadvvo.htm#ADFFD1179
    ... this Range Paging for a View Object seems to be described as an optimization, not as a requirement for functionally correct behaviour.
    - about (q1)
    Another approach that seems to avoid the repeated rows in scenario (sc1) is removing the value for the RangeSize attribute on the iterator, so the RangeSize is not specified.
    Using the modified example application
    at http://www.consideringred.com/files/oracle/2010/RepeatedRowsIssueApp-v0.02.zip
    ... this can be seen in scenario (sc2) in the screencast at http://screencast.com/t/0bpCo33i8J
    Although, the documentation in section "22.4.2.2 Iterator RangeSize Attribute " ...
    at http://download.oracle.com/docs/cd/E14571_01/web.1111/b31974/web_form.htm#ADFFD706
    ... does not seem to mention anything about not specifying the RangeSize attribute, it does say "... You can set it to -1 to have the full record set returned. ...".
    As can be seen in scenario (sc2) the EL expression #{bindings.EmployeesVOVIIterator.rangeSize} resolves to -1 which suggests that not specifying the RangeSize attribute is the same as configuring the RangeSize attribute to -1.
    questions:
    - (q2) What is the preferred way to avoid having "the full record set returned", without having repeated rows as in scenario (sc1)?
    - (q3) Is the default configuration of RangeSize="25" on the iterator intended behaviour (for an interator supporting an executeWithParams action)?
    regards
    Jan

  • LOV query with bind variable

    Hi,
    I have a LOV with a query has a bind variable:
    select comp_plan_id,name from cn_comp_plans_all
    where sysdate between start_date and nvl(end_date,sysdate+1)
    and org_id = : 1
    So I create a CO for this LOV , and in processRequest(), I pass the value of this bind varible.
    Now in the base page,
    if comp plan crteria is blank, this LOV works fine.
    if comp plan criteria has value: 2007 PTE COMP PLAN 1001
    I get this error:
    oracle.apps.fnd.framework.OAException: oracle.jbo.SQLStmtException: JBO-27122: SQL error during statement preparation. Statement: SELECT * FROM (select comp_plan_id,name from cn_comp_plans_all
    where sysdate between start_date and nvl(end_date,sysdate+1)
    and org_id =:1) QRSLT WHERE (( UPPER(NAME) like :2 AND (NAME like :3 OR NAME like :4 OR NAME like :5 OR NAME like :6)))
    Because '2007 PTE COMP PLAN 1001' has 5 tokens, the generated query automatically add 'Name' 5 times.
    Can anyone help?
    thanks
    Lei

    Complete error is:
    java.sql.SQLException: Invalid column type
    Exception Details.
    oracle.apps.fnd.framework.OAException: oracle.jbo.SQLStmtException: JBO-27122: SQL error during statement preparation. Statement: SELECT * FROM (select comp_plan_id,name,org_id from cn_comp_plans_all
    where sysdate between start_date and nvl(end_date,sysdate+1)
    and org_id = :1) QRSLT WHERE (( UPPER(NAME) like :2 AND (NAME like :3 OR NAME like :4 OR NAME like :5 OR NAME like :6)))
         at oracle.apps.fnd.framework.OAException.wrapperException(Unknown Source)
         at oracle.apps.fnd.framework.webui.OAPageErrorHandler.prepareException(Unknown Source)
         at oracle.apps.fnd.framework.webui.OAPageErrorHandler.processErrors(Unknown Source)
         at oracle.apps.fnd.framework.webui.OAPageBean.processRequest(Unknown Source)
         at oracle.apps.fnd.framework.webui.OAPageBean.preparePage(Unknown Source)
         at oracle.apps.fnd.framework.webui.OAPageBean.preparePage(Unknown Source)
         at oracle.apps.fnd.framework.webui.OAPageBean.preparePage(Unknown Source)
         at OA.jspService(_OA.java:75)
         at com.orionserver.http.OrionHttpJspPage.service(OrionHttpJspPage.java:59)
         at oracle.jsp.runtimev2.JspPageTable.service(JspPageTable.java:453)
         at oracle.jsp.runtimev2.JspServlet.internalService(JspServlet.java:591)
         at oracle.jsp.runtimev2.JspServlet.service(JspServlet.java:515)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
         at com.evermind.server.http.ServletRequestDispatcher.invoke(ServletRequestDispatcher.java:711)
         at com.evermind.server.http.ServletRequestDispatcher.forwardInternal(ServletRequestDispatcher.java:368)
         at com.evermind.server.http.HttpRequestHandler.doProcessRequest(HttpRequestHandler.java:866)
         at com.evermind.server.http.HttpRequestHandler.processRequest(HttpRequestHandler.java:448)
         at com.evermind.server.http.HttpRequestHandler.serveOneRequest(HttpRequestHandler.java:216)
         at com.evermind.server.http.HttpRequestHandler.run(HttpRequestHandler.java:117)
         at com.evermind.server.http.HttpRequestHandler.run(HttpRequestHandler.java:110)
         at oracle.oc4j.network.ServerSocketReadHandler$SafeRunnable.run(ServerSocketReadHandler.java:260)
         at com.evermind.util.ReleasableResourcePooledExecutor$MyWorker.run(ReleasableResourcePooledExecutor.java:303)
         at java.lang.Thread.run(Thread.java:595)
    ## Detail 0 ##
    java.sql.SQLException: Invalid column type
         at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:138)
         at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:175)
         at oracle.jdbc.driver.DatabaseError.throwSqlException(DatabaseError.java:240)
         at oracle.jdbc.driver.OraclePreparedStatement.setObjectCritical(OraclePreparedStatement.java:7895)
         at oracle.jdbc.driver.OraclePreparedStatement.setObjectInternal(OraclePreparedStatement.java:7572)
         at oracle.jdbc.driver.OraclePreparedStatement.setObjectInternal(OraclePreparedStatement.java:8183)
         at oracle.jdbc.driver.OraclePreparedStatement.setObjectAtName(OraclePreparedStatement.java:8206)
         at oracle.jbo.server.OracleSQLBuilderImpl.bindParamValue(OracleSQLBuilderImpl.java:3916)
         at oracle.jbo.server.BaseSQLBuilderImpl.bindParametersForStmt(BaseSQLBuilderImpl.java:3335)
         at oracle.jbo.server.ViewObjectImpl.bindParametersForCollection(ViewObjectImpl.java:13746)
         at oracle.jbo.server.QueryCollection.buildResultSet(QueryCollection.java:801)
         at oracle.jbo.server.QueryCollection.executeQuery(QueryCollection.java:666)
         at oracle.jbo.server.ViewObjectImpl.executeQueryForCollection(ViewObjectImpl.java:3655)
         at oracle.jbo.server.OAJboViewObjectImpl.executeQueryForCollection(Unknown Source)
         at oracle.apps.fnd.framework.server.OAViewObjectImpl.executeQueryForCollection(Unknown Source)
         at oracle.jbo.server.ViewRowSetImpl.execute(ViewRowSetImpl.java:742)
         at oracle.jbo.server.ViewRowSetImpl.executeQueryForMasters(ViewRowSetImpl.java:891)
         at oracle.jbo.server.ViewRowSetImpl.executeQueryForMode(ViewRowSetImpl.java:805)
         at oracle.jbo.server.ViewRowSetImpl.executeQuery(ViewRowSetImpl.java:799)
         at oracle.jbo.server.ViewObjectImpl.executeQuery(ViewObjectImpl.java:3575)
         at oracle.apps.fnd.framework.server.OAViewObjectImpl.executeQuery(Unknown Source)
         at oracle.apps.fnd.framework.server.OAViewObjectImpl.initQuery(Unknown Source)
         at oracle.apps.fnd.framework.webui.OAWebBeanHelper.setCriteriaOnVO(Unknown Source)
         at oracle.apps.fnd.framework.webui.OAListOfValuesHelper.processRequestAfterController(Unknown Source)
         at oracle.apps.fnd.framework.webui.OAWebBeanHelper.processRequest(Unknown Source)
         at oracle.apps.fnd.framework.webui.OAWebBeanContainerHelper.processRequest(Unknown Source)
         at oracle.apps.fnd.framework.webui.OAListOfValuesHelper.processRequest(Unknown Source)
         at oracle.apps.fnd.framework.webui.beans.layout.OAListOfValuesBean.processRequest(Unknown Source)
         at oracle.apps.fnd.framework.webui.OAWebBeanHelper.processRequestChildren(Unknown Source)
         at oracle.apps.fnd.framework.webui.OAWebBeanHelper.processRequestChildren(Unknown Source)
         at oracle.apps.fnd.framework.webui.OAWebBeanHelper.processRequest(Unknown Source)
         at oracle.apps.fnd.framework.webui.OAWebBeanContainerHelper.processRequest(Unknown Source)
         at oracle.apps.fnd.framework.webui.beans.OABodyBean.processRequest(Unknown Source)
         at oracle.apps.fnd.framework.webui.OAPageBean.processRequest(Unknown Source)
         at oracle.apps.fnd.framework.webui.OAPageBean.preparePage(Unknown Source)
         at oracle.apps.fnd.framework.webui.OAPageBean.preparePage(Unknown Source)
         at oracle.apps.fnd.framework.webui.OAPageBean.preparePage(Unknown Source)
         at OA.jspService(_OA.java:75)
         at com.orionserver.http.OrionHttpJspPage.service(OrionHttpJspPage.java:59)
         at oracle.jsp.runtimev2.JspPageTable.service(JspPageTable.java:453)
         at oracle.jsp.runtimev2.JspServlet.internalService(JspServlet.java:591)
         at oracle.jsp.runtimev2.JspServlet.service(JspServlet.java:515)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
         at com.evermind.server.http.ServletRequestDispatcher.invoke(ServletRequestDispatcher.java:711)
         at com.evermind.server.http.ServletRequestDispatcher.forwardInternal(ServletRequestDispatcher.java:368)
         at com.evermind.server.http.HttpRequestHandler.doProcessRequest(HttpRequestHandler.java:866)
         at com.evermind.server.http.HttpRequestHandler.processRequest(HttpRequestHandler.java:448)
         at com.evermind.server.http.HttpRequestHandler.serveOneRequest(HttpRequestHandler.java:216)
         at com.evermind.server.http.HttpRequestHandler.run(HttpRequestHandler.java:117)
         at com.evermind.server.http.HttpRequestHandler.run(HttpRequestHandler.java:110)
         at oracle.oc4j.network.ServerSocketReadHandler$SafeRunnable.run(ServerSocketReadHandler.java:260)
         at com.evermind.util.ReleasableResourcePooledExecutor$MyWorker.run(ReleasableResourcePooledExecutor.java:303)
         at java.lang.Thread.run(Thread.java:595)

  • Report Query with Bind variables working very slowly

    Hi everyone,
    I'm having a hard time with one of my Reports.
    Basically the query looks like this:
    Select *
    from x,y,z
    where x.lang_id = :P1_LANG
    and y.name = :P1_LANG;
    I have a textfield and a Select List on my Page which have to have a value before the report is shown.
    Now to the problem, when I input a value into these Application Items the Report takes ages (3-5 min). But when I replace the Bind variables (:P1_LANG and :P1_LANG) with the actual values it takes mere seconds.
    Anyone got an idea why this might be?
    I'm at my wits end -.-
    Edited by: DocD on Oct 27, 2009 3:01 AM

    Hi
    This could be for a number of reasons and unfortunately there is no quick answer...
    When you run a query for the first time, the execution plan is worked out by the Cost Based Optimiser (I'm assuming you're using 10g or above here). This is referred to as a hard parse. Next time the same SQL text is used then the execution plan may still be in the shared pool - in this case the same execution plan is used rather than being calculated again.
    The great thing about using bind variables is that even with different inputs, the SQL text is the same so the execution plan can be shared for different inputs. One downside is that if the first time the query is executed using bind variables, out of the ordinary values are input, bind variable peeking can lead to a sub optimal execution plan being calculated for the query and then shared in other situations (where more 'normal' values are input).
    However, it could be down to a host of other things too. So your first check is to make sure that you have executed both queries a number of times. If you are still getting the same performance issues then plan post the full query, table creation scripts and execution plan for both querys.
    Cheers
    Ben

  • 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;
    /

Maybe you are looking for

  • Wipe my phone number from Apple imessage server

    I need to wipe my phone number from the Apple iMessage server to when I receive messages from iPhone users the message isn't parsed into 5 or more separate messages.  I turned off FaceTime and iMessages on my old iPhone 4

  • Assignment field updation in Vendor document

    In vendor master, i have given sort key as Purchase Order(10).  I made MIRO against PO, but assignment field not updated with Purchase order number.  If i pay down payment against PO, for that document, Purchase order is updated.  But for MIRO it has

  • XML-RPC simple server

    I wan't to make a simple XML-RPC server. public class JavaServer      public JavaServer()      public static void main(String[] args)           try                WebServer server = new WebServer(8080);                server.addHandler("test", new Ja

  • Challenge of the day - "beginner" errors in SAP-delivered transactions

    1.  Read this post here: Question on SWUI_SINGLE and SWUI_START 2.  Name another SAP-delivered transaction that exhibits the same incorrect behavior as SWUI_SINGLE and SWUI_START. Note: Assume that the behavior of these transactions at this customer

  • How can I do to migrate mine old email from outlook to Mac ?

    I have years of mail that I do not want to loose, so I need to transfer from outlook to mail.....How can I do? Thx