count all values with a special WHERE clause in a select group?

Hello

I have the following table 1:

code, month, value
* 1,1,40 *.
* 1,2,50 *.
* 1,3,0 *.
* 1,4,0 *.
* 1,5,20 *.
* 1,6,30 *.
* 1,7,30 *.
* 1,8,30 *.
* 1,9,20 *.
* 1,10,20 *.
* 1,11,0 *.
* 1,12,0 *.

* 2,1,10 *.
* 2,2,10 *.
* 2,3,20 *.
* 2,4,20 *.
* 2,5,20 *.
* 2,6,30 *.
* 2,7,40 *.
* 2,8,50 *.
* 2,9,20 *.
* 2,10,20 *.
* 2,11,20 *.
* 2,12,20 *.


This is a table with 3 columns, first column is a code, second is the number of months, third, one is a value.
Now, I want to select records for each code. For example, all records for the code = 1.
I want to count how many values = 0 for this code = 1. After this count, I want to update the value with the number 0.

For my example:
Code 1, there are 4 fields with the value 0. So, I want to update all values from code 1 to 4.
The second code = 2 there is no value = 0. So, I want to update the values of code2 to 0.

This should be the result:
code, month, value
* 1,1,4 *.
* 1,2,4 *.
* 1,3,4 *.
* 1,4,4 *.
* 1,5,4 *.
* 1,6,4 *.
* 1,7,4 *.
* 1,8,4 *.
* 1,9,4 *.
* 1,10,4 *.
* 1,11,4 *.
* 1,12,4 *.

* 2,1,0 *.
* 2,2,0 *.
* 2,3,0 *.
* 2,4,0 *.
* 2,5,0 *.
* 2,6,0 *.
* 2,7,0 *.
* 2,8,0 *.
* 2,9,0 *.
* 2,10,0 *.
* 2,11,0 *.
* 2,12,0 *.


My question is:
Is it possible in oracle to count in a select (or in an insert/update statement) all values = 0 for a group (in this example, named code) and make an update in the same statement for this group?

I hope someone can give me a hint, if possible?

Thank you very much.
Best regards


Tim

something like that? NOT TESTED *.

Setting a DAY Table1 a SET A.Value = (SELECT COUNT (B.ROWID) FROM Table1 B WHERE A.Code = B.Code AND B.Value = 0);

Tags: Database

Similar Questions

  • Materialized view does not quickly refresh with sysdate in where clause

    Hi all

    I am trying to create a view, materialized with sysdate in where clause. This makes the complex query, and so I can't create a quick refreshment mview.

    I tried to create with rowid too, but it does not create a quick refreshment.

    I was wondering if someone can advise me, how can I accomplish this task, which would be really appreciated.

    The query is:

    create a materialized view PS_MEETING

    build the DEFERRED payment

    Refresh quickly with rowid

    as

    SELECT *.

    MEETING M

    WHERE state_desc = 'VIC '.

    OR Meet_date < TRUNC (SYSDATE);

    the behavior is documented: http://docs.oracle.com/cd/E11882_01/server.112/e25554/basicmv.htm#DWHSG8201

    General restrictions on update quickly

    The definition of the materialized view query is limited as follows:

    • The materialized view must not contain references to non-repetitive phrases such as SYSDATE and ROWNUM .

    So I guess that you would need a more static than sysdate condition - or another strategy update.

  • 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

  • Oracle OFA customization list of values (LOV) mapping in Where clause with variables

    Hi all

    I have a requirement to add the condition of the UOM LOV I don't understand under conditions in LOV for example mcc.inventory_item_id =: 1 what: 1 means? and how the system look at the value in: 1? if I have to add the condition to the middle which number should I use?

    SELECT * FROM (SELECT distinct muc.unit_of_measure unit_meas_lookup_code, muc.unit_of_measure_tl unit_meas_lookup_code_tl, muc.description, muc.uom_class, muom.uom_code FROM mtl_uom_conversions_val_v muc, mtl_units_of_measure muom WHERE (muc.uom_class IN (SELECT mcc.to_uom_class CMC mtl_uom_class_conv_val_v WHERE mcc.inventory_item_id =: 1) muc.uom_class = GOLD: 2), AND (muc.item_id =) ((: 3 GOLD muc.item_id = 0) AND muc.unit_of_measure = muom.unit_of_measure) QRSLT WHERE ((UPPER (UNIT_MEAS_LOOKUP_CODE_TL) like UPPER(:4) AND (UNIT_MEAS_LOOKUP_CODE_TL like: 5 OR UNIT_MEAS_LOOKUP_CODE_TL as: 6 OR UNIT_MEAS_LOOKUP_CODE_TL as: 7 OR UNIT_MEAS_LOOKUP_CODE_TL as: 8))) ORDER BY upper (unit_meas_lookup_code)

    LOV.png

    Concerning

    A.S.

    Hey A.S.,.

    Looking more closely at the image you included, it seems that it is already a custom code, it starts with "Xx".  You should see if you have the available custom code.

    To answer part of your original question ""mcc.inventory_item_id =: 1 what: 1 means? ' " The ': 1 ' is a variable binding in the SQL code.  This value is populated at run time by using the "setWhereClauseParam (Bind number, value).  You can see the details of the request and the variable linking using JDeveloper and a double-tap on the View object.  Again, this should be in the custom code of the object View 'atco.oracle.apps.po.lov.server.XxDocumentUomBothVo '.

    I hope this helps.

    Thank you

    Tim

  • Group by, with and without where clause

    Do I need to use these two interior views to display the results by group by a line? I can get the same result without having to type the same statement select twice since these two SELECT statements differ only in where clause. This query is a simulation. My actual query is longer. My hope is to make this shorter query (without interior views).
    with tmp as (
    select 'COMPLETE' status, 'GERMANY' country, 0 substatus FROM dual UNION ALL
    select 'COMPLETE' status, 'GERMANY' country, 1 substatus FROM dual UNION ALL
    select 'COMPLETE' status, 'GERMANY' country, 0 substatus FROM dual)
    select v1.status, v1.country, v1.cnt01, v2.cntIncluding0 from 
    (select status, country, count(*) cnt01 from tmp tmp1 group by status, country) v1
    JOIN
    (select status, country, count(*) cntIncluding0 from tmp tmp2 where substatus=0 group by status, country) v2
    on v1.status=v2.status and v1.country=v2.country;
     

    totalnewby wrote:
    Do I need to use these two interior views to display the results by group by a line? I can get the same result without having to type the same statement select twice since these two SELECT statements differ only in where clause. This query is a simulation. My actual query is longer. My hope is to make this shorter query (without interior views).

    with tmp as (
    select 'COMPLETE' status, 'GERMANY' country, 0 substatus FROM dual UNION ALL
    select 'COMPLETE' status, 'GERMANY' country, 1 substatus FROM dual UNION ALL
    select 'COMPLETE' status, 'GERMANY' country, 0 substatus FROM dual)
    select v1.status, v1.country, v1.cnt01, v2.cntIncluding0 from
    (select status, country, count(*) cnt01 from tmp tmp1 group by status, country) v1
    JOIN
    (select status, country, count(*) cntIncluding0 from tmp tmp2 where substatus=0 group by status, country) v2
    on v1.status=v2.status and v1.country=v2.country;
    
    SQL> with tmp as
      2  (
      3  select 'COMPLETE' status, 'GERMANY' country, 0 substatus FROM dual UNION ALL
      4  select 'COMPLETE' status, 'GERMANY' country, 1 substatus FROM dual UNION ALL
      5  select 'COMPLETE' status, 'GERMANY' country, 0 substatus FROM dual
      6  )
      7  select status,
      8         country,
      9         count(substatus) cnt01,
     10         sum(decode(substatus, 0, 1, 0)) cntincluding0
     11    from tmp
     12   group by status, country
     13  ;
    
    STATUS   COUNTRY      CNT01 CNTINCLUDING0
    -------- ------- ---------- -------------
    COMPLETE GERMANY          3             2
    
  • Optimize query with function in where clause

    Hello

    I have a query like this:

    SELECT * FROM table_1 t
    WHERE
    (
    -- Clause A (very long clause that filters a lot of rows)
    )
    AND f(t.field) = 'Y' -- This function is heavy but it should filter few rows
    

    This query, it is very slow because I think he's trying to evaluate f() for all rows in table_1.

    Howerver, if I have database query:

    SELECT f(t.field) FROM table_1 t
    WHERE
    (
    -- very long clause that filters a lot of rows
    )
    

    It's very fast.

    How can I reference the query to filter the lines of division A, then by function?

    Thanks in advance!

    If you wrap the function in a select clause then the optimizer can use a scalar subquery caching:

    SELECT * FROM table_1 t 

    WHERE  (  -- Clause A (very long clause that filters a lot of rows)  ) 

    AND (Select f(t.field) From Dual) = 'Y' -- This function is heavy but it should filter few rows

  • Problem with the creation of date range with PL/SQL WHERE clause

    Hello, everyone:

    I'm unable to develop and the SQL statement to filter records today and seven days back. My condition is as follows:
     from  wsualumni.wsu_online_giving_table
           --where ALM_OG_ACTIVITY_DATE >= ALM_OG_ACTIVITY_DATE - 7
           where ALM_OG_ACTIVITY_DATE >= SYSDATE - 7
           and ALM_OG_CAMPAIGN_CODE = 'MED' 
           OR ALM_OG_CAMPAIGN_CODE = 'MED1';
    I think I'm to mess with the (to_char (ALM_OG_ACTIVITY_DATE, ' mm/dd/yyyy ' ")) statement.

    The actual code is below to:
    set serveroutput ON SIZE 1000000
    set heading off                
    set feedback off                
    set trimspool off               
    set echo off                    
    set pagesize 0                  
    
    DECLARE
        v_data_line_hdr      varchar2(1000);
        v_data_file          varchar2(80);
        v_sch_code            varchar2(10);
        v_instance_name       varchar2(10);
        ws_path            payroll.pybutfl.pybutfl_utl_file_path%TYPE; 
        v_data_line           VARCHAR2 (4000)                              := NULL;
        fhandle_o             UTL_FILE.file_type;
        v_line_count          NUMBER                                       := 0;
        v_selected_count      NUMBER                                       := 0;
        v_error_count         NUMBER                                       := 0;
        v_written_count       NUMBER                                       := 0;
        v_error_text          VARCHAR2 (50)       := ' Unable to write the line. ';
        v_errm                VARCHAR2 (255);
        v_sqlerrm             VARCHAR2 (255);
    
    
    CURSOR C1 IS
    
    select RTRIM
        (
        ALM_OG_ID                                           ||'|'||                                                                 
        NULL                                                ||'|'||   
        (to_char(ALM_OG_AMOUNT, '999,999.99'))              ||'|'||            
        'Cash'                                              ||'|'||             
        'Credit Card'                                       ||'|'||             
        (to_char(ALM_OG_ACTIVITY_DATE, 'mm/dd/yyyy'))       ||'|'||                    
        ALM_OG_ACCI_CODE                                    ||'|'|| 
        'On-Line Giving'                                    ||'|'||       
        'On-Line giving'                                    ||'|'||    
        ALM_OG_HONOR_MEM_NAME                               ||'|'||        
        NULL                                                ||'|'||   
        'Do not post'                                       ||'|'|| 
        'StandardThankYou'                                  ||'|'||  
        'Not Acknowledged'                                  ||'|'||        
        'Do not receipt'                                    ||'|'||      
        NULL                                                ||'|'|| 
        'Banner Gift Number'                                ||'|'|| 
        ALM_OG_BANNER_GIFT_NO ||'.'|| ALM_OG_ACCI_CODE      ||'|'|| 
        (to_char(ALM_OG_ACTIVITY_DATE, 'mm/dd/yyyy'))       ||'|'|| 
        NULL                                                ||'|'|| 
        'Web ID'                                            ||'|'|| 
        ALM_OG_WEBID                                        ||'|'|| 
        NULL                                                ||'|'|| 
        'Source'                                            ||'|'||  
        ALM_OG_CAMPAIGN_CODE                                ||'|'||
        'On-Line Giving'    ) data_line 
        
           
           from  wsualumni.wsu_online_giving_table
           --where ALM_OG_ACTIVITY_DATE >= ALM_OG_ACTIVITY_DATE - 7
           where ALM_OG_ACTIVITY_DATE >= SYSDATE - 7
           and ALM_OG_CAMPAIGN_CODE = 'MED' 
           OR ALM_OG_CAMPAIGN_CODE = 'MED1';
           
           
           
     CURSOR C2 IS
     
     select RTRIM(
                    'ConsID'        ||'|'||
                    'GFImpID'       ||'|'||
                    'GFTAmt'        ||'|'||
                    'GFType'        ||'|'||
                    'GFPayMeth'     ||'|'||
                    'GFDate'        ||'|'||
                    'FundID'        ||'|'||
                    'CAMPID'        ||'|'||
                    'GFAppeal'      ||'|'||
                    'GfRef'         ||'|'||
                    'GfPostDate'    ||'|'||
                    'GfPostStatus'  ||'|'||
                    'GfltrCode'     ||'|'||
                    'GfAck'         ||'|'||
                    'GfRcpt'        ||'|'||
                    'GfAttrlmpID00' ||'|'||
                    'GfAttrCat00'   ||'|'||
                    'GfAttrdesc00'  ||'|'||
                    'GfAttrDate00'  ||'|'||
                    'GfAttrlmpD01'  ||'|'||
                    'GfAttrCat01'   ||'|'||
                    'GfAttrdesc01'  ||'|'||
                    'GfAttrlmpID02' ||'|'||
                    'GfAttrCat02'   ||'|'||
                    'GfAttrdesc02'  ||'|'||
                    'GfSubType'      ) line_header      from DUAL;
                    
                    
    
    /**********************************************************************/
    /*                Main Program Processing                             */
    /**********************************************************************/
    
    BEGIN
    
    
    
    
    DBMS_OUTPUT.put_line ('Program Started in wsualumni.wsu_online_giving_online');
    IF UTL_FILE.is_open (fhandle_o)
        THEN   
       UTL_FILE.fclose (fhandle_o);
    END IF;
    
    /* Name The File Here */
    v_data_file := ('MED_SCH_' || TO_CHAR(sysdate, 'dd-MON-yyyy') || '_OG_DATA.txt');
    
    
    
    SELECT RTRIM (pybutfl_utl_file_path)
          INTO ws_path
          FROM payroll.pybutfl;
    
    
    
          fhandle_o := UTL_FILE.fopen (ws_path, v_data_file, 'w');
          DBMS_OUTPUT.put_line ('UTLFILE file for this run is: ' || ws_path||'/'||v_data_file);
          v_written_count := 0;   
          
          
        
    FOR c2_rec IN C2 LOOP
        BEGIN
            v_selected_count := v_selected_count + 1;
            v_data_line_hdr := rtrim(c2_rec.line_header);
            UTL_FILE.put_line (fhandle_o, v_data_line_hdr);
            v_written_count := v_written_count + 1;
    EXCEPTION
         WHEN OTHERS
          THEN
           DBMS_OUTPUT.put_line (v_error_text);
           v_error_count := v_error_count + 1;
        END;
    END LOOP;
    
    
    FOR c1_rec IN C1 LOOP
        BEGIN
            v_selected_count := v_selected_count + 1;
            v_data_line := rtrim(c1_rec.data_line);
            UTL_FILE.put_line (fhandle_o, v_data_line);
            v_written_count := v_written_count + 1;
        EXCEPTION
         WHEN OTHERS
          THEN
           DBMS_OUTPUT.put_line (v_error_text);
           v_error_count := v_error_count + 1;
        END;
    END LOOP;
    
         DBMS_OUTPUT.put_line ('Number of Records Selected: ' || v_selected_count);
         DBMS_OUTPUT.put_line ('Number of Records Written: ' || v_written_count);
    
          IF UTL_FILE.is_open (fhandle_o)
          THEN
             UTL_FILE.fclose (fhandle_o);
          END IF;
    
    
    
    
    END;
    /
    Results
    ConsID|GFImpID|GFTAmt|GFType|GFPayMeth|GFDate|FundID|CAMPID|GFAppeal|GfRef|GfPostDate|GfPostStatus|GfltrCode|GfAck|GfRcpt|GfAttrlmpID00|GfAttrCat00|GfAttrdesc00|GfAttrDate00|GfAttrlmpD01|GfAttrCat01|GfAttrdesc01|GfAttrlmpID02|GfAttrCat02|GfAttrdesc02|GfSubType
    000013505||      20.00|Cash|Credit Card|06/22/2009|221686|On-Line Giving|On-Line giving|||Do not post|StandardThankYou|Not Acknowledged|Do not receipt||Banner Gift Number|1179534.221686|06/22/2009||Web ID|000013505||Source|MED|On-Line Giving
    000013505||      20.00|Cash|Credit Card|06/22/2009|770830|On-Line Giving|On-Line giving|||Do not post|StandardThankYou|Not Acknowledged|Do not receipt||Banner Gift Number|1179534.770830|06/22/2009||Web ID|000013505||Source|MED|On-Line Giving

    Hello

    The problem is due to the "OR" condition (I did not pay attention to it earlier).

    Because of this condition, your query is given beyond 7 days recovery. You need to rewrite the code as:

    ALM_OG_CAMPAIGN_CODE in ('MED', 'MED1')
    

    Instead of

       and ALM_OG_CAMPAIGN_CODE = 'MED'
         OR ALM_OG_CAMPAIGN_CODE = 'MED1';
    

    This will do the magic for you.

    Concerning

    Asif Momen
    http://momendba.blogspot.com

  • Passing the value of the where clause with the page

    Dear friends,

    I have a requirement like when I select a selection list value I should pass this value to sql query where clause without submitting the page

    ex I have a select like: P1_Dept guess I selects the value 10 in this

    then I have a query select * from emp where deptno =: P1_Dept.

    DB. ORACLE 11G

    APEX 4.1.1.00.23

    is this possible? can someone help me please in this topic

    Thanks and greetings

    Vballeda

    Suppose we have the selection list with the name P1_DEPT and query for report

    select * from emp where deptno = :P1_DEPT
    

    We create dynamic Action on the evolution of the P1_DEPT point. We will need two real actions:

    1-> set value action

    Set the Type - > body of the PL/SQL function

    The function of body - > return 1;

    Page item to submit-> P1_DEPT

    Change to delete-> Yes event

    Selecttion Type-> trigger element

    2. action-> Refresh

    Selecttion Type-> region

    Region-> your region of report

  • Treat all values of parameter by bursting

    Hello

    I have a BI Publisher report with a statement where clause. When I try to run the break-up, I get an error "there is no data". If I select "All" in the Panel breaking I always get this message. Now when I run bursting, I remove the where the statement.

    How can I use burst without removing the where the release of my data model?

    Thnx!

    Marco

    You can try this

    When you choose the "NULL" value for your choice of all THE

    then

    WHERE "RAPPORTAGE_WINKEL" = nvl(:winkelnamen,RAPPORTAGE_WINKEL)

    When you choose the 'All' value for your choice of all THE

    then

    WHERE 'RAPPORTAGE_WINKEL' in (: winkelnamen)

  • Details on the order of columns in a Where Clause

    Hi All
    My both Quarries  are giving same record count .
    so  can  i say that the order of the columns("msib.inventory_item_id=pol.item_id" AND" pol.item_id=msib.inventory_item_id ") 
    in the where  clause doesn't effect the query result in any situation 
    {code
    }
    select count(*)
    from po_headers_all poh
       ,po_vendors pv
       ,po_lines_all pol
       ,po_line_locations_all pll
       ,mtl_system_items_b msib
    where poh.vendor_id = pv.vendor_id
    and poh.po_header_id = pol.po_header_id
    and pol.po_line_id = pll.po_line_id
    and pll.ship_to_organization_id = msib.organization_id ----------------1
    and msib.inventory_item_id=pol.item_id --------------------------2
    and poh.type_lookup_code = 'STANDARD'
    and pv.vendor_name = 'Star Gate Ltd'  
    group by 1
    
    select count(*)
    from po_headers_all poh
       ,po_vendors pv
       ,po_lines_all pol
       ,po_line_locations_all pll
       ,mtl_system_items_b msib
    where poh.vendor_id = pv.vendor_id
    and poh.po_header_id = pol.po_header_id
    and pol.po_line_id = pll.po_line_id
    and pol.item_id = msib.inventory_item_id  ----------------------------------2 
    and pll.ship_to_organization_id = msib.organization_id -----------------------------1 
    and poh.type_lookup_code = 'STANDARD'
    and pv.vendor_name = 'Star Gate Ltd'  
    Thank you

    Published by: vijay539 on November 20, 2009 09:17

    Published by: vijay539 on November 20, 2009 09:18

    Published by: vijay539 on November 20, 2009 09:19

    Published by: vijay539 on November 20, 2009 09:19

    Hello

    Right; the order in which the columns appear in the SELECT clause has nothing to do with the lines that are in the result set.

    In fact, unless you say SELECT DISTINCT , I don't think there's anything (except to trigger an error) you can do in the SELECT clause, which would change the lines are selected.

    Published by: Frank Kulash, November 20, 2009 12:45

    Sorry, I misread the question. You may have about the order of the conditions in the WHERE clause, not the SELECT clause.

    The answer in short is the same:
    Right.

    Unless you mix ANDS and ORs (no one should ever do and that you are not), the order of the conditions will make no difference in the results.

  • where clause

    Hi Master,

    I have a small doubt regarding where clause of a select query. I have a select query with 3 tables. I joined like that.

    Select * from

    ABC one

    XYZ x

    PQR p

    where a.column1 = b.column1

    and a. column 2 = value

    and b.coumn1 = c.column1

    and c. column2 = value

    and b. Column3 certain condition

    How oracle work where condition? average which condition will run first... is there a systematic order? Please advise... !!

    Concerning

    AR

    Hi, Ar,

    874273 wrote:

    Hi Master,

    I have a small doubt regarding where clause of a select query. I have a select query with 3 tables. I joined like that.

    Select * from

    ABC one

    XYZ x

    PQR p

    where a.column1 = b.column1

    and a. column 2 = value

    and b.coumn1 = c.column1

    and c. column2 = value

    and b. Column3 certain condition

    How oracle work where condition? average which condition will run first... is there a systematic order? Please advise... !!

    Concerning

    AR

    There is no predefined order.  The optimizer uses any order that it deems will get faster results.  You can check the execution plan to see how she chose in a particular case.

    SQL is a non-procedural language.  When you write code in a procedural language, tell you How you want to do something.  When you write code in SQL, you say what you want to do.

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

  • How to call a form with splashing around by clicking on a record with a time where

    Hi all

    How to call a form with splashing around by clicking on a record with a time where clause. I mean when I dip, click current record I want to call another form with the details of the
    record with onetime where clause. Can someone help me in this regard.

    Now, I'll call you a form with parameter with where Jadi but this should be avoided.


    Thanks in advance

    Arif

    Maybe this helps http://andreas.weiden.orcl.over-blog.de/article-28180655.html

  • Generating a 'WHERE' clause using a function

    Hi, I have provided,

    given the function at the bottom are input parameters.

    sk_func (salary, dept_no, Job, hire_date)

    whatever input is given these entries should be there in a statement,

    For example if I contribute as

    Select double sk_func(5000,null,null,null);

    I need output where salary = 5000;

    If I give as

    Select double sk_func(5000,null,'Programmer',null);

    I need output to where salary = 5000 and job = 'program';

    Hope am clear,

    In short that never values are non-null, those all should include in my where clause.

    I know how to do it, but in light of the considerations, am finding the best way to do it,


    Thanks for your answers,

    I could do that

    CREATE OR REPLACE FUNCTION get_where_clause_for_emp_req (
       emp_id IN NUMBER,
       salary IN NUMBER,
       job    IN VARCHAR2,
       dept   IN NUMBER
    )
       RETURN VARCHAR2
    IS
       l_where_clause   VARCHAR2 (2000) := 'WHERE 1=1 ';
    BEGIN
      IF emp_id is not null THEN
        l_where_clause := l_where_clause || 'AND emp_id = ' || emp_id || ' ';
      END IF;
    
      IF salary is not null THEN
        l_where_clause := l_where_clause || 'AND salary = ' || salary || ' ';
      END IF;
    
      IF job is not null THEN
        l_where_clause := l_where_clause || 'AND job = ' || job || ' ';
      END IF;
    
      IF dept is not null THEN
        l_where_clause := l_where_clause || 'AND dept = ' || dept || ' ';
      END IF;
    
      RETURN l_where_clause;
    END;
    
  • TO_CHAR in where clause

    Hello

    Here's my query below. I added a to_char dates in my paintings (expiry_dstamp) but now my request does not take the "superior to" in my where clause into consideration.

    Could someone ' a please inform me on what I should do now with my where clause.
    select *
    from
    
    (select distinct sku_id pfs, location_id pfl, to_char(expiry_dstamp, 'DD-Mon-YYYY') pfexd
    from inventory
    where pick_face = 'F') pf,
    
    (select distinct i.sku_id npfs, i.location_id npfl, to_char(i.expiry_dstamp, 'DD-Mon-YYYY') npfexd
    from inventory i, location l
    where i.pick_face is null
    and lock_code is null
    and i.location_id = l.location_id
    and l.work_zone not in ('DESPATCH', 'QUALITY', 'CHILLER', 'MARSHALL')) npf
    
    where pf.pfexd > npf.npfexd
    and npf.npfs = pf.pfs
    order by pf.pfl
    Thank you

    SM

    It is the taking into account, but now you're string comparison no dates...

    Try this

    select to_Char (pfexd, 'dd-mon-yyyy')
    , to_char (npfexd, 'dd-mon-yyyy')
    from
    
    (select distinct sku_id pfs, location_id pfl, expiry_dstamp pfexd
    from inventory
    where pick_face = 'F') pf,
    
    (select distinct i.sku_id npfs, i.location_id npfl, i.expiry_dstamp npfexd
    from inventory i, location l
    where i.pick_face is null
    and lock_code is null
    and i.location_id = l.location_id
    and l.work_zone not in ('DESPATCH', 'QUALITY', 'CHILLER', 'MARSHALL')) npf
    
    where pf.pfexd > npf.npfexd
    and npf.npfs = pf.pfs
    order by pf.pfl
    

    not tested

    Published by: Alex Nuijten on January 7, 2010 17:45

    Published by: Alex Nuijten on January 7, 2010 17:46

Maybe you are looking for

  • I changed my preferences of Firefox and now Firefox does not open.

    I changed my security settings and privacy and delete my cookies. When I tried to open Firefox, it would not open. I deleted Firefox to my Mac Applications, Safari used to download Firefox 42.0, and Firefox is not yet open. How can I fix? (I ALWAYS u

  • What happened to the progress bar in iTunes?

    Hi all I just downloaded and installed 9.2.1 to my iPhone 6s more use iTunes on Windows 7. Nothing happened. I waited for a while and then decided to close iTunes and start again. When I clicked on the 'X' I got an alert that asked if I really wanted

  • HP OfficeJet Pro 8600 Scan number

    Hi all I tried 2 scan options. 1. scan by clicking on the computer that I can choose a few options. for example, contrast, brightness. I chose option of black and white scanning with contrast and brightness 0 2 analyze in touchpad on the printer itse

  • LM_LICENSE_FILE conflicts

    My company has about 20 machines with different versions of LabVIEW installed.  I just realized that the update OR utility Service never ran on my main workstation, but he did it on several machines lab.  I tried to launch the Update Service OR manua

  • Download and silverlight v 2.0 registry key

    I get an error when you try to upgrade Silverlight 2.0 to 4.0 that the patch could not be found. As far as I can say it could be a corrupted registry key and it should reinstall 2.0 in order to uninstall it. There could be another issue however. Seve