Help - count function returns strange results

hi everyone,
here's my scenario: i'm trying to get the NUMBER OF REPORTS and NUMBER OF
IMAGES GROUP BY MONTH from the two tables below.
REPORT
reportid(*primary key)
date
IMAGE
reportid(*foreign key referring to report's table)
image
sample output:
MONTH NO.OF REPORTS NO. OF IMAGES
feb 01 10 9
mar 01 12 8
my SQL goes like this:
select to_char(date, 'month-yy'),
count(REPORT.reportid), count(IMAGE.reportid)
from REPORT, IMAGE
where REPORT.reportid = IMAGE.reportid
group by to_char(date, 'month-yy')
the above sql yielded strange results, number of images is equal to the number of reports, which is of course wrong! as one report may or may not contain one or more image.
i dont know what's wrong with the above statement, but if i were to group it
by REPORTID and DAY rather than MONTH, then amazingly it works! what's
wrong with the count, why does it give me the same result if i group by
MONTH.
can anyone shed some light on this?

try using the following example:
Table TEST_REPORT
RPTID RPTDATE
1 02-JAN-01
3 02-JAN-01
2 02-JAN-01
5 11-FEB-01
6 11-FEB-01
7 11-FEB-01
Table TEST_IMAGE
RPTID IM
1 1
2 1
3 1
SQL:
select to_char(rptdate,'MON-YYYY'),
sum(decode(a.rptid,null,0,1)) report_cnt,
sum(decode(b.rptid,null,0,1)) image_cnt
from test_report a, test_image b
where a.rptid = b.rptid(+)
group by to_char(rptdate,'MON-YYYY');
<BLOCKQUOTE><font size="1" face="Verdana, Arial, Helvetica">quote:</font><HR>Originally posted by skcedric:
hi everyone,
here's my scenario: i'm trying to get the NUMBER OF REPORTS and NUMBER OF
IMAGES GROUP BY MONTH from the two tables below.
REPORT
reportid(*primary key)
date
IMAGE
reportid(*foreign key referring to report's table)
image
sample output:
MONTH NO.OF REPORTS NO. OF IMAGES
feb 01 10 9
mar 01 12 8
my SQL goes like this:
select to_char(date, 'month-yy'),
count(REPORT.reportid), count(IMAGE.reportid)
from REPORT, IMAGE
where REPORT.reportid = IMAGE.reportid
group by to_char(date, 'month-yy')
the above sql yielded strange results, number of images is equal to the number of reports, which is of course wrong! as one report may or may not contain one or more image.
i dont know what's wrong with the above statement, but if i were to group it
by REPORTID and DAY rather than MONTH, then amazingly it works! what's
wrong with the count, why does it give me the same result if i group by
MONTH.
can anyone shed some light on this? <HR></BLOCKQUOTE>
null

Similar Messages

  • [HELP] AGO function return wrong result

    Hi, i try to implement ago function in OBIEE, but the result is not as expected. Please help me to configure Time Dimension to get this work.
    My case:
    - I have a time dimension with this configuration:
    [http://i264.photobucket.com/albums/ii176/necrombi/NEO/1-1.png]
    Time Hierarchy: Total > Year > Quarter > Month > Day
    Year:
    Primary key: Calendar_year_cal_year_code
    Chronological key: Does not define
    Quarter:
    Primary key: Calendar_quarter_description
    Chronological key: Does not define
    Month:
    Primary key: Calendar_month_description
    Chronological key: Calendar_month_description
    Day:
    Primary key: Dimension_key
    Chronological key: Day_day_code
    My ago function: AGO(expression, mywh.D_qn_thoigianDim."month", 1)
    I do not understand why i get this wrong results:
    [http://i264.photobucket.com/albums/ii176/necrombi/NEO/2.png]
    Does anyone know how to solve this?
    Edited by: 864451 on Jun 8, 2011 5:11 AM

    Hi, thanks for your reply.
    I implemented Time dimension with your recommend, and have time dimension like this:
    Time Hierarchy: Total > Year > Quarter > Month > Day
    Year:
    Primary key: Calendar_year_start_date
    Chronological key: Calendar_year_start_date
    Quarter:
    Primary key: Calendar_quarter_start_date
    Chronological key: Calendar_quarter_start_date
    Month:
    Primary key: Calendar_month_start_date
    Chronological key: Calendar_month_start_date
    Day:
    Primary key: Day
    Chronological key: Dimension_key
    And Ago function works fine with month level: AGO(expression, mywh.D_qn_thoigianDim."month", n)
    But return sum result of 12 month with: AGO(expression, mywh.D_qn_thoigianDim."year", 1)
    In my case, i just use AGO(expression, mywh.D_qn_thoigianDim."month", 12) to get year ago value. But i still don't understand clearly about OBIEE Time Serries functions.
    Thanks,
    Dung Nguyen

  • ProxyHistory returns strange results

    Hi,
    I am trying to programmatically access the mailbox into which I most recently proxied via the GUI.
    From what I understand, a call to Groupwise.Account.Application.ProxyHistory should return a collection of mailboxes into which I recently proxied via the Groupwise GUI. When I iterate over the returned collection, some of the mailboxes are missing or are replaced by other mailboxes in the list.
    For example, my Proxy list on the Groupwise GUI shows:
    Me
    Proxy...
    1. UserA
    2. UserB
    3. UserC
    4. UserD
    5. UserE
    6. UserF
    7. UserG
    8. UserH
    9. UserI
    A call to the ProxyHistory function returns:
    1. Me
    2. Me
    3. Me
    4. UserD
    5. UserE
    6. UserE
    7. UserG
    8. UserG
    9. UserG
    Is this discrepancy a known issue? Is there a workaround for this problem?
    Thank you,
    M

    There's no such method
    There's
    getProxyListRequest
    If that's what you mean. But no method called ProxyHistory
    OTOH, there's such an animal in OBJECT API. Perhaps you should post on
    that forum.
    On 7/20/2010 12:05 PM, MK wrote:
    > Hi,
    > I am trying to programmatically access the mailbox into which I most
    > recently proxied via the GUI.
    > From what I understand, a call to
    > Groupwise.Account.Application.ProxyHistory should return a collection of
    > mailboxes into which I recently proxied via the Groupwise GUI. When I
    > iterate over the returned collection, some of the mailboxes are missing
    > or are replaced by other mailboxes in the list.
    > For example, my Proxy list on the Groupwise GUI shows:
    > Me
    > Proxy...
    > 1. UserA
    > 2. UserB
    > 3. UserC
    > 4. UserD
    > 5. UserE
    > 6. UserF
    > 7. UserG
    > 8. UserH
    > 9. UserI
    > A call to the ProxyHistory function returns:
    > 1. Me
    > 2. Me
    > 3. Me
    > 4. UserD
    > 5. UserE
    > 6. UserE
    > 7. UserG
    > 8. UserG
    > 9. UserG
    > Is this discrepancy a known issue? Is there a workaround for this problem?
    > Thank you,
    > M

  • [Solved] pacman -Qtdq is returning strange results - Please Help!

    Hi guys,
    I'm having an issue with the pacman command -
    #pacman -Qtdq
    It has been spitting out some VERY odd results. Here
    [anders@Freki ~]$ pacman -Qtdq
    abs
    agave
    alsa-utils
    archlinux-artwork
    arj
    aspell-en
    audacity
    autoconf
    automake
    bacula
    banshee
    beanshell
    bleachbit
    bluefish
    calibre
    cryptsetup
    dash
    dosfstools
    ekiga
    expect
    fakeroot
    feh
    file-roller
    firefox
    flex
    gcalctool
    gconf-editor
    gedit
    git
    gksu
    gnome-color-manager
    gnome-disk-utility
    gnome-media
    gnome-nettool
    gnome-power-manager
    gnome-utils
    gpart
    gparted
    grub2-bios
    gstreamer0.10-bad-plugins
    gtk-doc
    handbrake
    hardinfo
    heirloom-mailx
    hsqldb-java
    hunspell-en
    hyphen-en
    icedtea-web
    initscripts
    inkscape
    iputils
    jfsutils
    less
    libdvdcss
    libmspack
    libmythes
    libreoffice-base
    libreoffice-calc
    libreoffice-draw
    libreoffice-extension-ct2n
    libreoffice-extension-diagram
    libreoffice-extension-google-docs
    libreoffice-extension-hunart
    libreoffice-extension-nlpsolver
    libreoffice-extension-numbertext
    libreoffice-extension-oooblogger
    libreoffice-extension-pdfimport
    libreoffice-extension-presentation-minimizer
    libreoffice-extension-presenter-screen
    libreoffice-extension-report-builder
    libreoffice-extension-scripting-beanshell
    libreoffice-extension-scripting-javascript
    libreoffice-extension-scripting-python
    libreoffice-extension-typo
    libreoffice-extension-validator
    libreoffice-extension-watch-window
    libreoffice-extension-wiki-publisher
    libreoffice-gnome
    libreoffice-impress
    libreoffice-math
    libreoffice-sdk-doc
    libreoffice-writer
    libwpg
    licenses
    lm_sensors
    logrotate
    lucene
    lvm2
    man-db
    man-pages
    mdadm
    mesa-demos
    mousetweaks
    mythes-en
    nano
    ntfsprogs
    openshot
    os-prober
    pacman
    parcellite
    patch
    pcmciautils
    perl-passwd-md5
    pkg-config
    pstoedit
    python2-gtkspell
    python2-numpy
    rdesktop
    reiserfsprogs
    samba
    skype
    skype-call-recorder
    sound-juicer
    soundconverter
    subversion
    sudo
    syslog-ng
    telepathy-butterfly
    telepathy-gabble
    telepathy-haze
    telepathy-idle
    telepathy-salut
    telepathy-sofiasip
    texlive-core
    thunderbird
    tomboy
    tomoyo-tools
    truecrypt
    ufw
    unace
    unetbootin
    uniconvertor
    unrar
    vala
    vi
    vigra
    vino
    virtualbox
    virtualbox-additions
    wgetpaste
    which
    wicd-gtk
    xchat
    xdotool
    xf86-video-ati
    xfsprogs
    xorg-twm
    xorg-utils
    xorg-xclock
    xorg-xinit
    xsane-gimp
    xscreensaver
    xterm
    I first noticed this when I removed lxde and awesome after I was done playing with them and pacman took out pkgs necessary to run gnome. As you can see some x pkgs are listed as orphans, along with things that were not orphans before, like abs and firefox. My orphan list used to be only a few items long because gwibber apparenly has some build items that are no longer needed after install like dee and vala.
    I've tried reinstalling the listed pkgs, ALL of my installed pkgs, and nothing. It keeps reporting this same string of pkgs and it is making me afraid to remove xscreensaver (the one thing on the list I don't want to keep) because I am afriad of pacman taking out too many pkgs. Installs seem to be working just fine, and I only use pacman to install pkgs on this system, I always use
    sudo pacman -S pkgname
    or
    sudo pacman -U /path/to/aur/pkg
    and I only update via
    sudo pacman -Syu
    So is there any way to "rebuild" the dependancy tree that I don't know about? I looked thourgh the Wiki and did not see anything.
    Could I have removed a pkg(s) that has broken Pacman's dependancy tree?
    Is there any more info that you guys might need to help me out with this?
    - Thanks for any help,
    Anders H
    Last edited by Anders H (2012-02-14 09:34:13)

    For some reason theses packages are installed as a dependency for another package, but they're not required by any package.
    Can you post the output of e.g. 'pacman -Qi less'?
    -D, --database
    Modify the package database. This operation allows you to modify
    certain attributes of the installed packages in pacman’s database.
    At the moment, you can only change the install reason using
    --asdeps and --asexplicit options.
    [karol@black ~]$ pacman -Qi less
    Name : less
    Version : 444-3
    URL : http://www.greenwoodsoftware.com/less
    Licenses : GPL3
    Groups : base
    Provides : None
    Depends On : ncurses pcre
    Optional Deps : None
    Required By : None
    Conflicts With : None
    Replaces : None
    Installed Size : 220,00 KiB
    Packager : Allan McRae <[email protected]>
    Architecture : i686
    Build Date : pon, 6 lut 2012, 03:25:08
    Install Date : czw, 9 lut 2012, 21:09:29
    Install Reason : Explicitly installed
    Install Script : No
    Description : A terminal based program for viewing text files
    [karol@black ~]$ pacman -Qi less | grep -e "Required By" -e "Install Reason"
    Required By : None
    Install Reason : Explicitly installed
    [karol@black ~]$ pacman -Qdt
    [karol@black ~]$ pacman -D --asdeps less
    less: install reason has been set to 'installed as dependency'
    [karol@black ~]$ pacman -Qi less | grep -e "Required By" -e "Install Reason"
    Required By : None
    Install Reason : Installed as a dependency for another package
    [karol@black ~]$ pacman -Qdt
    less 444-3
    I've changed the install reason and now 'less' shows up as an orphan.

  • Mathscript contourf function produces strange results

    the code "contourf(magic(8))" typed into the mathscripts window produces a different result from the same single line in matlab.  The resolution and colormap differences don't bother me, but the line fragments are clearly incorrect.  This is a simple example of a problem I'm having in my data.  Further, if I'd like to plot the contour line myself, the "hold on" function does not seem to work with the contour.  Any help would be much appreciated.  A simple example demonstrating both problems:
    clf
    colormap(jet)
    contourf(magic(8));
    hold on
    plot(1:8,1:8,'r*')
    shg
    piyrwq
    Attachments:
    matlabmagic8.jpg ‏35 KB
    mathscriptsmagic8.jpg ‏143 KB

    Hello,
    I have looked into this issue some more.  I talked to the developer who wrote the colormap function and it turns out we do have all the colormaps.  However, their use is not documented.  They are passed to the function as an option, e.g. colormap('jet').
    In addition, the order of calls matters.  The colormap only applies to the current plot.  If you generate a new one, the colormap disappears.  Consequently, reverse the order of your colormap and contourf calls as follows:
    contourf(magic(8));
    colormap('jet')
    Grant M.
    Staff Software Engineer | LabVIEW Math & Signal Processing | National Instruments

  • HTMLDB_ITEM.SELECT_LIST function returns wrong result in 1.6?

    Look at following select statements:
    1. select flows_010600.htmldb_item.select_list(1,null,'Full;F,Read;R,No;N',
    '','YES',null,'Derived','f01_'||TO_CHAR(ROWNUM,'FM0000'),'D')
    from dual
    &lt;label for="f01_0001" class="hideMe508"&gt;D&lt;/label&gt;&lt;select name="f01" id="f01_0001"&gt;&lt;option value=""&gt;Derived&lt;/option&gt;&lt;option value="F" &gt;Full&lt;/option&gt;&lt;option value="R" &gt;Read&lt;/option&gt;&lt;option value="N" &gt;No&lt;/option&gt;&lt;option value="" selected="selected"&gt;&lt;/option&gt;&lt;/select&gt;
    2.select flows_010500.htmldb_item.select_list(1,null,'Full;F,Read;R,No;N',
    '','YES',null,'Derived','f01_'||TO_CHAR(ROWNUM,'FM0000'),'D')
    from dual
    &lt;label for="f01_0001" class="hideMe508"&gt;D&lt;/label&gt;&lt;select name="f01" id="f01_0001"&gt;&lt;option value=""&gt;Derived&lt;option value="F" &gt;Full&lt;option value="R" &gt;Read&lt;option value="N" &gt;No&lt;/select&gt;
    If selected value of list is null version 1.6 call adds extra item without display value. Version 1.5 call works fine. Is it a bug or implied behavior?

    Hi Alexey,
    This is the intended behavior; in your htmldb_item.select_list call, you are setting the current value to NULL. This is the value shown in 1.6. In 1.5 the first value from your list of values was shown. This behavior wasn't appropriate in most cases. If for example you had a tabular form with a select list and the values retrieved from the database were not part of the list of values used for the select list, it would basically default the select list to the first value from your list of values. If you then saved your tabular form, you would have ended up with the wrong data. Now the select list will show the actual value from the database, if it's not part of the list of values. Otherwise it will show the correct display value. If in your case this is not the behavior you need, you can simply turn that off by modifying your query to:
    select flows_010600.htmldb_item.select_list(1,null,'Full;F,Read;R,No;N',
    '','YES',null,'Derived','f01_'||TO_CHAR(ROWNUM,'FM0000'),'D','NO')
    from dual
    I simply added another attribute which is called p_show_extra and set it to 'NO'. Here's the full specification of the function:
    function select_list (
    p_idx in number,
    p_value in varchar2 default null,
    p_list_values in varchar2 default null,
    p_attributes in varchar2 default null,
    p_show_null in varchar2 default 'NO',
    p_null_value in varchar2 default '%null%',
    p_null_text in varchar2 default '%',
    p_item_id in varchar2 default null,
    p_item_label in varchar2 default null,
    p_show_extra in varchar2 default 'YES'
    ) return varchar2
    Hope this helps,
    Marc

  • HELP!! Return Key results in multiple lines down

    Everytime I press the return key, pages returns at least 10 lines. i can't figure out what is going wrong. PLEASE HELP

    Put the cursor where you just hit return. Bring up the Text Inspector, Text panel. Check the settings under Spacing for Line, Before Paragraph and After Paragraph. Those all control how much space results when you hit enter.
    You probably want Before Para and After Para to be at zero. You might need to select all text before making the change.

  • ResultSet returning strange results for BIGINT datatype, using rs.getLong()

    In a MySQL db I have a value of 10 for the BIGINT primary key column 'account', which is auto-incrementing.
    The result of rs.getLong("account") is:
    4.294967305E9
    Not exactly the answer I was looking for. The other column, 'phoneNum', also a BIGINT, and also using rs.getLong("phoneNum") is returning correctly.
    And ideas why?

    The number in question is 4,294,967,305. There was another thread here recently about MySQL using numbers that are just slightly above 2^32 (which is 4,294,967,296) in auto-increment columns.

  • LibreOffice Calc - insertion of current date returns strange result

    Hey,
    When i want to insert the current date with the command TODAY() i get a result like this:
    25.[~bu250i0t] Oktober 2011
    The [~bu250i0t] is obviously what annoys me! How do i get it away?
    Cheers

    Why the language? My mother tongue happens to be German, nothing wrong about that!
    I just want to get rid of the digits and letters within the date...
    Last edited by gunjah292 (2011-10-25 16:54:38)

  • IsTransactionDirty returns strange results ?

    Jclient, if I insert a record and then I call as follows:
    boolean result = panelBinding.isTransactionDirty();
    or
    boolean result2 = panelBinding.findIterBinding("testIter").getApplicationModule().getTransaction().isDirty();
    System.out.println(result + " " + result2);
    Output:
    true false
    does anyone know why the results are not the same ?

    Jclient, if I insert a record and then I call as follows:
    boolean result = panelBinding.isTransactionDirty();
    or
    boolean result2 = panelBinding.findIterBinding("testIter").getApplicationModule().getTransaction().isDirty();
    System.out.println(result + " " + result2);
    Output:
    true false
    does anyone know why the results are not the same ?

  • Connect by in R2 return strange result.

    Step to reproduce:
    1.
    create or replace type TST_OBJ_REC as object (
    ID Integer,
    Parent_ID Integer,
    OValue Integer
    );2.
    create or replace type TST_OBJ_TBL as table of TST_OBJ_REC;3.
    create table TST_TBL as select * from TABLE(TST_OBJ_TBL (
    TST_OBJ_REC(ID => 1, Parent_ID => -1, OValue => 1),
    TST_OBJ_REC(ID => 2, Parent_ID => 1, OValue => 2),
    TST_OBJ_REC(ID => 3, Parent_ID => 2, OValue => 3)
    ));Query on table:
    select * from tst_tbl a
      connect by prior a.id = a.parent_id
      start with a.id = 2All fine:
    ID PARENT_ID OVALUE
         2     1     2
         3     2     3
    Query from object:
    select * from (TABLE(TST_OBJ_TBL (
    TST_OBJ_REC(ID => 1, Parent_ID => -1, OValue => 1),
    TST_OBJ_REC(ID => 2, Parent_ID => 1, OValue => 2),
    TST_OBJ_REC(ID => 3, Parent_ID => 2, OValue => 3)
    ))) a
    connect by prior a.id = a.parent_id
      start with a.id = 2Result different !!
    ID PARENT_ID OVALUE
         2     1     null
         3     2     null
    select A.* from (TABLE(TST_OBJ_TBL (
    TST_OBJ_REC(ID => 1, Parent_ID => -1, OValue => 1),
    TST_OBJ_REC(ID => 2, Parent_ID => 1, OValue => 2),
    TST_OBJ_REC(ID => 3, Parent_ID => 2, OValue => 3)
    ))) a
    connect by prior a.id = a.parent_idstart with a.id = 2
    ID PARENT_ID OVALUE
         null     null     null
    select A.*, connect_by_isleaf from (TABLE(TST_OBJ_TBL (
    TST_OBJ_REC(ID => 1, Parent_ID => -1, OValue => 1),
    TST_OBJ_REC(ID => 2, Parent_ID => 1, OValue => 2),
    TST_OBJ_REC(ID => 3, Parent_ID => 2, OValue => 3)
    ))) a
    connect by prior a.id = a.parent_id
      start with a.id = 2ID PARENT_ID OVALUE connect_by_isleaf
         null     null     null 1
    And final
    select id, parent_id, oValue,  connect_by_isleaf from (TABLE(TST_OBJ_TBL (
    TST_OBJ_REC(ID => 1, Parent_ID => -1, OValue => 1),
    TST_OBJ_REC(ID => 2, Parent_ID => 1, OValue => 2),
    TST_OBJ_REC(ID => 3, Parent_ID => 2, OValue => 3)
    ))) a
    connect by prior a.id = a.parent_id
      start with a.id = 2ID PARENT_ID OVALUE connect_by_isleaf
         2     1     2 0
         3     2     3 1
    This behaviour normal ? In 11R1 All ok.
    Edited by: D.Andreychik on 07.06.2010 7:38
    Edited by: D.Andreychik on 07.06.2010 7:40

    Please read the FAQ and learn how to use tags to make your listing readable.
    Then update your post so it will be properly formatted. Thank you.                                                                                                                                                                                                                                                                                                                   

  • Count(1) returns null in group by

    hi gems..good afternoon..
    I read that the COUNT() function always returns 0 (zero) if there is no matching rows in the table.
    The following code returns the 0 as expected:
    SELECT COUNT(1) FROM book_table
                 WHERE client_id = 10009
                   AND book_id = 5465465
                   AND book_sub_id = 'gfdf'
                   AND amount = 78686But when I used the GROUP BY clause with the query, then it returned nothing:
    SELECT COUNT(1) FROM book_table
                 WHERE client_id = 10009
                   AND book_id = 5465465
                   AND book_sub_id = 'gfdf'
                   AND amount = 78686
    group by client_id,book_id,book_sub_id,amountWhy this is happening..please suggest...

    gogol wrote:
    But Ranit...
    Again I am thinking...the COUNT() is an aggregate function. Now a function should return something(as per my plsql knowledge) and in this case the return datatype is integer. So why isnt it returning zero..Don't think like that sandy.
    The Group By is actually done on an empty result set, so the result is neither 0 nor NULL
    It is an empty result set.
    Check this -- http://stackoverflow.com/questions/2552086/does-count-always-return-a-result
    >
    The "return value of the 'count' function" is ALWAYS a non-null integer, without exception. By mentioning "group by", you're referencing the containing query and changing the subject of "return value" from "count function" to "query's result set". A non-grouped count query produces a result set of a single record containing the return value of count. Alternatively, a grouped count query produces a result set where each record contains a count value. In that case, if there are no groups for count to run on, count is never run and the "query return value" is an empty set.
    >
    Hope this Helps.
    Ranit B.
    Edited by: ranit B on Nov 23, 2012 5:25 PM

  • Function returning a query

    Hi guys,
    A query suddenly became very slow & has remained like it while connecting over a database. I assume the reason is because the data is being retrieved from 6 tables across a link (6 different connections to the same database) so I thought a view should be better as I had a similar issue and this seemed to resolve it. However I then thought that perhaps a function returning the results would be faster as it would mean I could include the where clauses & group by clause to be done remotely on the database rather than locally after much more rows were returned...is this assumption correct?
    My query is as follows:
    select     rpad(username,18) user_name, rpad(terminal,18) terminal_id, rpad(userhost,30) host_name, 
               action_name, count(*) actions, sum(sessioncpu) session_cpu
    from
    select     username,
       terminal,
       userhost,
       action_name,
       to_char(timestamp,'DD/MM/YYYY HH24:MI:SS') timestamp,
       logoff_time,
       returncode, session_cpu sessioncpu
    from       dba_audit_session@XXX
    where (logoff_time >= sysdate - :P1_RAD
    AND :P1_RAD IS NOT NULL AND :P1_RAD != -1
    AND :REQUEST != 'But')
    OR (logoff_time >= to_TIMESTAMP(TO_DATE(:P1_FROM, 'DD-MON-YY') || ' ' || :P1_FROM_HOUR, 'DD-MON-YY HH24:MI:SS')
    AND logoff_time < to_TIMESTAMP(TO_DATE(:P1_TO, 'DD-MON-YY') || ' ' || :P1_TO_HOUR, 'DD-MON-YY HH24:MI:SS')
    AND :REQUEST = 'But'
    AND :P1_FROM IS NOT NULL AND :P1_TO IS NOT NULL)
    union
    select username,
            terminal,
       userhost,
       action_name,
       to_char(timestamp,'DD/MM/YYYY HH24:MI:SS') timestamp,
       logoff_time,
       returncode, sessioncpu
    from
    select
           userid            USERNAME ,
           userhost          USERHOST ,
           terminal          TERMINAL ,
           cast (
               (from_tz(ntimestamp#,'00:00') at local) as date) timestamp,
           act.name          ACTION_NAME ,         
           logoff$time logoff_time      /* LOGOFF_TIME   */,
           sessionid         /* SESSIONID */,
           returncode        /* RETURNCODE */,      
           sessioncpu        /* SESSION_CPU */      
    from sys.aud_archive@XXX aud, system_privilege_map@XXX spm, system_privilege_map@XXX spx,
         STMT_AUDIT_OPTION_MAP@XXX aom, audit_actions@XXX act
    where   aud.action#     = act.action    (+)
      and - aud.logoff$dead = spm.privilege (+)
      and   aud.logoff$dead = aom.option#   (+)
      and - aud.priv$used   = spx.privilege (+)
    and act.action between 100 and 102
    where (logoff_time >= sysdate - :P1_rad
    AND :P1_RAD IS NOT NULL AND :P1_RAD != -1
    AND :REQUEST != 'But')
    OR (logoff_time >= to_TIMESTAMP(TO_DATE(:P1_FROM, 'DD-MON-YY') || ' ' || :P1_FROM_HOUR, 'DD-MON-YY HH24:MI:SS')
    AND logoff_time < to_TIMESTAMP(TO_DATE(:P1_TO, 'DD-MON-YY') || ' ' || :P1_TO_HOUR, 'DD-MON-YY HH24:MI:SS')
    AND :REQUEST = 'But'
    AND :P1_FROM IS NOT NULL AND :P1_TO IS NOT NULL)
    group by username,   terminal,   userhost,    action_name
    order by actions desc;So it would take 6 parameters (p1_rad, request, p1_from, p1_to, p1_from_hour, p1_to_hour) and return a table with 8 columns. Would the WHERE & GROUP BY clauses being done remotely rather than on APEX be much better?
    Mike

    In general functions don't help much to increase the performance.
    However sometimes you can programatically choose different select statements depending whether a parameter is filled by the user or not. This allows you as a programmer to provide different and optimized statements depening on the input conditions.
    simplified pseudocode example
    "SELECT"
    select *
    from myTable
    where (column1 = :param1 or :param1 is null); /* problematic to get an index scon on column1 for this OR expression */
    "PL/SQL"
    if :param1 is null then
      select *
      bulk collect into ...
      from myTable; /* Full table scan will be used */
    else
      select *
      bulk collect into ...
      from myTable
      where column1 = :param1; /* index scan on column1 can be used, column historgrams will be considered */
    end if;

  • Oracle function and query return different results

    Hi, I am using oracle 10g database.
    Function is :
    create or replace FUNCTION FUNC_FAAL(myCode number,firstDate date
    *, secondDate date)*
    RETURN INTEGER as
    rtr integer;
    BEGIN
    select count() into rtr*
    from myschema.my_table tbl where tbl.myDateColumn between firstDate and
    secondDate and tbl.kkct is null and tbl.myNumberColumn  = myCode ;
    return (rtr);
    END FUNC_FAAL;
    This function returns 117177 as result.
    But if I run same query in the function seperately ;
    select count()*
    from myschema.my_table tbl
    where tbl.myDateColumn between firstDate and secondDate
    and tbl.kkct is null and tbl.myNumberColumn  = myCode ;
    I get different result 11344 (which is the right one).
    Table and function are in the same schema.
    What can be the problem ?
    Thanks.

    1. i think ur parameter name and Column names are same Firstdate and seconddate try to choose different name
    2. try using Trunc function around your dates
    where trunc(tbl.myDateColumn) between trunc(firstDate) and trunc(secondDate)then compare the result....sometimes time elements comes into play.
    Baig
    [My Oracle Blog|http://baigsorcl.blogspot.com/]

  • HELP needed to write a function returning 1 record from join tables

    Hi,
    I would like to have some help to write a function so It can return 1 result.
    I post my question in the APEX Express sextion but I think it's belong here.
    Mount Points and Home Directory
    Also, can I move a thread in another forum?
    thanks
    Roseline
    Edited by: user8772975 on 2009-09-19 21:43

    ok, I think I started to understand the functions. But I still can't figured out
    CONTEXT
    We are scanning pages and images from different newspaper. All the .tif, .jpg are on DVDs.
    I'm trying to build a search page who will allow for all DVDs and All images name related to the search result. Let say I search for:
    FIGARO
    I have this SQL query and I want to make a function that will return the same thing as:
    select     
          "DOSSIER"."ID" as "DOSSIERID",
          "DOSSIER"."TITLE" as "TITLE",
          "DVD"."ID" as "DVDID",
          "DVD"."NAME" as "DVDNAME",
          "DVD"."ID_DOSSIER" as "DVD_ID_DOSSIER",
          "ELEMENTS"."ID" as "ELEMENTSID",
          "ELEMENTS"."NAME" as "ELEMENTSNAME",
          "ELEMENTS"."ID_DVD" as "ELEMENTS_ID_DVD"
    from      "DOSSIER" "DOSSIER",
               "DVD" "DVD",
               "ELEMENTS" "ELEMENTS"
    where   "DVD"."ID_DOSSIER"="DOSSIER"."ID"
    and      "ELEMENTS"."ID_DVD"="DVD"."ID"
      and       "DOSSIER"."TITLE" = :P3_SEARCH
    ORDER BY "DVD".NAMEBasiccly, We are scanning pages and images from different newspaper. All the .tif, .jpg are on DVDs.
    So we have someting like that:
    TITLE: FIGARO
    DVD:        C2008-203
    Elements: 12l10201.tif, 12l10202.tif, 12l11101.tif, 12l11102.tif, 12l11201.tif
                    12l11202.tif, 12l12101.tif, 12l12102.tif
    DVD         C2008-204
    Elements: 12l12202.tif, 12l13101.tif, 12l13102.tif, 12l13201.tif, 12l13202.tif,
                   12l14101.tif, 12l14102.tif, 12l14201.tif, 12l14202.tif, 12l15101.tif,
                   12l15102.tif, 12l15201.tif
    DVD:       C2008-205
    Elements: 12l15202.tif, 12l16101.tif, 12l16102.tif, 12l16201.tif, 12l16202.tif,
                    12m01101.tif, 12m01102.tif, 12m01201.tifBased on what people on the forum told me, I now know that I have to use Pl/SQL so I have to write a function that will return the same thing as the prvious query.
    Is that exact?
    Based on this example,
    [http://plsql-tutorial.com/plsql-functions.htm|http://plsql-tutorial.com/plsql-functions.htm]
    I would write something like:
    CREATE FUNCTION my_super_function
    RETURN VARCHAR(2000);
    IS
    details VARCHAR(2000);
    BEGIN
    select     
          "DOSSIER"."ID" as "DOSSIERID",
          "DOSSIER"."TITLE" as "TITLE",
          "DVD"."ID" as "DVDID",
          "DVD"."NAME" as "DVDNAME",
          "DVD"."ID_DOSSIER" as "DVD_ID_DOSSIER",
          "ELEMENTS"."ID" as "ELEMENTSID",
          "ELEMENTS"."NAME" as "ELEMENTSNAME",
          "ELEMENTS"."ID_DVD" as "ELEMENTS_ID_DVD"
    from      "DOSSIER" "DOSSIER",
               "DVD" "DVD",
               "ELEMENTS" "ELEMENTS"
    where   "DVD"."ID_DOSSIER"="DOSSIER"."ID"
    and      "ELEMENTS"."ID_DVD"="DVD"."ID"
      and       "DOSSIER"."TITLE" = :P3_SEARCH
    RETURN details;
    END;
    / And then, use soemthing like:
    select my_super_function("DOSSIER"."ID") from "DOSSIER" "DOSSIER" where "DOSSIER"."TITLE" = :P3_SEARCHI'm kinda of lost. I spent the last 6 hours but I think that programming is a working progress.
    Any hint would be appreciated,
    thanks
    Roseline

Maybe you are looking for

  • Meter squared symbol in pages for iPad

    Hey Guys, Does anyone know how to make the meter squared symbol in Pages for iPad? I cant find away to push the 2 up. Thanks Tom

  • Call library node - using a structure with dll

    Hi folks. I was hoping to recieve some help or advice on solving this problem I am having in labview: Some background info - I am trying to use the 'call library node' to allow me to use a .dll to allow for control of a remote power supply over RS-23

  • Series of Dark Spots at the Screen Bottom

    Hi all, Just purchased my Macbook Pro 15" w/ Anti-Glare LCD screen. This is the 4th Mac I've owned over the years so I'm familiar with them. The second time I went to use it, I noticed a series of dark spots positioned horizontally at the bottom of t

  • Third Party Apps in AppWorld

    If something as basic as mute camera noise could be addressed in the OS it would eliminate the need to download 3rd party programs as well as eliminating the need to expose yourself the possibility of phony software. Not that any coder worth their sa

  • Insert Using SELECT & Sub-SELECT

    Hi All, I am trying to insert records into a table using SELECT statement. The SELECT statement has a Sub-SELECT statement as follows: INSERT INTO table1(c1,c2,c3,c4,c5) SELECT c1,c2, (SELECT MAX(C3)+a1.c3 FROM table1 WHERE c1 = var1 AND c2 = a1.c2 G