How to use a function in a Where Clause?

Hello
I have a doubt. If MY_FUNCT is a function that returns a Boolean value, can I use in a where clause clause to write a query like this? :

Select...
table one
where the...
*...*
and MY_FUNC (a.field) = true
*...*
*;*

Thank you!

Published by: Mark1970 on 3.27 lug-2-2010

But is it possible that the function does not return a Boolean value?

Yes (as sysdate, substr and instr etc.) you can also use your own function in a where clause clause, as long as it does not return a BOOLEAN value.

I mean how to use a function in a where clause clause?

Your own pseudocode seems a good example for me.
So, just give it a try.

Tags: Database

Similar Questions

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

  • How to use the instruction box in where clause

    Hi all


    I need to use cases where clause guide me please how I can do it.


    AND WHEN BOX: KAPCO = "KAPCO" THEN cla. CLASS_NAME LIKE '% KAPCO % '.
    WHEN: KAPCO = "NON_KAPCO" THEN SUPERIOR (cla. CLASS_NAME) NOT LIKE '% KAPCO % '.
    WHEN: KAPCO = 'ALL' GOLD: KAPCO IS NULL SO SUPERIOR (cla. CLASS_NAME) LIKE '% '.
    END



    Concerning

    Published by: user10941925 on March 4, 2012 22:31

    Hello

    CASE expressions return a single value, for example a VARCHAR2. They do refer to code fragments.

    You usually don't need (or want) an expression BOX in a WHERE clause, or any other condition. I think that you were trying to do the equivalent of:

    AND     (     (:KAPCO = 'KAPCO'          AND cla.CLASS_NAME       LIKE '%KAPCO%')     -- Don't you want UPPER on this line?
         OR     (:KAPCO = 'NON_KAPCO'           AND UPPER(cla.CLASS_NAME) NOT LIKE '%KAPCO%')
         OR     (NVL (:KAPCO, 'ALL') = 'ALL'       AND cla.CLASS_NAME IS NOT NULL)
         )
    

    If you would care to post some sample data (CREATE TABLE and INSERT statements) and the results desired from this data, I was able to test this.

  • How to use a function inside the package?

    Hello

    You will need to convert weight unit of kilogram kips when filling out the weight values into a temporary table. In our database, schema there is a function called convert_units is available.
    How could I use this feature in my package? My package is also resides in the same database schema.

    Here, I pasted the function.
         convert_units
       (
         in_base_unit_id       NUMBER,
         in_conversion_unit_id NUMBER,
         in_value              NUMBER
       ) RETURN NUMBER AS
    CURSOR unit_cur IS
      SELECT *
      FROM units_conversion
      WHERE base_unit_id = in_base_unit_id
        AND conversion_unit_id = in_conversion_unit_id;
    unit_rec unit_cur%ROWTYPE;
    BEGIN
      OPEN unit_cur;
      FETCH unit_cur INTO unit_rec;
      IF unit_cur%NOTFOUND THEN
        unit_rec := NULL;
      END IF;
      CLOSE unit_cur;
      RETURN (in_value+unit_rec.pre_adjust_add)*(unit_rec.rate);
    END convert_units;

    Hello

    It seems that the first two arguments of this function are ID in the units_conversion table. If you know this id = 1234 means kilograms, 9876 means kips, then you can do things like:

    wt_kips := convert_units (1234, 9876, wt_kilograms);
    

    or

    INSERT INTO tmp_table ( ..., weight_val,                               ...)
           VALUES           ( ..., convert_units (1234, 9876, wt_kilograms), ...);
    

    I can't just look at the code which could be any valid ID. I'm not even sure of the order of the arguments. I hope you have instructions on how to use the function.

    If the function is in a package named pk_xyz (a different package to the one in which you call it), add the name of the package, like this

    wt_kips := pk_xyz.convert_units (1234, 9876, wt_kilograms);
    
  • I use Windows 10 and use the Canon SX20 IS. How to use the function of Photo stich?

    I use Windows 10 and use the Canon SX20 IS. How to use the function of Photo stich?

    Is it possible to get the procedure to use feature stich photo?

    Will be Zoombrowser EX for windows 10 wotk?

    If any expert can guide me... that will be great.

    Hi Sat17,

    Thank you for your inquiry.

    For Windows 8 and beyond, ZoomBrowser EX has been replaced by EX. ImageBrowser

    Your software you will need to updated for Windows 10.

    You can access the software for your camera by clicking here.  Once on our site, scroll down to "Drivers and downloads", then use the drop down menu to choose "8.1 Windows" or "Windows 8.1 (x 64)".»  Your camera software has not been updated for Windows 10, but for Windows 8.1 software will run on your computer.

    To update your software, click the [Select] button to the right, then click on "How to download and install" for installation instructions.

  • How to use the functions of SetValue executeScript activity.

    Hello

    Could someone let me know how to use the function activity setValue (serialize concate, count etc) in activity executeScript. What all liberaries I need to import to executeScript. I want to perform the same task in executeScript performed in the setValue activity.

    Concerning

    Sunil Gupta

    Forgive me if I seem obtuse, but why would you use XPath functions (is that serialize, concat, and count) when there are perfectly good Java alternatives that will be much easier to use.  Java is, after all, the language used in the executeScript.  Serialize is just toString(), CONCATENATE is just + or. concat() (I assume that you are running on Java 6 web application server).  The count function is just the length() or size() methods or to the tables, the length property.  If you really need to reorganize in a variable of the XML data using a XSL stylesheet - you have access to all the functions in XPath 1.0 and XPath 1.0 power and you do not need to tinker with the headache of trying to debug Java in an environment (Workbench), which does not give you the tools that you would normally , as a contextual Editor.

  • How to use the function @RETURN for poster messages Essbase in 11.1.2.1

    Hello

    I found the business support Essbase Hyperion Planning 11.1.2.1 @RETURN rule novelty.

    If I create a simple BR for planning app like below:
    "@RETURN ("test return message,"WARNING);
    Validation returns error and BR can not be deployed.

    One is how to use the function @RETURN br?

    Thank you!

    He probably should be in a calco for example block

    "Profit".
    (
    ....
    )

    It is more likely to be used with an IF ELSE command, you do not want to define the condition for the calculation, roughly what the feature is designed for output.

    See you soon

    John
    http://John-Goodwin.blogspot.com/

  • call a function in a where clause of a select statement clause

    Hello

    is it possible to call a function in a where clause of a select statement clause?

    ex: select col1, col2
    from my_table
    where my_package.my_function (32199, 2008, col3, 'P');

    and I have the error message ' ORA-00920: invalid relational operator.

    FUNCTION ma_fonction (v_matricule in NUMBER,
    v_Year in NUMBERS
    T_DATE IN a DATE,
    v_type in DEFAULT CHAR 'P')
    RETURN A BOOLEAN VALUE;

    @+ Rosagio

    Yes, it is possible.

    But you have no relational operator:

    where my_package.my_function (32199, 2008, col3, 'P') =?
    where my_package.my_function (32199, 2008, col3, 'P') >?
    where my_package.my_function (32199, 2008, col3, 'P')<>

    Oops, I just noticed that your function returns a Boolean value.

    Can't do that as in a SQL statement.

    Boolean is known only to other code PL/SQL, no SQL statements.

    Published by: SomeoneElse on November 7, 2008 09:24

  • How to use BETWEEN function in calculation discoverer report?

    Hello

    I need discoverer report to:

    All part_numbers between SDK00 and SDK99 should have calculation (Pay_amount + 100)

    SQL for this is: PART_NUM between 'SDK00' and 'SDK99 '.

    * How can I get the function BETWEEN in Discoverer report level calculation in Discoverer Desktop or discoverer more? *

    Thanks in advance,
    Gayatri

    Published by: cool gayatri on June 24, 2009 08:32

    Hi Gayatri

    Did you not see my answer for the CASE because the CASE offer the use of the clause BETWEEN, but DECODE indeed does not work. Let me give you a quick summary of DECODE.

    In its simplest form, it takes 4 values and looks like this: DECODE (A, B, C, D)

    This basically means, IF A = B THEN C D OTHER

    The trick to solve ENTERS a DECODING is to work on algoriths where A = B. Because we do not know how values are from 00 to 99, although I could tell there were 100 we would of course 100 pieces in DECODING, but that would be awful. How about if we look at it another way and say this:

    IF PART_NUMBER< 'sdk00'="" then="">
    ELSE IF PART_NUMBER > 'SDK99' DO pay_AMOUNT
    ANOTHER pay_amount + 100

    This statement was only 2 hard coded values, but how do you DECODE work with less of? Easy, we use the function LESS. The LEAST function takes 2 values and returns the one with the lowest value. So I use LESS (PART_NUMBER, 'SDK00'), then whenever the PART_NUMBER is lower than SDK00 it will be true. A similar situation exists for the inverse function more GRAND. Put it all together, then you can do this:

    DECODE (PART_NUMBER, BIGGER (PART_NUMBER, 'SDK00'), DECODE (PART_NUMBER, LESS (PART_NUMBER, 'SDK99'), PAY_AMOUNT * 100, PAY_AMOUNT), PAY_AMOUNT)

    In English it can be read as follows:

    IF the PART_NUMBER is greater than or equal to SDK00 and the PART_NUMBER is less than or equal to SDK99 THEN PAY_AMOUNT x 100 ELSE 0

    Best wishes
    Michael

  • How to use the functionality of search in Spotlight

    I was check preferences, Spotlight and noted down at the bottom of the window there is a box marked 'allow Spotlight Suggestions in Spotlight and look it up".

    I was curious about the 'Look up' and how it worked but after Googling it I couldn't find any reference to it or how to use it.

    I wonder if someone could enlighten me on what it does and how I use it.

    Thank you

    'Search' is not a feature turned on. If you have this box checked, then it is already working.

    The difference between the projectors now and Spotlight before "Look up", it's that Spotlight will now search the Internet for items that you put in the Spotlight. Previously, Spotlight search only files of your computer. Now (with the upward gaze) research in Spotlight is similar to an iOS devices. If she can not find what you are looking for on your computer, it will search the internet. For example, if I type in warriors, it returns this information:

    Hope that makes sense

    EDIT: Note that research first of all my events (since I'm a Kings fan, it shows their game against the warriors), and he then proceeds to the internet looking for other options, as well as iTunes for the film the warriors.

  • How to pass a value LOV to where clause of another LOV

    Hello

    I have the two LOV project and activity. When I select a value of project LOV this value project to switch to the 2nd activity LOV where clause. How can I achieve this.

    I tried to use the code in the process CO request by getting the value of project with the command below.

    int v_project = Integer.parseInt ((String) passiveCriteria.get ('Project')); grab the critirea project

    and set this value in the setwhereclauseparams of the VO LOV. But the above command is throwing an exception with the exception of null pointer.

    This approach is correct, or should I use any other method.

    Thank you
    HC

    Below you will find the article interesting

    http://oracleanil.blogspot.com/2010/12/dependent-lov-in-OAF.html

    Thank you
    AJ

  • How to set SQL that contains 'in' where clause in VO?

    I don't want to set "in" would adopt a kind of programatical in VO as below. I want to use a method declariable to set in the clause using bindings varaible.

    It can be implemented?

        private String getInClauseWithParamNames(List termCodes) {
               //logic to form the in clause with multiple bind variables
               StringBuffer inClause = new StringBuffer(); 
               if(termCodes !=null){
                   for (int i = 1; i < termCodes.size() + 1; i++) { 
                       inClause.append(":termC" + (i));
                       if (i < termCodes.size()) { 
                          inClause.append(","); 
                       } 
                   }
               }
               return inClause.toString();
        }
            
        public Row[] getYardFixedSlots(List termCodes) {
            if(termCodes != null && !termCodes.isEmpty()){
                String inClause = getInClauseWithParamNames(termCodes);
                //setting the where cluase to use the generated in clause
                this.setWhereClause("YardFixedSlot.TERMINAL_C in (" + inClause + ")");
                ////clearing all existing where clause params if any 
                this.setWhereClauseParams(null);
                if(getVariableManager() !=null){
                   this.getVariableManager().clearVariables();
                }
                //setting values for all bind variables one by one in the in clause
                for (int i = 0; i < termCodes.size(); i++) { 
                    //defining the named bind variables programatically 
                    this.defineNamedWhereClauseParam("termC" + (i + 1), null, null);
                    //setting the value for each named bind variable 
                    this.setNamedWhereClauseParam("termC" + (i + 1), termCodes.get(i)); 
                }
                this.setRangeSize(-1); 
                //executing the query 
                this.executeQuery(); 
            }
            //returning the rows from query result 
            return this.getAllRowsInRange(); 
        }
    

    You can only use the link as a parameter to the in clause. You must divide the string inside the binding variable. Sample can be found at decompilation binary ADF: using bind variable for SQL statements with the paragraph

    Timo

  • How can I extract a substring in WHERE Clause &lt; CFQUERY &gt;?

    Is it possible to extract a substring in the WHERE clause of either < CFQUERY > or in a query of queries?  I try to use the following query to find all e-mail addresses with the domain "comcast.net" (i.e., everything that follows the '@' in the email address).  I ask an MS-Access database table.

    < cfquery name='test' datasource='membership'>
    SELECT Email_address
    OF tblMembers
    WHERE the MID (email_address, INSTR (email_address, ' @') + 1) = "comcast.net"
    < / cfquery >


    If I try this as a query, I get the error message "[Macromedia] [SequeLink JDBC Driver] [ODBC Socket] [Microsoft] [ODBC Microsoft Access driver] data type incompatible in criteria expression."


    If I try it as a t/t, I get the error message " " Met 'MID (e-mail1.,. Incorrect conditional expression, waiting for one of [as | null | between | in | comparison] condition,'.

    I would be very grateful for any help on finding something that works!  Thanks for your help!


    You couldn't do a LIKE in where clause instead:

    SELECT Email_address

    OF tblMembers

    WHERE email_address LIKE ' %@comcast.net'

    You should get the addresses you're looking for.

    -Carl V.

  • Using the Case statement in Where clause with operator

    Hi all

    I'm doing the following work (this is just a simple version of what I'll eventually need):

    Sorry, I forgot how to use the code tags...

    and li. MAJOR_ACCT in case
    When: prompt = 'Energy' then ('9320906 ', ' 9321471')
    end


    Problem is that I get a missing closing parenthesis error.

    Wouldn't - that evaluate against a value(as below) it works fine:

    and li. MAJOR_ACCT in case
    When: prompt = 'Energy' then ('9320906')
    end


    Any thoughts? Is it possible to use a box (or decode) in an In clause with multiple values? I tried to use decode as well and get the same results.

    Thank you.

    Darren.

    What:

    and ( case
            when :prompt = 'Energy' and li.MAJOR_ACCT in ('9320906', '9321471') then 1
            when :prompt = 'Vehicle' and li.MAJOR_ACCT in ('9812180', '9812320')  then 1
            when :prompt = 'Meals' and li.MAJOR_ACCT in ('983120', '983452') then 1
          end
        ) = 1
    
  • No output for report of XML editor using CASE/DECODE in a Where Clause

    Hello

    I have a requirement of the company to modify an existing report that has two input parameters,
    -> p_statcode (closed status) which may have values "Y" or "n".
    -> p_overdue (flag late), which can have values of "Y" or "n".

    The flag late is a column evaluated with O/N values and it is evaluated as follows,
    ONTF_MOD_VAL(NVL (
                                         (TRUNC (SYSDATE)
                                          - (TO_DATE (oe_order_lines.attribute18,
                                                      'DD-MON-RRRR')
                                             + TO_NUMBER (fnd_lookup_values.meaning))),
                                         0
                                      ))
                            overdue_flag
    The requirement of user now is that they must be a third option for setting called p_overdue ALL,
    which by the way the output should include records with
    p_statcode is p_statcode ELSE is N AND Y OR p_overdue p_overdue is N

    In other words records with raising the Y and N for flag late must be returned regardless of the value given to the closed state.

    Original where clause contained in the data definition file is as follows,
    WHERE Closed_Status = nvl(:p_statcode,Closed_Status)
                       AND overdue_flag = nvl(:p_overdue,overdue_flag)
    My modified code is the following,
    WHERE   Closed_Status = NVL (:p_statcode, Closed_Status)
             AND overdue_flag = (CASE
             WHEN :p_overdue = 'Y' THEN 'Y'
             WHEN :p_overdue = 'N' THEN 'N'
             ELSE overdue_flag
             END)
    OR
    WHERE   Closed_Status = NVL (:p_statcode, Closed_Status)
             AND overdue_flag = DECODE (:p_overdue, 'Y', 'Y', 'N', 'N',overdue_flag)
    Both approaches have the same problem.
    The output is in EXCEL format. The modified query works very well for p_overdue as Y or N but when p_overdue is passed as ALL he returned a blank EXCEL sheet with just exit report column headings.
    Any help regarding, why is this the case? What's not in my approach?

    Kind regards
    Vishal

    unclear on p_overdue = ALL
    P_overdue = ALL on what necessary values?

    try sth like

    WHERE   Closed_Status = NVL (:p_statcode, Closed_Status)
    AND (
       overdue_flag = DECODE (:p_overdue, 'Y', 'Y', 'N', 'N',overdue_flag) and :p_overdue != 'ALL'
       or
      :p_overdue = 'ALL' and (overdue_flag = 'Y' or overdue_flag = 'N')
    )
    

    for overdue_flag, which has more then 'Y' values of "n".
    If overdue_flag that in ('Y', ' don't) then

    WHERE   Closed_Status = NVL (:p_statcode, Closed_Status)
    AND (
       overdue_flag = DECODE (:p_overdue, 'Y', 'Y', 'N', 'N',overdue_flag) and :p_overdue != 'ALL'
       or
      :p_overdue = 'ALL'
    )
    

Maybe you are looking for

  • I can't see Komplete in the library update and cannot see a window of plugin

    Hello I am trying to load third-party plugins in Mainstage 3 like Komplete, V-Station, Sylenth, etc... I do not see these plugins anywhewre, texts or patches to THE, and the menu to view the Plugins simply has nothing, not even in the background of t

  • How can I add a name to my address book?

    I can't find a way to add a new contact in my address book.

  • Upgrade memory of satellite S2450-S203

    Really appreciate it if you could help. I have a laptop perfect condition except it has only 512 MB of RAM. I tried to take part to upgrade, but I was not able to find where memory and I can't remove a plus. I took every screw out, I can find, but th

  • Satellite L735-11 d - repair windows 7 OS through the recovery

    Hey No way to repair my windows 7 OS without formatting my laptop I want to just install a new copyfiles of windows 7 without losing my files and programs? Windows vista has this option called repair that work like this hope that someone will help :(

  • New Airport extreme can't see printer

    I have a new Airport Extreme with an external hard drive and printer, but all of a sudden the printer to stop working with a "printer not connected" message. The reader and the printer are connected through a powered USB hub. What is the problem?