Group by caluse before where clause

Hi all,
Declare
cursor c1 is select ARc_Month as mnth,count(*) as nof from dbarc
group by ARc_Month
where ARc_Month like '%02%';
e1 varchar2(1000);
cnt number(10);
begin
e1:='1';
for crec in c1 loop
cnt:= c1%rowcount;
dbms_output.put_line(cnt||'------'||crec.mnth||'-------'||crec.nof);
end loop;
end ;
Please go through the select statement for the cursor C1 which is syntactically worng but, the cursor is giving correct data. If the same select statement is run independently i.e at the sql prompt then it giving the following error, I knew that the error is due to the group by clause is before where clause. but it is not giving error while executing using explicit cursor.
SQL> select arc_month as mnth,count(*) as nof from dbarc
2 group by arc_month
3 where arc_month like '%02%';
where arc_month like '%02%'
ERROR at line 3:
ORA-00933: SQL command not properly ended
can anybody resolve this ambiguity. my oracle version is 8.1.7, Is this a known bug or unknown
Thanks in advance.

Ram
Yes, I get the same, also on 8.1.7. I can only guess they have changed pl/sql to relax the syntax restriction but have not got around to putting it in sql yet.
SQL> list
1 begin
2 declare cursor x is
3 select dummy from dual
4 group by dummy
5 where dummy is not null;
6 thing varchar2(1);
7 begin
8 open x;
9 fetch x into thing;
10 end;
11* end;
SQL> /
PL/SQL procedure successfully completed.
SQL> select dummy from dual
2 group by dummy
3 where dummy is not null;
where dummy is not null
ERROR at line 3:
ORA-00933: SQL command not properly ended

Similar Messages

  • GROUP By function in where clause

    Hi,
    I have a table which stores student marks.
    Student Table
    STD_ID STD_MARK
    1 10
    2 20
    3 5
    I want to find the student who got the the highst marks with and SQL select statement. This is what I wrote.
    SELECT STD_ID from Student where STD_MARK=MAX(STD_MARK)
    But oracle gives an error saying group function is not allowed here.
    Can u plz tell me how to get the student who has got the highst marks.
    Chamal.

    Did you get an answer as to how to return only one
    row per student?
    I have the same problem and have been spinning my
    wheels.
    select * from table
    where action_ind = 'N'
    group by employee_id
    I get 4 rows per person and all I need is any 1 for
    that employee_id.
    rjdizolwell, this is a new question... but you cannot use rownum there, use analytics instead, and partition by grouping column
    ex:
    SQL> select ename, deptno, sal from (
        select row_number() over (partition by deptno order by sal desc) r, emp.* from emp)
    where r=1;
    ENAME          DEPTNO        SAL
    KING               10       5000
    SCOTT              20       3000
    BLAKE              30       2850

  • Creating WHERE clause for an outer join using DatabaseFilter

    Hi all,
    I read a post on thie group about constructing the WHERE clause for a RowSet Controls
    SQL Query using the DatabaseFilter and this is what it said:
    ****************************************************************************The
    following example shows adding part of a WHERE clause in an action method of a
    page flow:
    DatabaseFilter.FilterTerm term = new DatabaseFilter.FilterTerm(); term.sColumnName
    = "name"; term.op = DatabaseFilter.opContains; // there are ops for equals, less
    than, etc... term.value = form.getPartialName();
    // You can also add sort terms for an ORDER BY clause allNames = dbControl.getNames(new
    DatabaseFilter(new DatabaseFilter.FilterTerm[] {term}, null));
    I am trying to create a where clause which uses a join like this:
    Select * from x,y where x.id=y.id (+)
    ie. All values from x.id but only corrosponding ones from y.id.
    Is there any way to build this outer join query using the DatabaseFilter class
    or am i forced to use a String which is contruct in my page flow as the where
    clause?like so:
    * @jc:sql command-type="grid"
    * rowset-name="RFPSRowSet"
    * max-rows="1000"
    * statement::
    * SELECT RFPS.RFP_ID,RFPS.NAME AS RFP_NAME,RFPS.FFO_NUMBER,RFPS.RFP_TYPE,RFPS.CFDA_NUMBER,COMPETITIONS.NAME
    AS COMP_NAME,COMPETITIONS.COMPETITION_ID FROM RFPS,COMPETITIONS WHERE {sql: whereClause
    } {sql: filter.getOrderByClause ()}
    public RowSet getAllRfps(java.lang.String whereClause,DatabaseFilter filter)
    throws SQLException;
    and in my pageFlow action, i do the following:
    StringBuffer whereClause= new StringBuffer();
    whereClause.append("RFPS.RFP_ID = COMPETITIONS.RFP_ID (+)");
    if ((form.getRfpTitle() != null) &&
    (!form.getRfpTitle().equalsIgnoreCase("")))
    whereClause.append(" AND UPPER(RFPS.NAME) LIKE %"+form.getRfpTitle().toUpperCase());
    if ((form.getCfdaNumber() != null) &&
    (!form.getCfdaNumber().equalsIgnoreCase("")))
    whereClause.append(" AND RFPS.CFDA_NUMBER ="+form.getCfdaNumber());
    if ((form.getFfoNumber() != null) &&
    (!form.getFfoNumber().equalsIgnoreCase("")))
    whereClause.append(" AND RFPS.FFO_NUMBER ="+form.getFfoNumber());
    sortFilterService = SortFilterService.getInstance(getRequest());
    DatabaseFilter filter=sortFilterService.getDatabaseFilter(getGridName());
    log.debug("***********"+whereClause.toString()+"***********");
    allRows = searchRfaAndComp.getAllRfps(whereClause.toString(),filter);
    Thanks in advance for your help,
    Regards,
    Vik.

    Thanks for your reply. Just one more question....if we indeed are trying to use
    a simple query and have a where clause like "select * from x where upper(x) like
    {x}", how do we set the UPPER filter on the column using the database filter?
    I see a IDENTIFIER.ISUPPER static field on that DatabaseFilter but am unsure how
    to use it. Would appreciate any pointers .
    Thanks again,
    Vik
    Eddie O'Neil <[email protected]> wrote:
    Vik--
    I believe that the approach that you describe below is the best one
    for dealing with outer joins
    with the DatabaseFilter.
    Apologies for the limitation...
    Eddie
    vik wrote:
    Hi all,
    I read a post on thie group about constructing the WHERE clause fora RowSet Controls
    SQL Query using the DatabaseFilter and this is what it said:
    ****************************************************************************The
    following example shows adding part of a WHERE clause in an actionmethod of a
    page flow:
    DatabaseFilter.FilterTerm term = new DatabaseFilter.FilterTerm(); term.sColumnName
    = "name"; term.op = DatabaseFilter.opContains; // there are ops forequals, less
    than, etc... term.value = form.getPartialName();
    // You can also add sort terms for an ORDER BY clause allNames = dbControl.getNames(new
    DatabaseFilter(new DatabaseFilter.FilterTerm[] {term}, null));
    I am trying to create a where clause which uses a join like this:
    Select * from x,y where x.id=y.id (+)
    ie. All values from x.id but only corrosponding ones from y.id.
    Is there any way to build this outer join query using the DatabaseFilterclass
    or am i forced to use a String which is contruct in my page flow asthe where
    clause?like so:
    * @jc:sql command-type="grid"
    * rowset-name="RFPSRowSet"
    * max-rows="1000"
    * statement::
    * SELECT RFPS.RFP_ID,RFPS.NAME AS RFP_NAME,RFPS.FFO_NUMBER,RFPS.RFP_TYPE,RFPS.CFDA_NUMBER,COMPETITIONS.NAME
    AS COMP_NAME,COMPETITIONS.COMPETITION_ID FROM RFPS,COMPETITIONS WHERE{sql: whereClause
    sql: filter.getOrderByClause ()}* ::
    public RowSet getAllRfps(java.lang.String whereClause,DatabaseFilter
    filter)
    throws SQLException;
    and in my pageFlow action, i do the following:
    StringBuffer whereClause= new StringBuffer();
    whereClause.append("RFPS.RFP_ID = COMPETITIONS.RFP_ID (+)");
    if ((form.getRfpTitle() != null) &&
    (!form.getRfpTitle().equalsIgnoreCase("")))
    whereClause.append(" AND UPPER(RFPS.NAME) LIKE %"+form.getRfpTitle().toUpperCase());
    if ((form.getCfdaNumber() != null) &&
    (!form.getCfdaNumber().equalsIgnoreCase("")))
    whereClause.append(" AND RFPS.CFDA_NUMBER ="+form.getCfdaNumber());
    if ((form.getFfoNumber() != null) &&
    (!form.getFfoNumber().equalsIgnoreCase("")))
    whereClause.append(" AND RFPS.FFO_NUMBER ="+form.getFfoNumber());
    sortFilterService = SortFilterService.getInstance(getRequest());
    DatabaseFilter filter=sortFilterService.getDatabaseFilter(getGridName());
    log.debug("***********"+whereClause.toString()+"***********");
    allRows = searchRfaAndComp.getAllRfps(whereClause.toString(),filter);
    Thanks in advance for your help,
    Regards,
    Vik.

  • How to add a dynamic where clause for a sql based VO with group by query?

    Hi,
    Here is my case, I have a sql query based VO with the query like "select status, count(*) StatusCount from my_table group by status". Now I used the following java code trying to dynamically add the where clause to my VO to filter the rows based the type attribute in my DB table.
    vo.setWhereClause("type='MyType1' ");
    vo.executeQuery();
    Then I got the sql syntax error. Looks like the ADF has added the where clause to the end of my sql so my sql becomes "select status, count(*) StatusCount from my_table group by status where type='MyType1' ". But what I expected was the correct syntax "select status, count(*) StatusCount from my_table where type='MyType1' group by status".
    Does anyone know if this is an ADF bug? Or is there any other way to achieve my goal?
    Thanks,
    Chunyang
    Edited by: Chunyang on Dec 13, 2012 9:09 PM

    Hi,
    When you use setWhereClause on the VO, it is applied on top of the VO query. I.e, assume your VO has the following query.
    select empno, ename from empNow, if you apply the where clause programatically, only the two attributes that you are using in the select statement could be used. I.e
    select * from (select empno, ename from emp) where ename='KING' - VALID
    select * from (select empno, ename from emp) where deptno=10  - INVALID (because the inner query - the one you've defined as query for your vo does not have deptno attribute selected)If you would need to set a dynamic where clause, you need to make them available in your select statement / use bind variables.
    -Arun

  • Group by with and without where clause

    Do I need to use these two inner views to show results by group by as one line? Can I achieve the same result without typing the same select statement two times since these two SELECT statements differ only in where clause. This query is a simulation. My actual query is longer. My expectation is to make this query shorter (without inner 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 inner views to show results by group by as one line? Can I achieve the same result without typing the same select statement two times since these two SELECT statements differ only in where clause. This query is a simulation. My actual query is longer. My expectation is to make this query shorter (without inner 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

  • Group by, setting where clause in View Objects

    Hello,
    I have a problem with View Objects in BC4j. Cause I cannot use a column in the where clause of a view object that is not also an attribute of the view object, I am unable to group a statement as I want to. Is there a way to solve this problem?
    Thanks in advance!
    Britta

    What version are you using..I tried a simple WHERE clause using an attribute which is not part of the VO and that works ok....
    Thanks
    Grant Ronald
    Oracle Product Management

  • Functions in where clauses vs. in group-by ... inconsistent?

    Hello all.
    (assuming Oracle 9.2)
    First of all, does anyone know why the Oracle SQL Parser will not allow
    us to use the <name>-part of "table.column AS <name>" in where or
    group-by clauses?? Is this just being lazy on their part, or is there
    an actual reason behind this?
    Second, and relating to this I am confused as to how ORACLE handles
    group-by clauses with functions. (Or rather I find it a bit
    inconsistent.)
    a)
    select my_func(col1), col2
    from a_table
    where my_func(col1) = :filter;
    ==> This will evaluate my_func() two(2) times for every row in the
    table.
    b)
    select my_func(col1), sum(col2)
    from a_table
    group by my_func(col1);
    ==> This will NOT evaluate the function twice(2) for every result row,
    instead it is EXACTLY the same as when I would write:
    c = b)
    select col1_func, sum(col2)
    from (select my_func(col1) col1_func, col2)
    group_by col1_func
    Consider also the attached example to further confuse the issue.
    Any opinions, pointers, corrections on this are most welcome.
    cheers,
    Martin
    ** small example **
    CREATE OR REPLACE
    PACKAGE TEST_PACKAGE
    IS
    global_counter NUMBER;
    END TEST_PACKAGE;
    CREATE OR REPLACE
    FUNCTION TEST_PUT(x IN VARCHAR2)
    RETURN VARCHAR2 IS
    ret VARCHAR2(100) := x || test_package.global_counter;
    BEGIN
    dbms_output.put_line(ret);
    test_package.global_counter := NVL(test_package.global_counter, 0) +
    1;
    return ret;
    END;
    -- Test_Put will be evaluated 2 times(!):
    select test_put('fn_called') my_string, COUNT(object_name)
    from all_objects
    where rownum <= 2
    group by test_put('fn_called')
    -- Test_Put will be evaluated 4 times(!):
    select test_put('fn_called') my_string, COUNT(object_name)
    from all_objects
    where rownum <= 2
    group by test_put('fn_call')

    Hello
    Hopefully this will help to explain:
    SQL> create or replace package test_package
      2  is
      3     counter_select  number;
      4     counter_where   number;
      5  end;
      6  /
    Package created.
    SQL> create or replace function test_func_select
      2  return varchar2
      3  is
      4  begin
      5
      6     test_package.counter_select := NVL(test_package.counter_select,0) + 1;
      7
      8     dbms_output.put_line('test_func_select Call # '||TO_CHAR(test_package.counter_select));
      9
    10     return 'Call # '||TO_CHAR(test_package.counter_select);
    11
    12  end;
    13  /
    Function created.
    SQL>
    SQL> create or replace  function test_func_where
      2  return varchar2
      3  is
      4  begin
      5
      6     test_package.counter_where := NVL(test_package.counter_where,0) + 1;
      7
      8     dbms_output.put_line('test_func_where Call # '||TO_CHAR(test_package.counter_where));
      9
    10     return 'Call # '||TO_CHAR(test_package.counter_where);
    11
    12  end;
    13  /
    Function created.
    SQL> set serveroutput on
    SQL>
    SQL> SELECT
      2     test_func_select,
      3     count(*)
      4  FROM
      5     dt_test_tab
      6  WHERE
      7     rownum <=2
      8  GROUP BY
      9     test_func_select
    10  /
    TEST_FUNC_SELECT                 COUNT(*)
    Call # 2                                1
    Call # 1                                1
    test_func_select Call # 1
    test_func_select Call # 2
    SQL> exec test_package.counter_select:=NULL;
    PL/SQL procedure successfully completed.
    SQL> SELECT
      2     test_func_select
      3  FROM
      4     dt_test_tab
      5  WHERE
      6     rownum <=2
      7  AND
      8     test_func_where LIKE 'Call #%'
      9  /
    TEST_FUNC_SELECT
    Call # 1
    Call # 2
    test_func_where Call # 1
    test_func_select Call # 1
    test_func_select Call # 2
    SQL>
    SQL> create or replace function test_func_select(av_param in varchar2)
      2  return varchar2
      3  is
      4  begin
      5
      6     test_package.counter_select := NVL(test_package.counter_select,0) + 1;
      7
      8     dbms_output.put_line('test_func_select Call # '||TO_CHAR(test_package.counter_select));
      9
    10     return 'Call # '||TO_CHAR(test_package.counter_select);
    11
    12  end;
    13  /
    Function created.
    SQL>
    SQL> create or replace  function test_func_where(av_param in varchar2)
      2  return varchar2
      3  is
      4  begin
      5
      6     test_package.counter_where := NVL(test_package.counter_where,0) + 1;
      7
      8     dbms_output.put_line('test_func_where Call # '||TO_CHAR(test_package.counter_where));
      9
    10     return 'Call # '||TO_CHAR(test_package.counter_where);
    11
    12  end;
    13  /
    Function created.
    SQL> exec test_package.counter_select:=NULL;
    PL/SQL procedure successfully completed.
    SQL>
    SQL> SELECT
      2     test_func_select(object_name) test_func_select,
      3     count(*)
      4  FROM
      5     dt_test_tab
      6  WHERE
      7     rownum <=2
      8  GROUP BY
      9     test_func_select(object_name)
    10  /
    TEST_FUNC_SELECT                 COUNT(*)
    Call # 2                                1
    Call # 1                                1
    test_func_select Call # 1
    test_func_select Call # 2
    SQL> exec test_package.counter_select:=NULL;
    PL/SQL procedure successfully completed.
    SQL> exec test_package.counter_where:=NULL;
    PL/SQL procedure successfully completed.
    SQL> SELECT
      2     test_func_select(object_name) test_func_select
      3  FROM
      4     dt_test_tab
      5  WHERE
      6     rownum <=2
      7  AND
      8     test_func_where(object_name) LIKE 'Call #%'
      9  /
    TEST_FUNC_SELECT
    Call # 1
    Call # 2
    test_func_where Call # 1
    test_func_select Call # 1
    test_func_where Call # 2
    test_func_select Call # 2In the fist example, oracle only has to call the function once to satisfy the predicate as it is not technically being applied to the table. There could be 1million rows but if the function did not return a string in the form Call #, none of the result set would be materialised as the predicate had failed. In the second example, the predicate is being applied to the table as we are passing a column from the result set to the function. This means that the where clause function has to be called once for every row in the result set.
    HTH
    David

  • How to write WHERE clause in dynamic record group in oracle forms

    hi this is s.v.eswar,PLZ HELP ME
    i am new to oracle forms
    i want to write where clause in dynamic recordgroup
    this is the code i have written
    DECLARE
         MGR_ITEM ITEM:=FIND_ITEM('MGR');
         RG_ID_MGR RECORDGROUP:=NULL;
         MGR_DUMMY NUMBER;
    BEGIN
         RG_ID_MGR:=FIND_GROUP('MGRNUMBER');
         IF ID_NULL(RG_ID_MGR) THEN
              RG_ID_MGR:=CREATE_GROUP_FROM_QUERY('MGRNUMBER','SELECT DISTINCT TO_CHAR(EMPNO),TO_CHAR(EMPNO) FROM EMP WHERE JOB='MANAGER''); --THIS IS THE LINE I AM GETTING ERROR
         END IF;
         IF NOT ID_NULL(RG_ID_MGR) THEN
              MGR_DUMMY:=POPULATE_GROUP('MGRNUMBER');
              IF MGR_DUMMY=0 THEN
                   POPULATE_LIST(MGR_ITEM,'MGRNUMBER');
              END IF;          
         END IF;     
    END;
    COMPILE TIME ERROR
    1)I have written where clause like this WHERE JOB='MANAGER'
    then oracle compiler has given error like
    ENCOUNTERED THE SYMBOL 'MANAGER' WHEN EXPECTING ONE OF THE FOLLOWING .,().........etc
    (FOR THE ABOVE ERROR I JUST REMOVED SINGLE CODES AND WRITE LIKE THIS ----->WHERE JOB=MANAHER)------>THEN COMPILED SUCESSFULLY)
    AND I RUN THE FORM
    RUN TIME ERROR
    FRM-41072: CAN NOT CREATE GROUP 'MGRNUMBER'

    Hi there
    pls have a look here
    Dependent drop down lists in forms 6i
    hope this helps...
    regards,
    Amatu Allah

  • VOWizard-Bug: WHERE Clause not modified on EO add if manually changed befor

    VOWizard-Bug: WHERE Clause is not modified on adding a EO (with association) if it was manually changed before
    Testcase:
    - Create a VO based on 2 EO (Association already defined) --> Jon in WHERE Clause automatically created by Wizard
    - Then modify the WHERE clause, e.g. change an equal to outer join.
    - All works fine.
    - Then add a EO (also Association defined) and chose some attributes.
    - Test and wonder why there are much more rows in the result than expected.
    - Look into the Query-Tab and control the WHERE clause: Wizard forgot to add the new join... and therefore we get a cartesian product between the old view and the new added EO...
    Possible solutions to fix the Bug:
    1. add the JOIN ;-)
    or
    2. at least display a warning that the JOIN is not automatically created!
    Regards, Markus
    GE Medical Systems

    Hi Markus-
    Once the where clause has been customized, we don't update it in the interest of not messing up the user's custom code. However, we should probably warn the user in the types of cases you mention above that he will need to update the where clause manually to include the new information. We will add this in a future release.
    Thanks,
    Ray

  • Row Level Security using BO SDK - Dynamic Group and Criteria (where clauses)

    To the Universe Gurus out there:
    I have a rather daunting task of implementing a Row Level Security on a number of tables within our project using BO XI R2 SP2 with SQLServer 2005. Given the nature of the requirements around this (listed below), I am going to go with BO SDK to accomplish the creation of Restrictions. That said, I need some insight into some of the problem areas I have listed below. Any help is much appreciated.
    Background:
    We have 11 tables that are to be restricted.
    Each table is accessible to potentially 1..* group of users only.
    For eg SALES is accessible to ALL_SALES members only.
    Each row within each table is accessible to 1..* groups of users only. The restriction will occur on 2 columns Jurisdiction and LineID on SALES table.
    For eg
    1)Rows with NY Jurisdiction and LineID=123 are accessible to NY_SALES_ADMIN group only initially.
    2)NY_ADMIN will then approve that the above rows be open to NY_SALES_INTERNAL group only. This approval in turn will call upon the BO SDK to add a new restriction for the group with appropriate where clause.
    3)At a later point, the above rows will be opened to NY_SALES_EXTERNAL group also.
    This same concept holds good a number of jurisdiction (more or less static) and a dynamic number of LineIDs. So, if 10000 rows of data corresponding to new LineID 999 and Jurisdiction AK are in the table now, they are initially accessible only to AK_SALES_ADMIN group only. No one else should be able to access it.
    Results:
    1) With the way I laid out the business rules above, I am ending up with 528 groups.
    2) There is a restriction created for a unique combination of Jurisdiction and LineID for each table.
    Problems/Questions:
    How can I restrict access to the new rows to one group only. I know that I can let a certain group only look at certain data but how can I restrict that all others cannot look at the same.
    AK_SALES_ADMIN can look at LineID=999 and Jurisdiction='AK'.
    Do I use an Everyone group based restriction? If so, my Everyone group will end up with tons of restrictions. How will they be resolved in terms of priority.
    Am I even thinking of this the right way or is there a more noble way to do this?
    Regards

    the connectinit setting should look something like this:
    declare a date; begin vpd_setup('@VARIABLE('BOUSER')'); Commit; end;
    The vpd_setup procedure (in Oracle) should look like this:
    CREATE OR REPLACE procedure vpd_setup (p_user varchar)IS
    BEGIN
      DBMS_SESSION.set_vpd( 'SESSION_VALUES', 'USERID', p_user );
    END vpd_setup;
    Then you can retrieve the value of the context variable in your vpd functions
    and set the vpd.

  • Dynamically setting where clause parameter before the page load

    Hi Experts,
    I do have the following requirement.
    I am working on jsf page in ADF10.1.3.3. I have a View Object which displays the results on the screen. Can someone provide me some example where I can dynamically set the where clause parameter to my Query in VO before the Page Load happens(By Overriding the Prepare Model) and display results on screen.
    Thanks

    Hi,
    Thanks for yor advice.
    I need to write the method in Prepare Model method when the page loads and not in AM.
    Here in the page there is no action as such.
    On the Page load we need to directly set the Where Clause on the VO.
    Provide me some examples if any.
    Thanks

  • Error when using record group type as param in a function in where clause

    Hi folks.
    I have a record type defined in a packages specification. I have to use this record as parameter to call a function. I am able to call the function if as return its value to a string variable. However, the function should be called into a query to compare the returned value and this code is not compiled.
    The code is below:
    DECLARE
    l_line_group_rec INL_CUSTOM_PUB.inl_ship_headers_rec;
    l_name VARCHAR2(100);
    l_count NUMBER;
    BEGIN
    l_name := INL_GET_PARTY_SITE_NAME(l_line_group_rec); -- Compiling successfully
    SELECT COUNT(1)
    INTO l_count
    FROM dual
    WHERE INL_GET_PARTY_SITE_NAME(l_line_group_rec) = 'Allied Manufacturing'; --- Error when compiling
    END;
    I got the error: PLS-00306: wrong number or types of arguments in call to 'INL_GET_PARTY_SITE_NAME'
    I would like to know if there is any restriction in using record type as parameter in where clauses or if there is another way to do it.
    Thanks in advance

    Hi.
    The definition of INL_GET_PARTY_SITE_NAME:
    FUNCTION INL_GET_PARTY_SITE_NAME(p_line_group_rec INL_CUSTOM_PUB.inl_ship_headers_rec) RETURN VARCHAR2 IS
    l_party_site_name VARCHAR2(100);
    BEGIN
    l_party_site_name := 'Allied Manufacturing';
    URN l_party_site_name;
    END INL_GET_PARTY_SITE_NAME;
    Thanks.

  • Using decode to define "where" clause

    Gurus,
    Before, I was unioning several queries to get my desired results. Is there a way to utilize decode to define my "where" conditions?
    Thanks
    msi.global_attribute1               HTS_Number,           
    msi.global_attribute2               ECCN_Number  ,
    msi.market_price                    price,     --- double-check
    decode(msi.serial_number_control_code,5,'Serial','Lot') control_type,
    -- add item_type
    --Item Label Creation        At Receipt or At Sales Order Issue
    (case
    when enabled_flag = 'Y' and end_date_active is null then 'Active'
    when enabled_flag = 'Y' and end_date_active > sysdate then 'Active'
    when enabled_flag = 'Y' and end_date_active < sysdate then 'Inactive'
    when enabled_flag = 'N' then 'Inactive'
    else 'Active'
    end) status,
    from inv.mtl_system_items_b   msi,
         po_hazard_classes    phc,
        po_un_numbers        pun
    where msi.hazard_class_id = phc.hazard_class_id(+)  
    and   msi.un_number_id = pun.un_number_id(+)   
    and   msi.organization_id = 543
    and   msi.creation_date = msi.last_update_date
    --and   'New Items' = nvl(p_item_status,'All Items') --p_item_status
    and   decode('New Items', --p_item_status,
          'New Items', (msi.creation_date = msi.last_update_date),
          'Updated Items', (msi.creation_date <> msi.last_update_date),
          'All Items', (1=1), (1=1))
      and msi.segment2 = '14078'

    Hi,
    sreese wrote:
    Before, I was unioning several queries to get my desired results. Is there a way to utilize decode to define my "where" conditions?Depending on what you mean, yes.
    Whenever you have a problem, please post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) from all tables involved.
    Also post the results you want from that data, and an explanation of how you get those results from that data, with specific examples.
    Simplify the problem as much as possible. Remove all tables and columns that play no role in this problem.
    Always say which version of Oracle you're using.
    Here's an example of two UNIONed queries:
    SELECT       deptno
    ,       SUM (sal)     AS total_sal
    ,       'MANAGEMENT'     AS grp_name
    FROM       scott.emp
    WHERE       job     IN ('MANAGER', 'PRESIDENT')
    GROUP BY  deptno
         UNION ALL
    SELECT       deptno
    ,       SUM (sal)     AS total_sal
    ,       'OLD-TIMERS'     AS grp_name
    FROM       scott.emp
    WHERE       hiredate     < DATE '1984-01-01'
    GROUP BY  deptno
    ORDER BY  deptno
    ,            grp_name
    ;Output:
    `   DEPTNO  TOTAL_SAL GRP_NAME
            10       7450 MANAGEMENT
            10       8750 OLD-TIMERS
            20       2975 MANAGEMENT
            20       6775 OLD-TIMERS
            30       2850 MANAGEMENT
            30       9400 OLD-TIMERSA more efficient way to get the same information, without a UNION is:
    SELECT       deptno
    ,       SUM (CASE WHEN job IN ('MANAGER', 'PRESIDENT') THEN sal END)     AS management
    ,       SUM (CASE WHEN hiredate < DATE '1984-01-01'      THEN sal END)     AS old_timers
    FROM       scott.emp
    WHERE       job          IN ('MANAGER', 'PRESIDENT')
    OR       hiredate     < DATE '1984-01-01'
    GROUP BY  deptno
    ORDER BY  deptno
    ;Output:
    `   DEPTNO MANAGEMENT OLD_TIMERS
            10       7450       8750
            20       2975       6775
            30       2850       9400As you can see, the results aren't exactly the same. UNION makes it easy to get more rows in the output than there are in the original; CASE (or DECODE,you can use whichever you like) makes it easy to get fewer rows and more columns. If you reallt want one kind of output or the other, it can be done with a little more work using either UNION or CASE.
    When using CASE, the WHERE clause is typically more inclusive than any of the WHERE caluses in the UNION. Some of the conditions (in this example, all of the conditions) that were in the separate WHERE clauses of the UNION get changed to be conditions in separate CASE expressions.

  • Using round off function in where clause

    Hi All,
    I'm trying to use round off function in where clause, I seek help in completing this script.
    WITH CR_Details AS
    (Select
    request_id,
    parent_request_id,
    fcpt.user_concurrent_program_name Request_Name, phase_code, status_code,
    round((fcr.actual_completion_date - fcr.actual_start_date),3) * 24 * 60 as Run_Time,
    round(avg(round(to_number(actual_start_date - fcr.requested_start_date),3) * 1440),2) wait_time,
    fu.User_Name Requestor,
    fcr.argument_text parameters,
    to_char (fcr.requested_start_date, 'MM/DD HH24:mi:SS') requested_start,
    to_char(actual_start_date, 'MM/DD/YY HH24:mi:SS') ACT_START,
    to_char(actual_completion_date, 'MM/DD/YY HH24:mi:SS') ACT_COMP,
    fcr.completion_text
    From
    apps.fnd_concurrent_requests fcr,
    apps.fnd_concurrent_programs fcp,
    apps.fnd_concurrent_programs_tl fcpt,
    apps.fnd_user fu
    Where 1=1
    and fcr.concurrent_program_id = fcp.concurrent_program_id
    and fcp.concurrent_program_id = fcpt.concurrent_program_id
    and fcr.program_application_id = fcp.application_id
    and fcp.application_id = fcpt.application_id
    and fcr.requested_by = fu.user_id
    and fcpt.language = 'US'
    and fcr.actual_start_date like sysdate )
         select crd.*
         from CR_Details crd
         where Run_time <> '0'
         AND wait_time <> '0'
    GROUP BY
    crd.request_id,
    crd.parent_request_id,
    crd.fcpt.user_concurrent_program_name,
    crd.requested_start_date,
    crd.User_Name,
    crd.argument_text,
    crd.actual_completion_date,
    crd.actual_start_date,
    crd.phase_code,
    crd.status_code,
    crd.resubmit_interval,
    crd.completion_text,
    crd.resubmit_interval,
    crd.resubmit_interval_unit_code,
    crd.description
    Not sure about the GROUPBY function referencing the "crd." .

    Hi,
    The best thing for you to do is start over. Start as small as possible, then take baby steps.
    Pick one of the tables; fcr perhaps, and write a query that just uses that table, like this:
    SELECT    *
    FROM       apps.fnd_concurrent_requests     fcr
    WHERE       fcr.actual_start_date          >= TRUNC (SYSDATE)
    AND       fcr.actual_start_dt          <  TRUNC (SYSDATE) + 1
    ;(I think this is what you meant to do when you said "... LIKE SYSDATE".)
    Make sure this little query gets credible results. When that tiny query is working perfectly, add another line or two. You can cut and paste code from what you posted, if that helps you.
    If you get stuck, post the last version of your code that worked perfectly, and the latest version (only a line or two bigger) that has the problem. Describe what the problem is. If you get an error, post the complete error message. In any event, post CREATE TABLE and INSERT statements for all the tables and columns needed to run the query, and the results you want to get from that query.
    When you post any code, format it, so that how the code looks on the screen gives some clues about how it is working.
    When you post any formatted text on this site, type these 6 characters:
    \(small letters only, inside curly brackets) before and after each section of formatted text, to preserve spacing.
    If you going to use the AVG function in the sub-query, then you probably need to do a GROUP BY in the sub-query.
    If you're not using any aggregate functions (like AVG) in the main query, then you probably don't want to do a GROUP BY in the main query.
    I know this is a lot of work.  I'm sorry.  If there was an easier way, I wouldn't ask you to do all this.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Sub query in where clause

    I have the following code which keeps throwing an error:
    select distinct game_code, count(player_id)
    from customer_data.cd_nhl_gm_tender_stats t
    where 
    (select distinct player_id
    from customer_data.cd_nhl_gm_tender_stats
    where season_id = 200818)
    group by game_code, player_id
    having count(player_id) > 1Error states that there's a missing expression right before the group by, any thoughts?
    The subquery is basically used to find a unique player_id value, (so there's no duplicates rows in the result set.)
    Sample data;
    customer_data.cd_nhl_gm_tender_stats t
    Game_code player_id
    88484           545454
    88484           545454
    88484           545454There's obviously other columns in the table above, but ultimatly there is mutliple rows for each game.
    I'm just trying to return each game_code where more then one player_id is found.

    Michaels2 i'm not sure your code is doing quite what i need
    select   *
      from   (select   t.*,
                       count (distinct player_id) over (partition by game_code) cnt
                from   cd_nhl_gm_tender_stats t where season_id = 200818)
    where   cnt > 1The subquery in the from clause is just selecting every game_code where season_id 200818 and then you add a where clause where cnt > 1 in the main query(whcih doesn't accomplish what I really wanted). What I need is the count of distinct player_id where season_id = 200818 AND cnt of (distinct player_id) over (partition by game_code) cnt > 2**. The issue i'm having is, that i'm not quite sure how to format the code to get these results.
    To clairfy what i need one more time ( i didn't explain things well in my original post)...
    I want each game_code where a player_id count is greather then two. And as stated earlier the gm_tender_stats table has numerous entries with the same player_id for the same_game code, which is why this makes writing this query a little more difficult.
    Edited by: user652714 on May 11, 2009 7:52 AM

Maybe you are looking for

  • Wireless Card (wifi) not detected in Win 8.1

    Hi, Since I bought HP Pavilion 17-e100ex Notebook (Win 8.1) have problem with the wifi adapter, sometime the wifi light turns on and sometime its not, and when i go to device manager it does not recognized that I have any kind of wifi adapter (when t

  • Word Wrap with a Vertical Grid

    I've got a vertical grid with my headers in the left column and descriptive text in the column immediately to the right.  I'd like to have the descriptive text word wrap but checking the word wrap box on the layout tab doesn't seem to have any effect

  • Third Party Billing Integration

    Are there any guidelines for 3rd party billing integration?

  • Where the loaded files are stored?

    I loaded excel file with data in my FDM app. After the file loaded It could be seen in my HFM app (choosing "Restore Source Document"). Question: where this loaded excel file is stored?

  • Authentication failure after upgrade to 10.4 Server

    I have upgraded Xserve from 10.2 server to Tiger 10.4. The server does not log on after installation.