Usage of MAX Function.

Hi,
One of our customers is facing an error while executing a PL/SQL block like,
declare
l_flag varchar2(30);
begin
select max('Y') into l_flag from v$database; -- Can use any table here
end;
however, when the select query is changed to as follows, no error is seen.
select substr(max('Y'),1,30) into l_flag from v$database;
Can someone please help me in identifying what could be issue?
Thanks,
Dola

We are actually trying to check if the table contains any rows.Hmmm, I would have thought that using a MAX() function to do that is rather expensive (if it's a large table)...
SQL> set autotrace traceonly stat
SQL> select max('Y') from tt1
  2  /
Statistics
          0  recursive calls
          0  db block gets
        432  consistent gets
        428  physical reads
          0  redo size
        378  bytes sent via SQL*Net to client
        499  bytes received via SQL*Net from client
          2  SQL*Net roundtrips to/from client
          0  sorts (memory)
          0  sorts (disk)
          1  rows processed
SQL>          
SQL> select count(*) from tt1
  2  /
Statistics
          0  recursive calls
          0  db block gets
        432  consistent gets
        423  physical reads
          0  redo size
        381  bytes sent via SQL*Net to client
        499  bytes received via SQL*Net from client
          2  SQL*Net roundtrips to/from client
          0  sorts (memory)
          0  sorts (disk)
          1  rows processed
SQL>          
SQL> select null  from tt1
  2  where rownum = 1
  3  /
Statistics
          0  recursive calls
          0  db block gets
          4  consistent gets
          5  physical reads
          0  redo size
        372  bytes sent via SQL*Net to client
        499  bytes received via SQL*Net from client
          2  SQL*Net roundtrips to/from client
          0  sorts (memory)
          0  sorts (disk)
          1  rows processed
SQL> Cheers, APC

Similar Messages

  • Problem with max function in air

    Hello ,how are you,I write this query : [b]SELECT *, max(trackerId) FROM  sessiontracker [/b]in
    sqlite manager and it works ,but when I use it in Air application  ,it send me back this error:
    ReferenceError: Error #1056: Cannot create property max(trackerId) on
    com.afarinesh.models.SessionTracke
    ,I guess that Actionscript 3 can not pars max function.
    I appreciate your help

    Hello,
    AIR does support max function. Please see Page 1067 of the actionscript developer's guide, which can be download from http://help.adobe.com/en_US/as3/dev/as3_devguide.pdf. And I tried the max function in my AIR application: create a table, insert some records into the table, and use the "select *, max(column) from table". It works fine.
    I noticed your error is the ReferenceError and related to some AS class. So I am not sure if you use any ORM tool. If so, the issue may be caused by the use of the tool. Please check the configuration and usage of the tool.
    Thanks,
    Yang

  • How to Avoid Errors in Max Function When Data Contains Blank Cells

    I have a column with duration values. However, it also contains some blank cells. These "blank cells" have formulas in them, but as the cells they reference too are blank the formula doesn't produce a result.>/p>
    I want to get the max value from this column. When I simply do =MAX(column-name) I get an error, presumably because some of the cells are blank. This table is going to be highly dynamic, so I don't want to limit the range of the MAX() function to only those cells with values.
    So does anyone know a solution for this, please? If I was some how able to create a formula which returned the range of cells with actual values, then I could use that in the MAX() function. Or, if I could somehow tell the MAX() function to ignore blank cells, but I'm not sure either of these are possible.
    Thanks,
    Nic

    I don't see a problem with "blank" (null string) cells mixed with duration cells.  MAX works fine with this mix of cells. But if the "blank" cells are numbers, not text, that gives an error.
    A formula always produces a result. A formula cannot result in a blank cell. The closest you can get to "blank" is a null string (the result of two quotes next to each other with nothing between them) . So the question is, what is the result that you are calling "blank"?

  • MAX function

    Hi Everyone,
    Am aware of the following flavors of MAX function
    1) choose MAX from the folders/fields list (selected items tab)
    2) create calculation using: MAX keep dense
    3) create calculation using: MAX analytic function
    questions, pls:
    ===========
    a) with MAX regular, MAX keep dense, MAX - analytic function
    is it necessary to sort it using tools/sort - choose fields to sort by?
    or does the data get sorted due to the ORDER BY clause in MAX used in a calculation
    b) how to understand the diff. bet. MAX keep dense and MAX - analytic function
    1) i understand that analytic functions are applied after detail row processing
    does MAX keep dense calculation happen during detail row processing?
    2) how did you know to advise when to use MAX keep dense, and when to use MAX - analytic function?
    tx for your ideas and assistance, sandra

    Hi,
    a) with MAX regular, MAX keep dense, MAX - analytic function is it necessary to sort it using tools/sort - choose fields to sort by? or does the data get sorted due to the ORDER BY clause in MAX used in a calculationIt is only necessary to use a sort if you want to have the rows returned in a specific order. The order by in the max calculation defines the maximum within the group or window. It may affect the order the rows are returned, but if it does this is not guaranteed and you should use a sort on the main query.
    b) how to understand the diff. bet. MAX keep dense and MAX - analytic function
    1) i understand that analytic functions are applied after detail row processing does MAX keep dense calculation happen during detail row processing?Yes
    2) how did you know to advise when to use MAX keep dense, and when to use MAX - analytic function?In general, if you want the result on a single row, so you have one row for each group then you should use the aggregate max. If you want to use the same max on all the rows in the window (defined by the partition) then use the analytic max.
    Rod West

  • Using max function in PL/SQL

    VERY URGENT...
    Am new to oracle...
    I've written a package that display gif images in form of histogram/bar chart. using html,
    I need to use max function to display values proportionately.
    please help. i need to complete this assignment by 2/9/00 by 10.00 am at the latest. I've half written a function but I don't know if there's a simpler way fo doing this. html enabled

    First of all Thanks to all gentlemen who replied ..many thanks ...
    Tried the ROW_NUMBER() option but still it is taking time...have given output for the query and tkprof results as well. Even when it doesn't fetch any record ( this is a valid cased because the input header id doesn't have any workflow request submitted & hence no entry in the wf_items table)..then also see the time it has taken.
    Looked at the RANK & DENSE_RANK options which were suggested..but it is still taking time..
    Any further suggestions or ideas as to how this could be resolved..
    SELECT 'Y', 'Y', ITEM_KEY
    FROM
    ( SELECT ITEM_KEY, ROW_NUMBER() OVER(ORDER BY BEGIN_DATE DESC) RN FROM
    WF_ITEMS WHERE ITEM_TYPE = 'xxxxzzzz' AND ROOT_ACTIVITY = 'START_REQUESTS'
    AND SUBSTR(ITEM_KEY,1,INSTR(ITEM_KEY,'-') - 1) = :B1
    ) T WHERE RN <= 1
    call count cpu elapsed disk query current rows
    Parse 0 0.00 0.00 0 0 0 0
    Execute 1 0.00 1.57 0 0 0 0
    Fetch 1 8700.00 544968.73 8180 8185 0 0
    total 2 8700.00 544970.30 8180 8185 0 0
    many thanks

  • Regarding MAX() function

    Hi,
    I am having table A. I have few records in the table A. Database version : 9.2
    ID name deleted
    2 XYZ N
    3 ABD N
    4 GJK N
    5 GJK N
    6 HGY N
    7 YJG N
    8 PIN N
    9 BMF N
    10 OLG N
    I used the following query...
    SELECT MAX(ID) FROM A WHERE DELETED='N';
    It was worked fine until now....
    Now i used the same query...
    But the result is
    MAX(ID)
    9
    Please help me... What is the reason?
    I want the correct result...
    Thanks in advance....                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

    Kamran Agayev A. wrote:
    Yes you can use TO_NUMBER inside MAX function and it will not give any error in the futureHave you tested it?
    SQL> create table a (id,name,deleted)
      2  as
      3  select '2', 'XYZ', 'N' from dual union all
      4  select '3', 'ABD', 'N' from dual union all
      5  select '4', 'GJK', 'N' from dual union all
      6  select '5', 'GJK', 'N' from dual union all
      7  select '6', 'HGY', 'N' from dual union all
      8  select '7', 'YJG', 'N' from dual union all
      9  select '8', 'PIN', 'N' from dual union all
    10  select '9', 'BMF', 'N' from dual union all
    11  select '10', 'OLG', 'N' from dual
    12  /
    Tabel is aangemaakt.
    SQL> select max(id)
      2    from a
      3   where deleted = 'N'
      4  /
    MA
    9
    1 rij is geselecteerd.
    SQL> select max(to_number(id))
      2    from a
      3   where deleted = 'N'
      4  /
                        MAX(TO_NUMBER(ID))
                                        10
    1 rij is geselecteerd.
    SQL> insert into a values ('2A', 'ABC', 'N')
      2  /
    1 rij is aangemaakt.
    SQL> select max(to_number(id))
      2    from a
      3   where deleted = 'N'
      4  /
    select max(to_number(id))
    FOUT in regel 1:
    .ORA-01722: invalid numberRegards,
    Rob.

  • Use of MAX function

    Hi,
    I am using parent-child hierarchy and in my reports I want to show Max(hierarchy_level). When I use the function MAX directly in the report it works fine in every way. But I want to have this kind of column in the BI Server presentation catalog so the user does not need to add MAX in Analysis/Answers (this is 11g). Normally this would imply a Max(hierarchy_level) as a logical function, but in the BI Server it is not allowed with MAX function in the logical function so it does not work.
    The hierarchy level is just a column from a dimension table and creating it as a fact column is not a very good solution. I also tried to solve this in many different ways, but only the MAX funtion in Analysis/Answers allways give the correct result. Used in combination with other dimensions etc. I want the exact same behaviour as I get when using MAX in analysis.
    Any good ideas to solve this? Is there another function in the BI Server that works the same way as MAX ?

    Very often, about a primary key, see for example our italian accounting application (our VAT invoices:fatture IVA) ), where the holes might be a problem.
    Yes Rosario, of course I know that, and that's why I said "in this scenario" : if primary key is the only purpose, I don't think holes could be a problem.
    Buona giornata anche a te.

  • Use of MAX function in Query Designer

    Dear all,
    i want to create a report that gives ONE line per period that holds the MAX of several lines per period. So NO addition of the KF but just one line item.
    I tried to use the MAX function and/or MAX drop-down boxes via properties on KF,
    but they all provide the wrong result (mostly the MAX after summaction of the KF).
    Any ideas ??
    Greetz,
    Herman

    Hi Herman
        Please check the KF infoobject property which might have been set to Summation.  You need to change the property of the KF to MAX if you wish to have MAX value. 
        Hope this might be helpful to you
    Thanks
    Kishore Kusupati

  • How to use MAX function in SSAS MDX Query

    I want to run this Query with MAX Condition on LAST_DATA_UPDATE Column .

    Hi Ashishsingh,
    According to your description, you want to know how to use MAX function in SQL Server Analysis Services MDX Query, right? In this case, please refer to the link below which describe the syntax and sample of MDX function.
    http://technet.microsoft.com/en-us/library/ms145601.aspx
    http://www.mdxpert.com/Functions/MDXFunction.aspx?f=64
    Hope this helps.
    Regards,
    Charlie Liao
    TechNet Community Support

  • Oracle:how to use max() function in case expression

    how to use max() function in case expression, Please explain with any example

    Hope this helps and should be self explanatory
    with t as
    (select 1 col,100 col2 from dual union
    select 2 ,100 from dual union
    select 2 ,200 from dual union
    select 3,100  from dual union
    select 3,200  from dual  )
    select col, case when max(col2)=100 then 'with 100 range'
    when  max(col2)=200 then 'with 200 range' end  from t group by col

  • How to use MAX() function with date field

    Hi Frzz,
    I have created a Graphical calculation view in which i have multiple records for each employee with different dates. But my requirement is to take the records which have maximum date.
    I have converted the date into Integer and applied the MAX() function. But still am getting multiple records.
    Is there is any other way we can achieve this requirement in Graphical Calculation view??  Your suggestion will really help me.
    Thank  you.
    Krishna.

    Hmm... what have you tried out so far?
    Look, I took the effort and created a little example, just for you
    Assume we have a table that contains the logon dates of users.
    Every line contains the logon date and some info on the user.
    Very much like a not-normalized log file could look like.
    Now, the output we want is: one line per user with the most current logon time.
    Not too difficult:
    1. Have a aggregation node that gives you the distinct user details - one line for every user:
    2. Have another aggregation node that gives you the last (MAX) logon date per user:
    Finally you do a 1:1 join on the USER_ID and map the result to the output.
    Easy as pie
    - Lars

  • Use COUNT or MAX functions inside of a query, and you have no data found

    I'm writing a query with a COUNT and a MAX function.
        SELECT  li.id
                 , MAX(m.display_date)
                , COUNT(*)
         FROM li JOIN m  ON (m.LIID=li.LIID)
        WHERE m.DISPLAY_DATE < SYSDATE - 7
        GROUP BY  li.id;I would like to write a query that returns always a row foe each row in the table li.
    If there are no records with the condition "WHERE m.DISPLAY_DATE < SYSDATE - 7", I would like to have a row with
    - COUNT(*) = 0
    - MAX(m.display_date) = TO_DATE('2010-06-08', 'YYYY-MM-DD'

    user600979 wrote:
    I'm writing a query with a COUNT and a MAX function.
    SELECT  li.id
    , MAX(m.display_date)
    , COUNT(*)
    FROM li JOIN m  ON (m.LIID=li.LIID)
    WHERE m.DISPLAY_DATE < SYSDATE - 7
    GROUP BY  li.id;I would like to write a query that returns always a row foe each row in the table li.
    If there are no records with the condition "WHERE m.DISPLAY_DATE < SYSDATE - 7", I would like to have a row with
    - COUNT(*) = 0
    - MAX(m.display_date) = TO_DATE('2010-06-08', 'YYYY-MM-DD'In that case tell me what do you want to display in the ID column. That is the first column?

  • Using Max Function in View Criteria

    Hi
    I am having a requirement where by i need to make use of max function in view criteria but not able to see any such option. Can someone please help me over it. Here is the requirement.
    In table i will be having multiple rows for an employee and i need to pick latest row based on a column say request_id For e.g.
    Emp RequestId
    A 1
    A 2
    A 3
    A 4
    So if i pass the employee id i should get Row Number 4. In simple SQL language I want something like this
    select * from emp where empid=A and requestid=( select max(requestid) from emp where empid=A)
    Just wanted to know is there any approach that i can use to do all this as part of View Criteria or any other way.
    Any help is appreciated!!!
    Thanks
    AJ

    One way is this -
    1)https://blogs.oracle.com/adf/entry/using_groovy_aggregate_functions_in (You might need to create a self-referencing VL for this , try if it works using a ViewAccessor too)
    OR
    Order by RequestId descending in your SQL for the VO if thats ok , then have the ViewCriteria for the EmpId and programmatically pickup the first row...

  • Max value without using max() function

    Hi
    Is there any way to get the max value from a table without using MAX() function
    Thanks

    well if you think about it i'm sure you'll find a solution
    what does max(field) means, it simply is the value of the field where no other value of the same field that is > than this value exists.
    consider the following :
    table TAB(
    fld NUMBER(5));
    translate the logic and you'll have
    select a.fld from TAB a where NOT EXISTS(select b.fld from TAB b where b.fld>a.fld) and rownum=1;
    of course there are better ways i'm sure, you'll just have to figure'em out.

  • Using Max function

    I have the following tables along with their attributes(the
    stared fields show the primary key:
    Agent(AgentPhoneNo*, NameOfAgent)
    Constituency(ConstituencyNo*,
    ConstituencyName,District,RegionCode)
    PollingStation(StationNo*,ConstituencyNo*,AgentPhoneNo,
    StationName)
    VoteResults(Party*, ResultsCategory*,Votes, AgentPhoneNo*)
    Results category has two values (S,L) and the number of
    parties is variable
    My issue is this, below is my code that returns the total
    votes received by each party with each constituency. This
    query works fine.
    <cfquery name="WinningPartyinConstituency"
    datasource="#request.datasource#">
    SELECT c.ConstituencyName, s.ConstituencyNo, v.Party,
    Sum(v.Votes) AS TotalVotes
    From (Constituency c
    INNER JOIN PollingStation s ON c.ConstituencyNo =
    s.ConstituencyNo)
    INNER JOIN VoteResults v ON s.AgentPhoneNo = v.AgentPhoneNo
    WHERE v.ResultCategory = 'L' AND s.ConstituencyNo IN (Select
    ConstituencyNo From Constituency)
    Group By c.ConstituencyName, s.ConstituencyNo, v.Party
    Order By c.ConstituencyName
    </cfquery>
    Now I want to check and return the name and total votes of
    the party with the maximum votes within each constituency. And but
    I can't seem to figure out how to do that, especially because the
    max() function takes only to
    values.
    I will appreciate any guidance on how to write a query that
    returns the the party with the maximum votes in each constituency
    and the votes it got. TIA

    My approach would be to do 2 or 3 Q of Qs to get the numbers
    I need.

Maybe you are looking for

  • How to change values in the form?

    Hi guys, I am working on a small JSP project. I have a form in a page. It has several textboxes getting inputs from the user. In the JSP code, I want to change the value of the textbox based on the some condition in the JSP code: <form ... action="th

  • App store is in spanish?!?

    I updated to the ios6 and now the app store is in spanish... How do I fix that?!

  • New mac air for old mac air.

    Hi. i bought a mac air last month and now i see that new mac air is coming out in the market. so can i exchange my mac air for new mac air?? what is apple exchange policy/?? help me please.

  • 10.7.2 Better than Snow Leopard 10.6.8?

    Hi. I downgraded to Snow Leopard but if are you happy with 10.7.2 or should I stick with 10.6.8 Snow for now? Thank you. I'm on a late iMac 2009 i7. Thank you in advance. Gbu, Alvin

  • Need help editing gtk theme

    hey guys recently downloaded this package http://aur.archlinux.org/packages.php?ID=22813 and installed the theme. i would like to edit the theme so that i get less of the horrid white buttons and then submit the fix to author here is the screenshot s