expression of the condition as a function?

Is it possible to put some checks in a function?

Example:
SELECT * FROM A WHERE A.x < 50 and A.x+A.y > 0 and A.y < p_variable;
As I will use a similar condition in many places (in a box) I look at what makes a function, something like this:
SELECT * FROM A WHERE func1(A.x, A.y, p_variable);
One problem is that a function cannot return a value of truth.

No idea how to approach this problem?

Kind regards
David

Looks like your function should return the subitem_code if the user has access to this subitem_code.
If he doesnot have the permission, the query should not return any result.

Then create your function like this, but remember that you will hit the fuction for each row of table A.

CREATE OR REPLACE FUNCTION fnc_check (p_user         IN access_table.USER%TYPE,
                                      p_permission   IN access_table.permission,
                                      p_subitemcode  IN access_table.subitem_code)
   RETURN access_table.subitem_code%TYPE
IS
   l_num   NUMBER := 1;
BEGIN
   SELECT DISTINCT 1
     INTO l_num
     FROM access_table
    WHERE USER = p_user
      AND permission = p_permission
       AND subitem_code = p_subitem_code;

   RETURN p_subitemcode;
EXCEPTION
   WHEN NO_DATA_FOUND
   THEN
      RETURN NULL;
END;

And your interior will be like this,

procedure p1(user_id in NUMERIC, query_parameter_1 IN NUMERIC, query_parameter_2 IN VARCHAR2, result out SYS_REFCURSOR)
IS
begin
    open result for
    SELECT A.*
    FROM A
    WHERE
        A.foo =  query_parameter_1
        AND
        A.bar LIKE  query_parameter_2
        AND
        A.subitem_code = fnc_check(user_id, 'READ_TABLE_A', A.subitem_code);
end;

G.

Tags: Database

Similar Questions

  • Query Oracle - to display the line in the Condition column in function.

    Hi all

    I have data like below.

    ID of ranking name Desc

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

    1             ID1          A              AA1

    2             ID1          A              AA2

    1             ID1          B              BB1

    2             ID1          B              BB2

    1             ID2          C              CC1

    2             ID2          C             CC2

    1             ID2          D             DD1

    2             ID2          D             DD2

    I need the query to retrieve the data as below.

    ID of ranking Name1 Name2

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

    ID1 1 A - AA1 B - BB1

    1 ID2 CC1 - C D - DD1

    That is to say) Condition: Grade must be 1.

    Thank you and best regards,

    Stéphane.

    with

    DATA_TABLE as

    (select 1 Rank, ID 'ID1', 'A' name, Descr "AA1" of union double all the)

    Select 2, 'ID1', 'One ', ' AA2' Union double all the

    Select 0, 'ID1', 'B', "BB1" dual union all

    Select 3, 'ID1', 'B', 'BB2' from dual union all

    Select 2, 'ID2', 'C', 'CC1' from dual union all

    Select 3, 'ID2', 'C', 'CC2' from dual union all

    Select 1, 'ID2', would be ', 'DD1"dual union all

    Select 3, 'ID2', would be ', 'DD2' from dual

    )

    SELECT id, Name1, name2

    go (select id,

    name_desc_rank,

    ROW_NUMBER() over (partition by order of identification by name_desc_rank) rn

    go (select grade,

    ID,

    name | '-' || descr | '-' || TO_CHAR (Rank) name_desc_rank,

    ROW_NUMBER() over (partition by order of rank identification) rn

    of data_table

    )

    where rn<=>

    )

    Pivot (Max (name_desc_rank) of rn (1 as name1, name2 2))

    ID NAME1 NAME2
    ID1 A-1 AA1 B-BB1-0
    ID2 C CC1-2 D DD1-1

    Concerning

    Etbin

  • How to calculate count them distinct (by xdoxslt:distinct_values) with an expression of the condition

    I have the XML data such as the following:

    < ListOfBipCustOptyProd >

    < CustOptyProd >

    < > 10000 loan < / Loan >

    Initial meeting < status > < / status >

    medium-sized < OptyCustomerType > < / OptyCustomerType >

    New client < OptyProdCustomerType > < / OptyProdCustomerType >

    < OptyId > 1 - ABCD < / OptyId >

    < / CustOptyProd >

    < CustOptyProd >

    < > 5000 loan < / Loan >

    < Status > close < / status >

    small business < OptyCustomerType > < / OptyCustomerType >

    Existing customer of < OptyProdCustomerType > < / OptyProdCustomerType >

    < OptyId > 1 - XYZ < / OptyId >

    < / CustOptyProd >

    < CustOptyProd >

    < > 80000 loan < / Loan >

    Initial meeting < status > < / status >

    medium-sized < OptyCustomerType > < / OptyCustomerType >

    New client < OptyProdCustomerType > < / OptyProdCustomerType >

    < OptyId > 1 - ABCD < / OptyId >

    < / CustOptyProd >

    < / ListOfBipCustOptyProd >

    I grouped the records of the State.

    I have the following formula in the Working Group:

    (to calculate the sum of all loans in the group where OptyCustomerType = 'SMEs' and OptyProdCustomerType = 'New client'

    <? amount (current-group () / Loan [.. / OptyCustomerType = 'Medium' and... / OptyProdCustomerType = 'New customer'])? >


    < to calculate the number of records in the group with a distinct value of OptyId
    <? count (xdoxslt:distinct_values(current-group()/OptyId))? >



    What I can't understand is the formula to calculate the number of records in the Group (where OptyCustomerType = 'SMEs' and OptyProdCustomerType = 'New customer') with a value separate from OptyId.  Someone knows how to write the expression?

    I tried the following, but it doesn't work:

    <? County (xdoxslt:distinct_values (current-group () / OptyId[.. / OptyCustomerType = 'Medium' and... / OptyProdCustomerType = 'New customer']))? >

    sth

  • Grouping and backreferences with regular expressions on the window to replace the text

    I'm really appreciate the inclusion of regular Expressions in the search and replace functionality. One thing miss me that East of backreferences in the replacement expression. For example, in unix tools vi or sed, I could do something like this:
     s/\(firstPart\) \(secondPart\) \(oldThirdPart\)/\2 \1 newThirdPart/g 
    that allow me to switch the places of first and secondPart and substitute totally thirdPart. If grouping and backreferences are already present in the window replace text, how do you properly call them?

    Published by: Justin.Warwick on August 23, 2011 08:26

    You can vote on the request for this to the exchange of SQL Developer, to add weight to the implementation as soon as possible: https://apex.oracle.com/pls/apex/f?p=43135:7:3693861354483465:NO:RP, 7:P7_ID:16761

    Kind regards
    K.

  • The difference between the expression and the function?

    Could someone please explain me the technical difference? For example, I know CAST is an expression and To_CHAR would be a function, but what differentiates the expressions of functions?

    Hello

    2776946 wrote:

    Could someone please explain me the technical difference? For example, I know CAST is an expression and To_CHAR would be a function, but what differentiates the expressions of functions?

    What is the difference between a bird and an OWL?  An OWL is a special type of a bird.  All owls birds, but not all birds are fun.

    Similarly, a function is a particular type of expression.  All functions are expressions, nut not all expressions are functions.

    In fact, the CAST is a function, but you're not wrong when you say "CAST is an expression.

    Maybe you wanted to say, not MOUNT.  CASE expressions are expressions, but not the functions.

    The technical difference between the functions and the other types of expressions has to do with how they are being implemented and is not all that important to users.  Is DECODE function?  It depends on which version you use.  The Oracle 6, it was a function; in Oracle 8, it wasn't; Since Oracle 9 it is again a function.  I don't know what has changed; Maybe the documentation.

  • How to define the condition in the analytic function

    Oracle 10g version

    Hi all

    I have the following data samples:

    Examples of data

    WITH DATA AS

    (

    SELECT 100 case_id, next_date, to_date('01-feb-2015','dd-mon-yyyy') UNION double, ALL crt_date to_date('01-jan-2015','dd-mon-yyyy')

    SELECT 100 case_id, next_date, to_date('01-mar-2015','dd-mon-yyyy') UNION double, ALL crt_date to_date('01-feb-2015','dd-mon-yyyy')

    SELECT 100 case_id, next_date, to_date('01-apr-2015','dd-mon-yyyy') UNION double, ALL crt_date to_date('01-may-2015','dd-mon-yyyy')

    SELECT 100 case_id, to_date('01-jun-2015','dd-mon-yyyy') next_date, to_date('01-apr-2015','dd-mon-yyyy') crt_date FROM dual

    )

    SELECT wagneur, MIN (next_date) OVER (PARTITION BY case_id) min_dt_analytical

    ,(

    SELECT MIN (next_date) DATA dd

    WHERE dd.case_id = d.case_id

    AND dd.next_date > crt_date

    ) min_dt_sub_query

    DATA d

    ;

    My question is that I get min_dt_sub_query using sub query but I want to use the analytical instead of query sub function so I created min_dt_analytical column, but I do not have how to give the condition that is AND dd.next_date > crt_date analytical so that I can get the same result as min_dt_sub_query data accordingly. Thanks in advance

    Concerning

    MIT

    Do not know if I understood your needs... but... something like that?

    WITH DATA AS (SELECT 100 case_id, next_date, to_date('01-feb-2015','dd-mon-yyyy') UNION double, ALL crt_date to_date('01-jan-2015','dd-mon-yyyy')

    SELECT the 100 case_id, next_date, to_date('01-mar-2015','dd-mon-yyyy') UNION double, ALL crt_date to_date('01-feb-2015','dd-mon-yyyy')

    SELECT the 100 case_id, next_date, to_date('01-apr-2015','dd-mon-yyyy') UNION double, ALL crt_date to_date('01-may-2015','dd-mon-yyyy')

    SELECT 100 case_id, next_date, to_date('01-apr-2015','dd-mon-yyyy') double crt_date to_date('01-jun-2015','dd-mon-yyyy'))

    SELECT d.

    MIN (next_date) OVER (PARTITION BY case_id) min_dt_analytical

    MIN(CASE WHEN next_date > crt_date THEN next_date ELSE NULL END) OVER (PARTITION BY case_id) AS min_dt_sub_query2

    DATA d;

    HTH

  • remove the conditional compilation expressions

    I created a RH7 project, and it has expanded to become the sole source of our company for the documentation of the user. It's a good thing. However, as I added information to different audiences, I'm done with a number of conditional compilation expressions I need is no longer. I would like to delete, so I don't have to search a long list on the general screen of WebHelp.
    I searched the forum and didn't see any information on the removal of the conditional compilation expressions (tags, yes; expressions, no). Can someone tell me how to proceed?
    Thanks for your help!

    Thank you! It did exactly what I had, so I'll mark this message as answered. Appreciate the quick response and all the information you have made available through the forum, as well as on your site!

  • Display of the conditional field of Apex Oracle

    Hello

    I created two Wizard page in Oracle Apex.

    I have a table point and item_detail. For element1, I have a record of detail and item2, I have two detail record.

    Step 1: Choose the section that will fall to the bottom of the roll of the order of the day.

    On step 2: based on the record number of detail items, I want to display the text on step 2 fields. If item1 is selected in display 1 thenl, textdisplay1, and textfield1 to step 2 step. If item2 is not selected ' will display textfield1, textfield2 to step 2, textdisplay1, textdisplay2.

    SQL/pl/sql condition will be: select count (*) in the item_detail where item_id in (select item_id station where nom_element = 'provided to the step 1 "

    I want this dynamic ability to display fields or at least to hide textdisplay2, textfield2 based on condition of sql/plsql.

    Thank you

    Fields / display items (or hidden) by the result of the 'Condition' selection on the page field specification APEX / point. (You have all the tabs at the top: Identification, UI, grid, Label,..., Condition,...) Condition determines whether the field is displayed. Defaults to '-point not conditional ' but if you click on the drop-down menu, there are different conditions of 30-50. There are, there's NO..., never, always. If you select "PL/SQL function body returning a Boolean", it will add an Expression 1 box in the GUI where you can write a "starting...". End; "block to return TRUE or FALSE for the condition. It display if TRUE is returned, skins, if FALSE is returned. (Someone other chime in here if I missed something.)

    It is a VERY characteristic slick of APEX. The only addiitons I could ask would be: positive, negative and "do what I mean".

    Howard

  • Offshoot of page based on the return value of function

    I have a combo box (P2008_SUPPORTING_MATERIALS) with 'Yes' and 'No' values.

    I need a button that will save the selected value, and then create a branch to the 1092 page if it of 'Yes' or branch to page 2094 if it is 'no '.

    That's what I did:

    1 create a SAVE button
    2. created a page process of type PL/SQL with function (see code below) inside (PageBranchDecision). The conditional processing I put him "when press button" for the "SAVE" button.
    3. create a branch of the page with a branch type of DIRECTION to the FUNCTION RETURN A PAGE. For the action of the branch, I put the name of the procedure on the page (PageBranchDecision). Because these are conditions, I defined him "when press button" on the "SAVE" button.

    This is the code for the page process:

    DECLARE
    whole n_page_id;
    v_sup VARCHAR2 (3);

    BEGIN
    v_sup: =: P2008_SUPPORTING_MATERIALS;

    IF v_sup = "Yes".
    THEN
    SELECT 1092 INTO double n_page_id;
    RETURN n_page_id;
    ON THE OTHER
    SELECT 2049 INTO double n_page_id;
    RETURN n_page_id;
    END if;

    END;

    Now, that's the problem... According to the 'Oracle HTML DB manual"page 294 books and ' easy Oracle HTML-DB' page 307, with the type of the branch of 'Branch to function returning a Page', a function PL/SQL is written which returns a digital page at junction id. In my code, it would be 'n_page_id '. But, when I run my page and click on my "SAVE" button I gives me an error that a RETURN statement cannot contain an expression.

    I don't know why I get this error. I need to get the value of the page to the branch based on the 'yes' or 'no '.

    Someone has an idea what I am doing wrong? My situation seems, as it is possible through the logic, I'm following?

    Thanks in advance,
    Maggie

    ch - ensure that any unconditional branch on the page has a largest number in sequence to ensure that this branch is triggered and ensure that there is no other branch that is triggered by the "SAVE" button

  • Ignore the condition AVERAGEIF referenced cell is empty?

    I'm trying to run an AVERAGEIF function based on up to 3 sets of test values whose conditions are determined by the entries in cells referenced in the formula.

    Here is a picture of the table:

    Seminar, day and hour are the columns from the drop-down list. Registered average and average archived have AVERAGEIF formulas that use the data in the table another as test values that resolves as true when they correspond to data in the corresponding cells of the seminar, day and hour [example: IFERROR (AVERAGEIF (seminar, Schedule::Registered, $Topic, $A2, $Days, $B2, hourly seminars: $B, $C2),' ')]. This set works fine if I have all three of the cells in the columns of seminar, day and time information, but I would like to also see average which which do not take into account (i.e., what are the averages for what seminar is offered Monday, regardless of what time?). Is it possible to get these formulas to ignore the conditions that are left in white?

    Thank you!

    AVERAGEIF accept them * and? wildcard characters.  You could try to enter * in the Time column and see if your formula returns desired results.  Without seeing the data format in your time table of the seminars, however, it is difficult to know if you need to make other adjustments to make it work.

    For example, you use Date & time format of data?  If so, numbers actually stores a date and time, even if you have a cell that is formatted to display only the time. This can give results, that you are not pregnant if you do not have two cells showing that same time can be interpreted by the numbers as being different, because the part of associated of the date string date and hour is different.

    SG

  • Click on the button conditional and alert when the condition is not met

    Hello

    I have a problem with the click of a button; in my form when the user clicks on a button I have to run the True action only if an element has the value; otherwise I would show an alert message like "enter value < element >...". ».

    It seems a simple problem, I tried to insert the condition "Is not null" and warning that the action of false, but it does not work.

    Who is the Apex way to solve?

    Thanks in advance.

    Cry

    1. replace the button URL type

    Code - javascript:validate();

    2. create a javascript function in the page function and declaration of global variables

    function validate()

    {

    If ($v ('YOUR_ITEM_NAME') == ")

    Alert ('XYZ');

    on the other

    Apex. Submit ('BUTTON_NAME');

    }

  • Is highest Null or more low value? using the fewest number of function...

    So Null is one of the if not the highest value in a list of values.

    Whenever I order a column, null has always been highest.

    However, when I use the function less

    Select * from bills by terms_of_discount desc;

    Select LESS ('2 ', '5', '12', ' 3', null) double;

    Select the LEAST ('apples', 'apps', 'applas', null) double;

    In both cases the null value is the lowest

    so I wonder why this is.

    As mentioned in oradocs:

    DESCRIPTION

    The Oracle/PLSQL LESS function returns the smallest value in a list of expressions.

    It's the greatest or least. As soon as you try to use the NULL value in a comparison, the answer is unknown.

    So, if you have NOTHING in there, the answer will be NULL.

    It goes the same for GREATEST().

    Global functions (SUM, MIN, MAX, etc) ignore NULL values.

    In ORDER BY, you can specify NULL FIRST or NULLS LAST.

  • Dynamic action with multiple values of PL/SQL Expression as a condition

    Hel

    I am currently using Apex 4.0 for a schoolproject.

    I have two selectlists (P8_BUSINESSRULETYPE - which has al businessruletypes) and (P8_OPERATOR) that has a select statement based on the businessruletype.

    I want to hide the selectlist operator when P8_BUSINESSRULETYPE = 7,8,9 and 10 or P8_OPERATOR = 9

    When: change

    SelectionType article (s)

    Elements P8_BUSINESSRULETYPE

    condition: equal to 10

    Real actions: hide items p8_operator

    False actions: show p8_operator items

    ConditionType PL/SQL EXPRESSION

    : P8_BUSINESSRULETYPE = 10 OR: P8_BUSINESSRULETYPE = 8 OR: P8_BUSINESSRULETYPE = 7 OR: P8_BUSINESSRULETYPE = 9

    What is the problem with my dynamic action? Because he does not hide the operatorfield when businessruletype 10 or 9 are selected in the selectlist. Sessions has also said operator = 9 and Businessruletype = 10

    I hope you guys can help out me.

    Thank you very much.

    2843640 wrote:

    Please update your forum profile with a real handle instead of '2843640 '.

    I am currently using Apex 4.0 for a schoolproject.

    I have two selectlists (P8_BUSINESSRULETYPE - which has al businessruletypes) and (P8_OPERATOR) that has a select statement based on the businessruletype.

    I want to hide the selectlist operator when P8_BUSINESSRULETYPE = 7,8,9 and 10 or P8_OPERATOR = 9

    When: change

    SelectionType article (s)

    Elements P8_BUSINESSRULETYPE

    condition: equal to 10

    Real actions: hide items p8_operator

    False actions: show p8_operator items

    ConditionType PL/SQL EXPRESSION

    : P8_BUSINESSRULETYPE = 10 OR: P8_BUSINESSRULETYPE = 8 OR: P8_BUSINESSRULETYPE = 7 OR: P8_BUSINESSRULETYPE = 9

    What is the problem with my dynamic action? Because he does not hide the operatorfield when businessruletype 10 or 9 are selected in the selectlist. Sessions has also said operator = 9 and Businessruletype = 10

    The first thing is that a Condition that is applied to a control of dynamic action if the dynamic action is made the see page. She has therefore no impact on the question of whether the actions of true or false are performed. Control conditions which are those defined in the when the properties of the dynamic action. As they are evaluated in the browser, they must be specified as JavaScript.

    Secondly, this expression is not valid because it is a space between the colon and the identifiers. Link the names of rating, the colon and the variable element must be contiguous:

    :P8_BUSINESSRULETYPE = 10 OR :P8_BUSINESSRULETYPE = 8  OR :P8_BUSINESSRULETYPE = 7 OR :P8_BUSINESSRULETYPE = 9
    

    However the latter is only of academic interest, in this case you need to remove the condition of dynamic action.

    In the dynamic of change when action section, P8_BUSINESSRULETYPE, P8_OPERATOR, Condition of JavaScript Expressionand value to the value of the item (s)

       ($v('P8_BUSINESSRULETYPE') == '7')
    || ($v('P8_BUSINESSRULETYPE') == '8')
    || ($v('P8_BUSINESSRULETYPE') == '9')
    || ($v('P8_BUSINESSRULETYPE') == '10')
    || ($v('P8_OPERATOR') == '9')
    

    If you are using a browser that supported, this can be simplified to

       (['7', '8', '9', '10'].indexOf($v('P8_BUSINESSRULETYPE')) >= 0)
    || ($v('P8_OPERATOR') == '9')
    
  • Remove the conditional text

    In my text selected with two conditional text (red and green). I must remvoe the conditional text in red in the selected text

    How to do this

    Try this:

    (function removeConditionalText(/*Text*/tx,/*UIColor*/uiColor,/*bool=false*/STRICT)
    // -------------------------------------
    // Remove any text within tx having a uiColor condition applied.
    // (If STRICT is true, do not affect text undergoing multiple conditions.)
    {
        var ranges = tx.textStyleRanges,
            a = ranges.everyItem().getElements(),
            conds = ranges.everyItem().appliedConditions,
            i = a.length,
            t, c;
    
        while( i-- )
            {
            t = conds[i];
            if( STRICT && t.length != 1 ) continue;
            while( (c=t.pop()) && !(c=c.indicatorColor==uiColor) );
            if( c ) a[i].remove();
            }
    
    })(app.selection[0],UIColors.RED);
    

    @+

    Marc

  • The 2 field in the conditional form field validation

    I searched on this forum, but didn't come with anything. I need to package the field validation in a table on the value of another field in the form of tables. How do I refer to a field in the form of table in the Condition section?

    I like to use (in my example SPECIES are the domain I want as my conditional validation on):

    Condition type: PL/SQL
    Expression 1: SPECIES! = "NFSH.

    So I need to know how to run the SPECIES matter in my tabular form in my conditional statement.

    Thank you!
    John

    What version are you on? 4.1 you can create validations of columns as a table and reference columns by using bind variables syntax, such as ": SPECIES.

Maybe you are looking for

  • How to export a project of photo slideshow to iDVD

    Hello.. I created a slide show of Photos & I would like to export to iDVD. My operating system is OSX El Capitan 10.11.1. After that I click export it has no option to take my iDVD project. Robyn cordially

  • How to draw 3D graphics

    Hello: Is there a way of using VS 8.0 under VB2005 3D graphics path? I want to get something like this:

  • Family Safety: could not connect to the site Web Family Safety - "try again later".

    I am connected to MSLive with my account, the same one that I am connected to help with this issue.  I also see my mailbox outlook.com, so that my account is active and works very well. When I go to familysafety.microsoft.com, the URL bar changes sev

  • How to fill the entire screen with the background color?

    It doesn't seem like it should be difficult, but of course, it seems to be. I put the background color on themy page, but it only fills half the screen in the Simulator. It's a small page. OK, so I went to some styles. I updated the style of the body

  • Deploy a UC520 in a 2003 network

    I have configured the UC520 and it works like a stand-alone charm. But now I wan't to deploy in our network where a windows 2003 server acts dhcp. I've read countless discussions on this forum but I do not know how to disable dhcp in the CPU and use