Compare the result of a query with a number and return a message

Hello
I have the following query in oracle 9i:

SELECT COUNT (*)
OF hourly_files
WHERE date_received = TO_DATE ((SELECT TO_CHAR (SYSDATE - INTERVAL '1' DAY, 'DDMMYYYY')
(THE DOUBLE), 'DDMMYYYY');

This will produce a number of lines required

I need to compare the number of output with another number hardcoded (threshold) and print an appropriate example message

If the result of the query above is 18000 and the number of threshold is fixed at 20000, then output a meesage:

Number of files received less than 2000

Any help will be very appreciated!

Thank you.
SQL> ed
Wrote file afiedt.buf

  1  SELECT CASE WHEN COUNT(*) >5 THEN 'Number is > than 5'
  2              WHEN COUNT(*) <1 THEN 'Its less than 1'
  3  ELSE 'Its in between'
  4  END
  5  FROM emp
  6* WHERE deptno=20
SQL> /

CASEWHENCOUNT(*)>5
------------------
Its in between

SQL> SELECT COUNT(*) FROM emp
  2  WHERE deptno=10;

  COUNT(*)
----------
         3

Tags: Database

Similar Questions

  • When I subtract two numbers DBL and try to compare the result with another DBL, it fails

    I found a curious problem with subtraction and compare numbers DBL in LabVIEW (8.6). Here's how it works:

    1. subtract two numbers DBL such that the result is not incorporated. (Say, 3.2 - 3.1)

    2. compare the result with a constant/control that is on the result of the subtraction (in the example, 0.1)

    3 see the output of the comparison.

    If the result of the subtraction is an integer, the Boolean result is (as expected). If the result is not complete, the comparison fails.

    (Now, if I simply compare two floating point numbers, it works, so the issue is not with the node comparison itself, but with the data that is entered to the node). Can someone understand why this happens? It's unexpected, it's a pretty serious bug.

    It is provided with all programming languages. Numbers do not have an exact binary floating-point representation. This has been discussed endlessly. Never use the equal function with floats. You can use the function in the range and force.

  • Call Service, run a query with a LimitFilter and a comparator, extend

    I have a lot of difficulties running an InvocationService. I'm relatively new to coherence, please excuse my ignorance

    Basically, I'm trying to get a web client access to a cluster of consistency (which uses * extend) and run a query with a LimitFilter and a comparator.
    It looks that I implement the PortableObject interface on the comparator. I don't know how to be honest, and I'm getting an exception
    : java.io.NotSerializableException:com.tangosol.util.internal.ConcurrentCounter

    Do I need to apply the laptop on the comparator? I have to add the Group of comparison in a pof config XML? I have configuration errors?

    Java code:
            InvocationService service = (InvocationService)  CacheFactory.getConfigurableCacheFactory().ensureService("ExtendTcpInvocationService");
            Map map = service.query(new LatestContentAgent(), null);
            Set result = (Set) map.get(service.getCluster().getLocalMember());
    public class LatestContentAgent extends AbstractInvocable {
    
         private static final long serialVersionUID = 5121824227545845101L;
    
         @Override
         public void run() {
              final Filter filter = new EqualsFilter("getStatusId", Status.LIVE);
                    final LimitFilter limitFilter = new LimitFilter(filter,200);
                    NamedCache cacheInstance = CacheFactory.getCache("dist-extend-cache");
                    setResult(cacheInstance.entrySet(limitFilter,  new ActivityContentVOComparator()));
         }
    }
    public class ActivityContentVO extends AbstractEvolvable implements Serializable, Cacheable {
    
         private static final long serialVersionUID = 1282169603551341131L;
         
         private static final int VERSION = 2; 
    
         private static final int WHEN_IDX = 2;
         private Date when;
    
         public ActivityContentVO() {     // hibernate needs this constructor
         }
         
         public Date getWhen() {
              return when;
         }
    
         public void setWhen(Date when) {
              this.when = when;
         }
    
         public void readExternal(PofReader reader) throws IOException {
              setWhen((Date) reader.readObject(WHEN_IDX));
         }
    
         public void writeExternal(PofWriter writer) throws IOException {
              writer.writeObject(WHEN_IDX, getWhen());
         }
    
         @Override
         public int getImplVersion() {
              return VERSION;
         }
    }
    public class ActivityContentVOComparator implements Comparator<ActivityContentVO>, Serializable,PortableObject {
    
        private static final long serialVersionUID = -8536328258251728594L;
    
        @Override
         public int compare(ActivityContentVO a1, ActivityContentVO a2) {
              if ( a1 == null) {
                return a2 == null ? 0 : 1;
            }
            if (a2 == null) {
                return -1;
            }
            
            final Date d1 = a1.getWhen();
            final Date d2 = a2.getWhen();
            if (d1 == null) {
                return d2 == null ? 0 : 1;
            } else if (d2 == null) {
                return -1;
            }
            
            return d2.compareTo(d1);
         }
    
        @Override
        public void readExternal(PofReader arg0) throws IOException {
            // TODO Auto-generated method stub
            
        }
    
        @Override
        public void writeExternal(PofWriter arg0) throws IOException {
            // TODO Auto-generated method stub
            
        }
    }
    POF configuration file
    <pof-config>
      <user-type-list>
        <!-- coherence POF user types -->
        <include>coherence-pof-config.xml</include>
        <user-type> 
          <type-id>1004</type-id> 
          <class-name>net.tm.ActivityContentVO</class-name> 
        </user-type>
        ....
        <user-type>
          <type-id>1009</type-id> 
          <class-name>net.tm.ActivityContentVOComparator</class-name> 
        </user-type>
      </user-type-list>
      <allow-interfaces>true</allow-interfaces>
      <allow-subclasses>true</allow-subclasses>
    </pof-config>
    Configuration consistency client-side:
    <remote-invocation-scheme>
          <scheme-name>extend-invocation</scheme-name>
          <service-name>ExtendTcpInvocationService</service-name>
          <initiator-config>
            <tcp-initiator>
                   <remote-addresses>
                            <socket-address>
                                <address system-property="tangosol.coherence.extend.remote.node1"></address>
                                <port system-property="tangosol.coherence.extend.invocation.remote.port1">9094</port>
                            </socket-address>
                            <socket-address>
                                <address system-property="tangosol.coherence.extend.remote.node2"></address>
                                <port system-property="tangosol.coherence.extend.invocation.remote.port1">9094</port>
                            </socket-address>
                        </remote-addresses>
                        <connect-timeout>10s</connect-timeout>
                      </tcp-initiator>
                      <outgoing-message-handler>
                        <request-timeout>5s</request-timeout>
                      </outgoing-message-handler>
                    </initiator-config>
                <serializer>
                    <class-name>com.tangosol.io.pof.ConfigurablePofContext</class-name>
                    <init-params>
                        <init-param>
                            <param-type>String</param-type>
                            <param-value system-property="tangosol.pof.config">app-pof-config.xml</param-value>
                        </init-param>
                    </init-params>
                </serializer>           
    </remote-invocation-scheme>
    Consistent server configuration
            <proxy-scheme>
                <scheme-name>extend-proxy</scheme-name>
                <service-name>ExtendTcpProxyService</service-name>
                <thread-count>5</thread-count>
                <acceptor-config>
                    <tcp-acceptor>
                        <local-address>
                            <address>localhost</address>
                            <port system-property="tangosol.coherence.extend.port">9094</port>
                        </local-address>
                    </tcp-acceptor>
                </acceptor-config>
                <proxy-config>
                    <cache-service-proxy>
                        <lock-enabled>true</lock-enabled>
                    </cache-service-proxy>
                </proxy-config>
                <autostart 
                     system-property="tangosol.coherence.extend.enabled">
                     false
                </autostart>
            </proxy-scheme>
    It's filling stack trace
     TcpConnection(Id=0x000001297F449E980A640BB49B3E90457BFBA97FDB268F4DCF95962206C4C35D, Open=true, LocalAddress=10.100.11.180:90
    94, RemoteAddress=10.100.130.22:4989)
    2010-06-28 16:54:50.398/277.593 Oracle Coherence GE 3.5.3/465 <D6> (thread=Proxy:ExtendTcpProxyService:TcpAcceptor, member=3): Opened: Channel(Id=1588644627, Open=true, Connection=0x000001297F449E980A640BB49B3E90457BFBA97FDB268F4DCF95962206C4C35D)
    2010-06-28 16:54:50.528/277.723 Oracle Coherence GE 3.5.3/465 <Error> (thread=Proxy:ExtendTcpProxyService:TcpAcceptorWorker:3, member=3): An exception occurred while encoding a Response for Service=Proxy:ExtendTcpProxyService:TcpAcceptor: java.io.NotSerializableException: com.tangosol.util.internal.ConcurrentCounter
            at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1156)
    
    ....
       at com.tangosol.io.pof.PofBufferWriter$UserTypeWriter.writeObject(PofBufferWriter.java:2092)
            at com.tangosol.coherence.component.net.extend.message.Response.writeExternal(Response.CDB:15)
            at com.tangosol.coherence.component.net.extend.Codec.encode(Codec.CDB:23)
            at com.tangosol.coherence.component.util.daemon.queueProcessor.service.Peer.encodeMessage(Peer.CDB:23)
            at com.tangosol.coherence.component.util.daemon.queueProcessor.service.peer.acceptor.TcpAcceptor.encodeMessage(TcpAcceptor
    .CDB:8)
            at com.tangosol.coherence.component.util.daemon.queueProcessor.service.Peer.send(Peer.CDB:16)
            at com.tangosol.coherence.component.util.daemon.queueProcessor.service.Peer.post(Peer.CDB:23)
            at com.tangosol.coherence.component.net.extend.Channel.post(Channel.CDB:25)
            at com.tangosol.coherence.component.net.extend.Channel.send(Channel.CDB:6)
            at com.tangosol.coherence.component.net.extend.Channel.receive(Channel.CDB:55)
            at com.tangosol.coherence.component.util.daemon.queueProcessor.service.Peer$DaemonPool$WrapperTask.run(Peer.CDB:9)
            at com.tangosol.coherence.component.util.DaemonPool$WrapperTask.run(DaemonPool.CDB:32)
            at com.tangosol.coherence.component.util.DaemonPool$Daemon.onNotify(DaemonPool.CDB:63)
            at com.tangosol.coherence.component.util.Daemon.run(Daemon.CDB:42)
            at java.lang.Thread.run(Thread.java:619)
    Published by: user6122052 on June 28, 2010 09:46

    Hi user6122052,

    The problem is that you try to return the result of a query:

    setResult(cacheInstance.entrySet(limitFilter,  new ActivityContentVOComparator()));
    

    and this set is an instance of com.tangosol.util.ConverterCollections$ ConverterEntrySet, which is not serializable. So, you can either convert it, for example:

    Set setResults = cacheInstance.entrySet(limitFilter,  new ActivityContentVOComparator());
    Set setConverted = new HashSet(setResults.size());
    for (Iterator iter = setResults.iterator(); iter.hasNext(); )
        {
        Map.Entry entry = (Map.Entry) iter.next();
        setConverted.add(entry.getValue());
        }
    setResult(setConverted);
    

    or better yet - query the cache directly from your customer Extend.

    Kind regards
    Dimitri

  • Need to print the results of a query in a CASE statement

    I want to print the results of a query in a CASE statement:

    SELECT RUN_STATUS

    Of

    (select check BOX WHEN COUNT (ROW_WID) = 0 THEN 'NO JOBS RAN AFTER' |) (select sysdate - XXAFL_MINUTES MINUTE)

    END RUN_STATUS

    of W_ETL_RUN_SDTL

    where START_TS >

    (sélectionnez sysdate-MINUTES de XXAFL_MINUTES)) where RUN_STATUS is not null; e

    The query above subtracted 5 minutes from SYSDATE and he shoots XXAFL_MINUTES. I am doing this because we could change the number of minutes in the future. I want to print the number of minutes in the case statement.

    If I execute this statement, it throws an error stating:

    ORA-00937: not a single group group function

    00937 00000 - 'not a single-group function.

    * Cause:

    * Action:

    Error on line: 1 column: 96

    How can I include "select sysdate - MINUTES of XXAFL_MINUTES" in the CASE that it calculates the number of minutes and it prints with the results.

    Thanks in advance!

    Hey guys,.

    I found the solution:

    SELECT

    RUN_STATUS | TO_CHAR ((sélectionnez sysdate-MINUTES de XXAFL_MINUTES), 'HH24:MI:SS')

    Of

    (select check BOX WHEN COUNT (ROW_WID) = 0

    THEN "NO JOB RAN.

    END RUN_STATUS

    of W_ETL_RUN_SDTL

    where

    START_TS > (select sysdate - XXAFL_MINUTES MINUTE))

    where

    RUN_STATUS is not null;

    The output:

    NO JOBS RAN AFTER 09:07:54

    Thanks to you all!

  • Pagination of the table in a query with table Panel

    Hello

    I need to implement paging in a table as long as the results of a query which makes the user, the table that the query is run has several records, 40000 or more.

    I searched but I can't find a way to apply what I, some links show me how to insert the pagination on the part of the table, but if I only do when I want to see a different page, let's say 500 or 1000, it takes too long to display the data of that specific page. I'm guessing it will retrieve all the data from the query and read it all so it can show what I want.

    Another way is to control the amount of data to be returned from the view object (VO), but I am unable to perform paging efect component table in my file jspx somehow.

    I think I should change my VO both my component so I can get the effect I want, but I don't know how. Properties that I need to change to achieve this.

    THK

    If I set the af: non paginated table mode the number of pages do not appear.

    Then maybe you can use the code from this blog to do it manually:

    http://www.Ateam-Oracle.com/adventures-in-WebCenter-skinning-aftable-with-custom-pagination/

    The only optimization that I think is missing is somehow when I select the page from the list of results, will retrieve only the data on this page.

    Yes and for this you must range Paging in VO (so the result of the query may be limited by the size of the range).

    But, as I mentioned in my first reply, range of paging is bug in 12.1.3 then maybe the same applies to 11.1.1.7

    Dario

  • Insert the result of a query select in another table

    Hello

    I have a strange problem when I try to insert all the results of a query select in another table, using the declaration of the order.

    With the declaration of COMMAND it works fine
    Work:
    ------------------------------
    INSERT INTO ADART01 (SELECT (codart)
    "STOCK". "" CODART_STO ".
    Of
    "DB". ' ' 'ACTIONS');
    ------------------------------

    But if I try to sort the result using the declaration of the ORDER, I have the following error:
    Error: ORA-00907 missing right parenthesis
    ------------------------------
    INSERT INTO ADART01 (SELECT (codart)
    "STOCK". "" CODART_STO ".
    Of
    "DB". "" "ACTIONS"
    ORDER BY
    "STOCK". ("' CODART_STO ASC ');
    ------------------------------

    Any idea?

    Thank you for your help,
    Angel.

    delete "()" to select

    create table test1 (a number, b varchar2(100));
    
    insert into test1
        (a, b)
        select level, 'level ' || level from dual connect by level < 101;
    
    insert into test1
        (a, b)
        select level, 'level ' || level from dual connect by level < 101 order by to_char(sysdate - level, 'D');
    
    select * from test1;
    
    drop table test1;
    
  • I need to return the result of a query on a stored procedure

    I need to return the result of a query to a stored procedure, I mean when I run a stored procedure it returns a result set in a select statement.
    Best regards...

    Hello.

    Do you really want a stored procedure for this?
    Why not just a script that contains the query?

    Assuming that you don't really want a stored procedure, you'll have to decide what to do with the results.
    An option is a slider.

    For example, you can write a procedure of this type to hold the query:

    CREATE OR REPLACE PROCEDURE USP_TEST
    (     out_cursor     OUT     SYS_REFCURSOR
    )
    IS
    BEGIN
         OPEN  out_cursor
         FOR     SELECT     *
              FROM     scott.emp;
    END  USP_TEST;
    /
    SHOW ERRORS
    

    You can move the cursor to another procedure for handling.

    You could test this in SQL * more by creating a variable blond:

    VARIABLE     usp_test_cursor     REFCURSOR;
    
    EXEC  usp_test (:usp_test_cursor);
    
    PRINT     :usp_test_cursor
    
  • defining the results of a query to a variable

    Hi all

    I'm having a problem affecting the results of a query to a variable. What I'm trying to do, is to do an AJAX call to a .cfc file and pass back the results of the function. The main problem is, I'm again moving a block of HTML (resulting from a cfquery in a cfoutput) stored in a variable. My code is something like...

    < name cffunction = "getText" access = "remote" returntype = 'Cancel' >

    < datasource = "" #request.dsn # cfquery "name ="queryTable">"
    SELECT kort, infoB

    Of infoTable

    < / cfquery >


    < cfset result = ' <!-this is the part I'm stuck, I want the table go here. -> ">"

    < table >
    < cfoutput query = "tablequery" >
    < b >
    < td > #infoA # < table > < td > #infoB # < table >
    < /tr >
    < / cfoutput >
    < /table >


    < cfwddx action = "cfml2js" input = "" # result # ' toplevelvariable 'o' = > "

    < / cffunction >

    It is a simplified version of what I want to do, but you get the idea...

    Is it still the right way to go about this?  Thank you

    That's what I get for trying the E-mail response feature!  Are you not happy, that I double checked my post.

    You could do a lot of string concatenation here to do stuff like"& Kort &""& infoB &""> time and time again."  But in reality the tags is so much easier to use.



      

        
      

    #infoA #.#infoB #.

  • Export the results of a query to a CSV file

    Hello

    My requirement is that I need to export the results of a query to a CSV file. Can someone please suggest a way to also include the names of columns in the CSV file?

    Thanks in advance.

    Annie

    Following code comes from asktom. I changed to include the column header. This will get your CSV file desired for a given query.

    create or replace function  dump_csv( p_query     in varchar2,
                                          p_separator in varchar2
                                                        default ',',
                                          p_dir       in varchar2 ,
                                          p_filename  in varchar2 )
    return number
    AUTHID CURRENT_USER
    is
        l_output        utl_file.file_type;
        l_theCursor     integer default dbms_sql.open_cursor;
        l_columnValue   varchar2(2000);
        l_status        integer;
        l_colCnt        number default 0;
        l_separator     varchar2(10) default '';
        l_cnt           number default 0;
    
         l_colDesc          dbms_sql.DESC_TAB;
    begin
        l_output := utl_file.fopen( p_dir, p_filename, 'w' );
    
        dbms_sql.parse(  l_theCursor,  p_query, dbms_sql.native );
    
        for i in 1 .. 255 loop
            begin
                dbms_sql.define_column( l_theCursor, i,
                                        l_columnValue, 2000 );
                l_colCnt := i;
            exception
                when others then
                    if ( sqlcode = -1007 ) then exit;
                    else
                        raise;
                    end if;
            end;
        end loop;
    
        dbms_sql.define_column( l_theCursor, 1, l_columnValue, 2000 );
    
        l_status := dbms_sql.execute(l_theCursor);
    
         dbms_sql.describe_columns(l_theCursor,l_colCnt, l_colDesc);
    
         l_separator := '';
    
         for lColCnt in 1..l_colCnt
         loop
                utl_file.put( l_output, l_separator ||  '"' || Upper(l_colDesc(lColCnt).col_name) || '"');
                   l_separator := p_separator;
         end loop;
    
         utl_file.new_line( l_output );
    
        loop
            exit when ( dbms_sql.fetch_rows(l_theCursor) <= 0 );
            l_separator := '';
            for i in 1 .. l_colCnt loop
                dbms_sql.column_value( l_theCursor, i,
                                       l_columnValue );
                utl_file.put( l_output, l_separator ||  '"' ||
                                        l_columnValue || '"');
                l_separator := p_separator;
            end loop;
            utl_file.new_line( l_output );
            l_cnt := l_cnt+1;
        end loop;
        dbms_sql.close_cursor(l_theCursor);
    
        utl_file.fclose( l_output );
        return l_cnt;
    end dump_csv;
    

    The original link is below.

    http://asktom.Oracle.com/pls/asktom/f?p=100:11:0:P11_QUESTION_ID:95212348059

    Thank you
    Knani.

  • Why the results research print in two color blue and black fonts?

    Original title: research

    Why the results research print in two color blue and black fonts?

    In general, the files and folders shown in the Explorer with the blue text are files and compressed files.  Black text indicates a normal file or a folder.

    writing in the new message: * e-mail address is removed from the privacy... *

    Why the results research print in two color blue and black fonts?

  • The ZTE mf622 dongle works with Windows XP, and are there any software updates for this?

    Original title: I gave myself a dongle from ZTE MF622.

    The zte mf622 dongle works with windows xp, and are there updates software for it, as in this moment, it comes up saying dial * 99 #, when I try and connect to the internet?

    Hey dude,

    You should check the hardware manufacturer's Web site not in the Windows forums.

    All the best, take care!

  • Why Lightroom CC will not download Nikon D610 photos, the same problem, I got with lightroom 3 and told me that I had to upgrade.

    Why Lightroom CC will not download Nikon D610 photos, the same problem, I got with lightroom 3 and said to upgrade?

    Make sure you sort the display you are looking at instead of file name recording time. It is in the context menu with a small sign of a to z just below images. Make sure also that you have no active filters.

  • I'm on PC Win 7 and bought, downloaded and installed Lightroom 6 the day it was released. When he downloaded and installed it seems to be the version CC, not the LR6. I entered my license number and it works on my computer, but it has Adobe CC

    I'm on PC Win 7 and bought, downloaded and installed Lightroom 6 the day it was released. When he downloaded and installed it seems to be the version CC, not the LR6. I entered my license number and it works on my computer, but there CC Adobe on my desk and I don't want that on my computer. How can I remove the Adobe CC from my computer and still have 6 installed Lightroom and working?

    If you are unable to remove Adobe Creative cloud Control Panel, see link below:

    https://forums.Adobe.com/thread/1846925

  • Hi, I want to add a link back to a button in the muse. Any ideas? thinking that I'll have to add the following &lt; a href = "javascript:history.back ()" &gt; &lt; /a &gt; and return code in a text editor by hand after I exported the site in html format.

    Hi, I want to add a link back to a button in the muse. Any ideas? thinking that I'll have to add the following < a href = "javascript:history.back ()" > < /a > and return code in a text editor by hand after I exported the site in html format.

    No need to code the hand something to do.

    Create your button or link just as you would for any button or link.

    Click on your button

    In the hyperlinks tool simply add javascript:history.back()

    Press enter

    Fact...

  • I bought a new computer and downloaded my lightroom 4 to it. When I installed the program it asked for my serial number and I impujted it. Then he asked my previous serial number of my purchase of lightroom 3. Since I upgraded to ligtroom 4 I

    I bought a new computer and downloaded my lightroom 4 to it. When I installed the program it asked for my serial number and I charged it. Then he asked my previous serial number of my purchase of lightroom 3. Since I upgraded to lightroom 4 I don't have the serial number for the version 3. How can I get the serial number of my version 3 so I can activate my program version 4

    If you have Lightroom 3 is still installed, you can get it from there.

    If you do not and you have your box/drive, it should be there.

    IF you do not have one of the people, and you have registered your software, you can log in to your Adobe account and get it there.

Maybe you are looking for

  • Updated my iPhone 5 ios 9.3.3 and problems with messaging

    Many of my applications were unusable, unless I upgraded (it has been a long time) but when I did all my old messages disappeared. And if that wasn't bad enough when I now get a message there is no notification. AND the content of incoming or outgoin

  • How to add the contact id feature to connect to my chase app?

    On my old iphone 6, I was when I downloaded the app, Chase bank, he asked if I wanted to open a session with my fingerprint. Recently, I replaced my phone but it does not give me that option and I tried adding parameters, but it does not. Help!

  • The G50-80 processor upgrade

    Hello I use LenovoG50-80 laptop with disk hard 500 GB and the model ram 2 GB with pentium processor.now I want to know if I can improve my processor i3 or i5.do my knees supports upgrading proocessor.

  • HP 15-f162dx: System to disable the code 70909953

    One of my friends bought this laptop a sale at auction of the police. When she got home she could not initialize it, so she bought a new battery. The laptop powers on but the message: power on password or administrator password enter appears without

  • What graphics card is compatible with Hewlett - Packard 147 has?

    Hello! I have a G62-a70SQ laptop with a 512 MB card graph. Recently, I saw that my graphics card is switchable, so I ask which graphics cards are compatible with my motherboard? I want to change because it is too slow for games. Thank you.