Question number invalid where clause

Hello

I have the code snippet below fails with an ORA-01722 invalid number.
  select a.po_id, b.rb_mkstr_cd, a.insp_dt
  from Table1 a, Table2 b
   where  DECODE(SUBSTR(UPPER(a.PO_ID),1,1),'S','SP','U','SU','F','FA','H','HO') = b.Xse_Sesn_Cd (+)
    and     SUBSTR(LPAD(TRUNC((TO_CHAR(a.INSP_DT,'YY')+ 5 - SUBSTR(a.PO_ID,2,1))/10),2,'0'),2,1)||SUBSTR(a.PO_ID,2,1) = SUBSTR(CodeMsc.Xsn_Sesn_Yr_Rng(+),3,2)
SUBSTR(a.PO_ID,2,1))/10 
Select the portion of code where the arithmetic operation occurs has a null/empty character in the field of a.po_id, causing failure.

I tried to use the NVL function on the substr (a.po_id, 2, 1)) / 10, but that did not work.
Is there a work around to solve the error?

Hello

Change your code to

SUBSTR(Case When Instr(a.po_id,' ') > 0 Then Null Else a.po_id End,2,1))/10)

Hope this helps
Christian Balz

Tags: Database

Similar Questions

  • Case with where clause - ORA-00920: invalid relational operator

    Hi all, when I try to run the following query, I get the following error...

    ORA-00920: invalid relational operator

    00920 00000 - "invalid relational operator.

    * Cause:

    * Action:

    Error on line: column 16: 5

    Anyone know what the problem with my request? Thanks in advance.

    SELECT concat (year, period)

    OF DD_ACTUALS_FACT

    CASE WHERE period

    WHEN 'JAN' THEN '01'

    WHEN 'FEB' THEN '02'

    WHEN 'MAR' THEN ' 03 "

    WHEN "APR" THEN ' 04 "

    WHEN 'CAN' THEN ' 05 "

    WHEN "JUN" THEN '06'

    WHEN 'JUL' THEN '07'

    WHEN 'AUG' THEN '08'

    WHEN 'MS' THEN '09'

    WHEN 'OCT' THEN '10'

    WHEN 'NOV' THEN '11'

    WHEN 'DEC' THEN '12'

    END as number 'months '.

    ORDER OF CONCAT (year, number 'months') / / DESC

    The problem is the number 'month' - you cannot give an "ACE" alias for an expression in a where clause clause.

    You have not really given any condition, that a set of translations of period in a number.

    Also, you didn't say what you're trying to do.

    Maybe you want to:

    SELECT concat (year, period)

    OF DD_ACTUALS_FACT

    WHERE something

    ORDER OF CONCAT (year, period of the CASE

    WHEN 'JAN' THEN '01'

    WHEN 'FEB' THEN '02'

    WHEN 'MAR' THEN ' 03 "

    WHEN "APR" THEN ' 04 "

    WHEN 'CAN' THEN ' 05 "

    WHEN "JUN" THEN '06'

    WHEN 'JUL' THEN '07'

    WHEN 'AUG' THEN '08'

    WHEN 'MS' THEN '09'

    WHEN 'OCT' THEN '10'

    WHEN 'NOV' THEN '11'

    WHEN 'DEC' THEN '12'

    END DESC)

    /

  • ORA-01722: number not valid only in where clause

    I'm getting ORA-01722: invalid number when you use to_number in where clause:
    select to_number(txt_field) from tbl where 100>=to_number(txt_field);
    I don't get it without where clause (300 rows returned):
    select to_number(txt_field) from tbl;
    No logical explanation?

    Published by: totalnewby on February 21, 2012 04:54

    totalnewby wrote:
    No logical explanation?

    Let me guess - tbl is actually a point of view:

    SQL> create table tbl(code varchar2(10),val varchar2(10));
    
    Table created.
    
    SQL> insert into tbl values('string','abc');
    
    1 row created.
    
    SQL> insert into tbl values('number','123');
    
    1 row created.
    
    SQL> create or replace
      2    view tbl_vw
      3      as
      4        select  *
      5          from  tbl
      6          where code = 'number'
      7  /
    
    View created.
    
    SQL> select  to_number(val)
      2    from  tbl_vw
      3  /
    
    TO_NUMBER(VAL)
    --------------
               123
    
    SQL> select  to_number(code)
      2    from  tbl_vw
      3    where to_number(val) > 100
      4  /
    select  to_number(code)
            *
    ERROR at line 1:
    ORA-01722: invalid number
    
    SQL> 
    

    Reason is first selection from the first filters view (find out where clause) out of the non-numeric values and then only apply to_number. When the second select is run optimizer merges the view definition and where would adopt becomes:

    where where code = 'number '.
    and to_number (val) > 100

    Since there is no order of predicate, it happens that to_number (val) > 100 is applied first, and he obviously fails.

    SY.

  • Question about the order of evaluation of the clause WHERE CLAUSE when the Oracle OF the syntax used to join tables

    Hello

    Oracle version: 11.1.0.7.0 - 64 bit

    I read the documentation online at joins. The page is avialable here: joins at

    My question is about the join order of evaluation of the conditions in clause and the conditions of those

    are not the join conditions and are placed in the WHERE clause.

    Consider the following pseudocode

    SELECT

    T1. Col1,

    T2.Col1

    Of

    Table1 t1 LEFT OUTER JOIN table2 t2

    WE

    (condition_expression1)

    WHERE

    (condition_expression2)

    Is it correct to say that if there is no column on the status of join (condition_expression1) in condition_expression2, then condition_expression2 is executed before condition_expression1? In other words, oracle always trying to filter based on the WHERE clause individually each table as much as possible before joining them based on the conditions on the article?

    Thanks in advance,

    Hello

    dariyoosh wrote:

    Hello

    Oracle version: 11.1.0.7.0 - 64 bit

    I read the documentation online at joins. The page is avialable here: joins at

    My question is about the join order of evaluation of the conditions in clause and the conditions of those

    are not the join conditions and are placed in the WHERE clause.

    Consider the following pseudocode

    SELECT

    T1. Col1,

    T2.Col1

    Of

    Table1 t1 LEFT OUTER JOIN table2 t2

    WE

    (condition_expression1)

    WHERE

    (condition_expression2)

    Is it correct to say that if there is no column on the status of join (condition_expression1) in condition_expression2, then condition_expression2 is executed before condition_expression1? In other words, oracle always trying to filter based on the WHERE clause individually each table as much as possible before joining them based on the conditions on the article? ...

    The reverse is actually closer to the truth, but we can't really make general statements like that.

    SQL is not a language of the proceedings.  Looking at the code SQL, we could say that the code does, but we cannot say much about how that code it.  In other words, SQL is a language that describes the results you get, not the way to get them.

    The optimizer will do everything what he thinks is faster if it does not change the results.  If any order in which they are applied (in outer joins or CONNECT BY queries, for example), then think of the join is done first, and the value of the WHERE clause is applied to the result of the join.

    Here is a query looks very much like you posted:

    SELECT d.deptno

    e.ename, e.sal

    OF scott.dept d

    LEFT OUTER JOIN scott.emp e ON e.deptno = d.deptno

    WHERE e.sal > = 3000

    ORDER BY d.deptno

    ;

    Output:

    DEPTNO ENAME SAL

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

    10 KING 5000

    20 FORD 3000

    20 3000 SCOTT

    The scott.dept table contains deptnos 30 and 40; Why are they not in the result set?  The query behaves as if the outer join is made first (production 15 rows), then the WHERE clause has been applied.  All lines with deptno = 30 had sals down han 3000 and all single line with deptno = 40 was NULL in the sal column, then these lines are excluded (as well as other lines of deptnos 10 and 20), and only 3 lines above are left.

  • Question about WHERE Clause

    Hello

    I'm doing a conditional clause where clause displays the lines in a report.

    The desired control is date of two fields (CIC and announcement) must all be virgins or someone not be an 'Admin' (taken from a global variable stored on connection) for her to no display.

    Here's what I have:

    WHERE (DATACOLLECT. ANNOUNCEMENT_OF_DEAL_SIGN IS NOT NULL AND DATACOLLECT. CHANGE_IN_CONTROL IS NOT NULL) OR UPPER(:F19959_USER_ROLE) = "ADMIN".

    During the test of this query, it hides a field with ONE of the two dates being blank and which is not desirable.

    I also tried to write it like this and got an error of analysis for an invalid relational operator:

    WHERE (DATACOLLECT. ANNOUNCEMENT_OF_DEAL_SIGN AND DATACOLLECT. CHANGE_IN_CONTROL IS NOT NULL) OR UPPER(:F19959_USER_ROLE) = "ADMIN".

    Any help would be greatly appreciated. Please let me know if I need to clarify.

    I take what I said back.  Your requirement of "double negative" is odd

    DO NOT SHOW: where (X is null and Y is null)

    translates

    Show: where not (x is null and Y is null)

    WHERE NOT (DATACOLLECT. ANNOUNCEMENT_OF_DEAL_SIGN is null AND DATACOLLECT. CHANGE_IN_CONTROL IS NULL) OR UPPER(:F19959_USER_ROLE) = "ADMIN".

    MK

    PS - this is a thing of database.  PL/SQL and SQL would have been a better choice

  • have come to reinstall CS2, reached the error message "username, organization, number missing or invalid. where should I go from here?

    have come to reinstall CS2, reached the error message "username, organization, number missing or invalid. where should I go from here?

    CS2 (or earlier version) software activation server replacement... NOTE that CS2 will not install on a Mac "modern."

    l http://helpx.adobe.com/x-productkb/Policy-Pricing/Creative-Suite-2-activation-end-Life.htm

    When you install the special version of the PPro2 on a Win7 or Win8 or Win10 computer, you may need to right click on the program icon and select compatibility Windows XP in the popup of option

  • Question of WHERE Clause.

    All, I was just doing some checking at random and came across the following query

    SELECT * FROM emp WHERE +empno > 0;
    

    My question is that oracle runs the query above without any error. What is the use of such expressions in where clause and why the compiler does not throw error for these?

    I've never met such scenario. Just tried your query and it works. The reason is below.

    Look at what makes this request.

    SELECT - empno FROM emp;

    OUTPUT:

    -EMPNO
    ----------
    -7369
    -7499
    -7521
    -7566
    -7654
    -7698
    -7782
    -7788
    -7839
    -7844
    -7876

    -EMPNO
    ----------
    -7900
    -7902
    -7934

    14 selected lines.

    So you might see if you add a minus sign before the name of the column, it converts only for negative values.

    So, even if you add a sign "+", since these are positive values (> 0), your condition succeeds and gives the result. See what would happen if you used - empno in which your condition.

    SQL > SELECT * FROM emp WHERE empno - > 0;

    OUTPUT:

    no selected line

    Hope you clear how it works.

  • WHERE clause order ox performance question

    I do not understand order of execution of a WHERE clause, the use of a complex database

    I want to write a SELECT statement with the following condition

    ... WHERE (branch = 'main') AND (type = 1) OR (AND the costs-1 = 2).

    My question is

    < 1 > yoyu can use parentheses within a WHERE clause

    < 2 > how you would write such a clause as above if you cannot use parenthesis

    Thank you

    Hello

    Yes, you can have parentheses in a WHERE clause.
    I highly recommend to use when you need to use both AND and or in the same WHERE clause, since

    WHERE  (    x
            AND y
            )
    OR      z
    

    is not the same as

    WHERE   x
    AND     (   y
            OR  z
            )
    

    As others have said:

    ( charge -1 AND charge = 2 )
    

    will cause a compilation error.
    Here's the syntax valid and quite reasonable (although somewhat obscure):

    WHERE     (     branch = 'main'
         AND     type    = 1
         )
    OR          (     charge != -1
            AND     charge !=  2
         )
    
  • Where-Clause-Question by using "defined values.

    Hello

    I use 10 gr 2

    It is possible to filter the lines using sets of values in the where clause?

    As for example:
    SELECT a, b, c
      FROM mytable
      WHERE (b,c) IN
        (
          (3,4),
          (6,7),
          (9,1),
          (0,2)
        )
    .. must retrieve only the rows from myTable with sets (pairs) over the top of the list

    It is not difficult to test:

    with my_tab as (select 1 a, 2 b, 3 c from dual union all
                    select 2 a, 2 b, 2 c from dual)
    select * from my_tab
    where (b, c) in ((1,2), (2,3));
    
             A          B          C
    ---------- ---------- ----------
             1          2          3
    
  • Implementation of subqueries in the WHERE clause

    Hi all

    First of all, here are the technical info:

    Oracle JDeveloper 12 c 12.1.3.0.0

    Studio Edition Version 12.1.3.0.0

    Build JDEVADF_12.1.3.0.0_GENERIC_140521.1008.S

    Version of the component

    ========= =======

    Oracle IDE 12.1.3.0.41.140521.1008

    Java (TM) Platform 1.7.0_51

    Support versioning 12.1.3.0.41.140521.1008

    Secondly, the issue I'm facing is I'm trying to implement a query with three sous-sélections them in the (see image below) WHERE clause. I don't know what is the best way to implement something like this.

    I have implemented this by creating a display object and add a view criteria. I put the whole SQL fragment in the view as a literal value criteria. Is there a better (or best?) approach to implement something like this?

    This implementation is a problem is because as well as query tests out fine when I click on explain Plan even recognized that there is no bind variables in subqueries and allows me to.

    When I run this test by the tester of AM, that it fails to recognize and define the binding (projCategory) variable that appears only in subqueries. All your comments and/or help is very appreciated.

    Query.JPG

    Thank you

    Vladimir

    Vladimir, there is something wrong in the view Definition of criteria dialog box. The button "explain plan...". "running the whole statement generated (as a string) and returns the result. The entire statement is valid and returns the correct result. However, the view criteria, when it is running in the application work differently. Here the literal that you entered is not passed as a string, but the framework does something internally with her (it is necessary to do things as in the research of memory and other things). If you run the criteria to view in the app Tester I get

    SQL error in the preparation of the statement.  Instruction: SELECT Employees.EMPLOYEE_ID, Employees.FIRST_NAME, Employees.LAST_NAME, Employees.EMAIL, Employees.PHONE_NUMBER, Employees.HIRE_DATE, Employees.JOB_ID, Employees.SALARY, Employees.COMMISSION_PCT, Employees.MANAGER_ID, Employees.DEPARTMENT_ID from employees WHERE (((Employees.SALARY< :vc_temp_1="" )="" )="" )="" ):="" ora-01722:="" invalid="">

    Accordingly, for the display criteria

    employes.salaire< (select="" max(e2.salary)="" from="" employees="" e2="" where="" e2.department_id="">

    As you can see the literal is passed as: vc_temp_1 and my binding variable is not visible at all. You can open an SR and ask for the support of working on it. I guess that they do not see a bug here as help for the dialog box says:

    Literal

    Select when you want to provide a value for the attribute, or when you want to set a default value for a lookup field specified by the user for a search query-by-example form.

    When the criteria of view defines a search query for the user interface form, you can leave the field blank. In this case, the user will provide the value. Alternatively, you can provide a value that will act as a default value to the field search that the user will be able to substitute. This entry can include wildcards * or %.

    When the attribute is of type Date, specify the value of the date in the format YYYY-MM-DD; for example, to December 16, 2010, enter 2010-12-16.

    Here, it tells you that a value is expected. Your sub query is not interpreted, but is simply converted to the appropriate data type. In my example, I get an invalid number as expected.

    So I guess my suggestion to use a custom sql statement stands.

    Timo

  • Binds a parameter in WHERE clause throws error (ORA-00920)

    Good day to you all.  Hope everything goes well.

    Ok.  Here's the deal.  I am trying to bind a parameter in a where clause clause, but I continue to get the error invalid relational operator (ORA-00920).  It seems as if Oracle is looking for a correct syntax before you pass the variable (bind value).

    For example:

    SELECT LAST_NAME, FIRST_NAME FROM MYTABLE
    WHERE OBSOLETE IS NULL
    and :P_MY_BIND_VALUE
    

    What is the right way to get around this?

    Thanks for all your help!

    AquaNX4 wrote:

    Thank you for the reply.

    I use simple SQL.  The variable binding will be used in the APEX and an item that is based on a LOV with where condition stored there.  Make sense?

    Logic you want... doesn't have a sense of how you try to do.

    Bind variables are for the passage of the 'values' to a question, only not for the passage of the SQL statements or sections of objects such as the names of tables etc.  It is not a substitution string such as the use of '&' in SQL * more and should not be treated this way.

    If you could provide more details on exactly what you're trying to do (some data would help) then perhaps we could tell how best to go about this.

  • NVL selection list does not not on the place where clause in query

    Ok. APEX 4.2...

    Im having problems with my selection lists and NULL values... I see that it has come time and time again...

    I have a tabular presentation, with a query based on a selection list.  The selection list has the ability to '- Show All -'... The value of the selection list is a number, and the display is words...  (for reference the LOV query is: select status, batch from pmt_stat_lookup by 1)

    Initially I had problems with null and invalid numbers like ' display Null = 'Yes' and the problem of null % ', so have used the code in this blog to remove the NULL values... Display Null = & amp; #34; Yes & amp; #34; and the problem of null % | Inside Oracle APEX by Patrick Wolf

    Then in the application of my report, I have a where clause clause that checks the value of the selection list... WHERE batch = nvl(:P11_STATUS_SELECT,STATUS_ID)

    everything works almost fine, and I can choose a status, or I choose - see the All-, but the query will not include the lines where the State is null.

    (I also see that maybe I should be, use the case statement instead of the NVL on where clause, but not sure of the syntax. In addition, NVL was used somewhat in the different reports in the application...)

    For reference, the code of the old blog that I as a process page is:

    BEGIN

    FOR rItem IN

    (SELECT NOM_ELEMENT

    OF APEX_APPLICATION_PAGE_ITEMS

    WHERE APPLICATION_ID = TO_NUMBER(:APP_ID)

    AND PAGE_ID IN (TO_NUMBER(:APP_PAGE_ID), 0)

    AND LOV_DISPLAY_NULL = 'Yes'

    AND LOV_DEFINITION IS NOT NULL

    -change here

    AND LOV_NULL_VALUE = '% null | '%'

    )

    LOOP

    IF V (rItem.ITEM_NAME) = "% null | '%'

    THEN

    Apex_Util.set_session_state (rItem.ITEM_NAME, NULL);

    END IF;

    END LOOP;

    END;

    Thank you very much

    Richard

    Richard,

    Perhaps this example can help you solve your problem.

    https://Apex.Oracle.com/pls/Apex/f?p=63838:2

    Jeff

  • Very Urgent: Setting dynamic where clause for Popup list VO

    Hello world


    It is a very urgent requirement please help as soon as possible.


    I have a custom page in iSupplier. I created two supplier site, number of PO fields.

    Site of beg - choice of Message and PO number - Message LOV of entry


    I have a named VO under xxisupplier.oracle.apps.pos.home.poplist.server for site begging and xxisupplier.oracle.apps.pos.home.lov.server for PO number.

    I have joined these two VO AM homepage.




    Now the question is

    1. I want to restrict these VO vendor_id-based so I'll put dynamically where clause for these two VO of in my CO


    VO SITE PROVIDER QUERY


    SELECT POVs.vendor_site_code site, pov.vendor_id
    OF po_vendors pov, povs po_vendor_sites_all
    WHERE pov.vendor_id = povs.vendor_id
    AND TRUNC (povs.inactive_date) IS NULL


    PO NUMBER LOV QUERY VO


    SELECT DISTINCT ai.invoice_num, ai.vendor_id, ai.invoice_date, poh.segment1
    AI ap_invoices_all,.
    help ap_invoice_distributions_all,
    po_headers_all poh,
    po_distributions_all pda,
    Al ap_lookup_codes
    WHERE aid.po_distribution_id = pda.po_distribution_id
    AND ai.invoice_id = aid.invoice_id
    AND poh.po_header_id = pda.po_header_id
    AND ai.invoice_type_lookup_code = al.lookup_code
    AND al.lookup_type = 'INVOICE TYPE'


    I am creating where cluase as below in CO



    If (vendor_id1! = null)
    {
    System.out.println ("vendor_id:" + vendor_id1);
    OAViewObjectImpl vo = (OAViewObjectImpl) am.findViewObject ("PO_LOV_VO");
    if(vo!=null)
    {
    vo.clearCache ();
    VO. Reset();
    System.out.println ("inside IN. VO:" + vendor_id1);
    vo.setWhereClause (null);
    vo.setWhereClause ("vendor_id =: 1");
    vo.setWhereClauseParams (null);
    vo.setWhereClauseParam(0,vendor_id1);
    vo.setOrderByClause ("invoice_date DESC");
    String INVQRY = vo.getQuery ();
    System.out.println ("INVQRY:" + INVQRY);
    vo.executeQuery ();
    VO. First();
    System.out.println ("after the query appear" + vo.getRowCount ());
    }

    OAViewObjectImpl sitevo1 = (OAViewObjectImpl) am.findViewObject ("SUPPLIER_SITE_VO1");
    if(sitevo1!=null)
    {
    sitevo1.clearcache ();
    sitevo1. Reset();
    System.out.println ("Interior site:" + vendor_id1);
    sitevo1.setWhereClause (null);
    sitevo1.setWhereClause ("vendor_id =: 1");
    sitevo1.setWhereClauseParams (null);
    sitevo1.setWhereClauseParam(0,vendor_id1);
    String SITEQRY = sitevo1.getQuery ();
    System.out.println ("SITEQRY:" + SITEQRY);
    sitevo1. ExecuteQuery();
    sitevo1. First();
    System.out.println ("after the query appear" + sitevo1.getRowCount ());
    }



    Here he works for the purchase order number but the where cluase does not work for Supplier Site. Please help as soon as possible.


    2 and also if supplier site to return multiple values then this field should show as messagechoice. If it returns a single value, then it should be the style text message
    How can I achieve this.



    Thank you
    CSK

    Try

    vo.setWhereClause ("IN vendor_id (" + vendor_id_qry + ")" ");

    vendor_id_qry is the query that retrieves the list of provider IDS. You don't need to put the vendor column id as whereClauseParam unless you want to have IN the clause in your query of VO and pass the list as 1,2,3 values to the parameter.

    Thank you
    Shree

  • How to create a procedure for REF CURSOR output with any WHERE clause?

    I have a requirement like this: I have a huge question that need to reuse in my code over 10 times. This SQL has about 50 lines. Here for these 10 odd times sometimes changes in WHERE clause (columns are the same). So I can't create a view as SQL is not static.

    I thought to write a procedure with a para of WHERE_CLAUSE entry. I pulled out a refcursor sys by adding where clause. But I can't do it because you cannot add a clause like this where clause.

    i.e.
    PROCEDURE dynamyic_query (p_where_clause IN VARCHAR2, p_out_query OUT SYS_REFCURSOR ) IS
    BEGIN
    
      OPEN p_out_query FOR SELECT ......... FROM table WHERE || ' ' || p_where_clause;
    
    END;
    The foregoing gives an error.

    How to handle such a situation? Any help would be greatly appreciated.

    Hello

    Channa wrote:
    ... However, when I change the procedure like this:

    PROCEDURE FORMS_TEXT_DYN_SQL_TEST(p_where_cluase IN VARCHAR2, p_out_cursor OUT SYS_REFCURSOR) IS
    v_stmt VARCHAR2(1000);
    BEGIN
    v_stmt := 'SELECT tname FROM tab_test WHERE tname LIKE ''%ABS_V4%'' AND :y';
    
    OPEN p_out_cursor FOR v_stmt using p_where_cluase;
    
    END;
    

    And run this block of code:

    declare
    v_tname varchar2(200);
    out_cursor sys_refcursor;
    begin
    forms_text_dyn_sql_test(' 1 = 1 ', out_cursor );
    LOOP
    fetch out_cursor INTO v_tname;
    exit when out_cursor%NOTFOUND;
    DBMS_OUTPUT.PUT_LINE(v_tname);
    END LOOP;
    end;
    /
    

    I get the error:

    [1]: (Error): ORA-00920: invalid relational operator ORA-06512: at "ABS.FORMS_TEXT_DYN_SQL_TEST", line 6 ORA-06512: at line 5
    

    Looks like you can only set column_name =: z, column_name =: values of type y. You can not it seems to replace it with no WHERE CLAUSE?

    A bind variable, such as: it, represents a single value.
    If: is the VARCHAR2 '1 = 1', then

    SELECT tname FROM tab_test WHERE tname LIKE '%ABS_V4%' AND :y
    

    takes the value

    SELECT tname FROM tab_test WHERE tname LIKE '%ABS_V4%' AND '1 = 1'
    

    I think you want something like this:

    CREATE OR REPLACE PROCEDURE FORMS_TEXT_DYN_SQL_TEST
    (     p_where_clause      IN      VARCHAR2
    ,      p_out_cursor      OUT      SYS_REFCURSOR
    ) IS
      v_stmt VARCHAR2(1000);
    BEGIN
      v_stmt := 'SELECT ename FROM scott.emp WHERE ename LIKE ''%A%'' AND '
              || p_where_clause;
    
      OPEN p_out_cursor FOR v_stmt;
    
    END;
    /
    show errors
    
    SET  SERVEROUTPUT  ON
    
    declare
      v_tname varchar2(200);
      out_cursor sys_refcursor;
    begin
      forms_text_dyn_sql_test(' 1 = 1 ', out_cursor );
      LOOP
        fetch out_cursor INTO v_tname;
        exit when out_cursor%NOTFOUND;
        DBMS_OUTPUT.PUT_LINE(v_tname);
      END LOOP;
    end;
    / 
    

    Output:

    ALLEN
    WARD
    MARTIN
    BLAKE
    CLARK
    ADAMS
    JAMES
    
  • Trouble using a function in the where clause

    Hello

    I use a function that is located at ask.tom.oracle.com, which converts a long data type in a character. The function returns an error when it is placed in the where clause. The sql statement, the error message and the function of asking tom are listed below. Does anyone know how to fix this?


    < pre >

    SELECT A.FLDPHYSICAL,
    A.FLDEXPOSURE,
    A.FLDDATEDUE,
    A.FLDDATELAST,
    A.FLDEMPLOYEE,
    B.FLDBDATE,
    B.FLDMAILSTOP,
    B.FLDREC_NUM,
    B.FLDLNAME,
    B.FLDMI,
    B.FLDFNAME,
    B.FLDBDATE,
    B.FLDDEPT,
    B.FLDSTATUS,
    B.FLDSSN,
    B.FLDHOMEPHON,
    B.FLDWORKPHON,
    B.FLDID,
    B.FLDDIVISION

    OF REQEXAM,.
    B OF THE EMPLOYEE,
    C EMPLOYEE_MEMO
    WHERE A.FLDEMPLOYEE = B.FLDREC_NUM
    AND b.flduserstr = c.fldrec_num
    AND OHM_PKG. GET_LONG ('EMPLOYEE_MEMO', 'FLDDATA', C.ROWID) AS ' % CDL YES % '.
    "AND A.FLDDATEDUE > 1 January 1900"
    AND A.FLDPHYSICAL = 'COP '.
    ORDER OF B.FLDDIVISION,
    B.FLDLNAME,
    B.FLDFNAME,
    B.FLDMI,
    A.FLDDATEDUE

    -------------------------------------------------------------------------
    The error message

    Error in the command line: 26 column: 4
    Error report:
    SQL error: ORA-00904: "OHM_PKG." "" GET_LONG ": invalid identifier
    00904, 00000 - '% s: invalid identifier '.



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

    create or replace
    PACKAGE OHM_PKG AS

    / * TODO type (types, exceptions, methods etc.) package declarations here * /.
    getlong function (p_tname in varchar2, p_cname in varchar2, p_rowid in rowid) return varchar2;

    END OHM_PKG;

    create or replace
    PACKAGE BODY OHM_PKG AS

    getlong function (p_tname in varchar2, p_cname in varchar2, p_rowid in rowid) return varchar2 as
    whole l_cursor default dbms_sql.open_cursor;
    number of l_n;
    l_long_val varchar2 (4000);
    number of l_long_len;
    number of l_buflen: = 4000;
    l_curpos number: = 0;
    Start
    DBMS_SQL. Parse (l_cursor,
    "select" | p_cname | 'from ' | p_tname |
    ' where rowid =: x',.
    DBMS_SQL.native);
    DBMS_SQL.bind_variable (l_cursor, ': x', p_rowid);

    DBMS_SQL.define_column_long (l_cursor, 1);
    l_n: = dbms_sql.execute (l_cursor);

    If (dbms_sql.fetch_rows (l_cursor) > 0)
    then
    DBMS_SQL.column_value_long (l_cursor, 1, l_buflen, l_curpos,)
    (l_long_val, l_long_len);
    end if;
    DBMS_SQL.close_cursor (l_cursor);
    Return l_long_val;
    getLong end;

    END OHM_PKG;

    < / prev >

    Remove the '_' in the name of the function as below:

    AND OHM_PKG. GETLONG('EMPLOYEE_MEMO', 'FLDDATA', C.ROWID) AS "CDL % YES % '.

Maybe you are looking for