Solved

SQL ORACLE: How to divide a static number

Posted on 2010-11-08
8
391 Views
Last Modified: 2012-06-27
Experts,

I have a query that divides into another query.  I am now wanting to have the query divide into a static number "6".

I am using Oracle 10g

Here is my SQL, need to replace the divisor to "6"
INSERT INTO NOC_KEY_INDICATOR_VALUES (FIELD_ID, FIELD_VALUE, REPORT_ID, REPORT_DATE, SHOW_DATE, KEY_INDICATOR)

        VALUES(

			'S32_W',

		to_char(((SELECT COUNT(*) 

        FROM ARADMIN.NOC_SITE_ALERTS_HISTORY 

          WHERE UDF_CONVERT_UNIX_DATETIME(CREATE_DATE, 'US/Eastern') >= (TRUNC(SYSDATE) - INTERVAL '7' DAY) AND UDF_CONVERT_UNIX_DATETIME(CREATE_DATE, 'US/Eastern') < (TRUNC(SYSDATE) - INTERVAL '0' DAY) 

            AND WS_MODIFIED_BY IS NULL 

            AND UDF_CONVERT_UNIX_DATETIME(CREATE_DATE, 'US/Eastern') <= UDF_CONVERT_UNIX_DATETIME(TICKET_CREATE_DATE, 'US/Eastern') + INTERVAL '15' MINUTE) 

        / (SELECT case when COUNT(*) = 0 then null else count(*) end FROM ARADMIN.NOC_SITE_ALERTS_HISTORY 

            WHERE UDF_CONVERT_UNIX_DATETIME(TICKET_CREATE_DATE, 'US/Eastern') >= (TRUNC(SYSDATE) - INTERVAL '7' DAY) 

            AND UDF_CONVERT_UNIX_DATETIME(TICKET_CREATE_DATE, 'US/Eastern') < (TRUNC(SYSDATE) - INTERVAL '0' DAY) AND WS_MODIFIED_BY IS NULL)),'9999999.99')

          ,'SO-WKLY-00',TRUNC(SYSDATE),TO_CHAR(SYSDATE-1, 'DAY')

          , '% Site Alerts Executed Within 15 Minutes of Ticket Creation');

Open in new window

0
Comment
Question by:Maliki Hassani
  • 2
  • 2
  • 2
  • +1
8 Comments
 
LVL 58

Expert Comment

by:cyberkiwi
ID: 34086824
This?

INSERT INTO NOC_KEY_INDICATOR_VALUES (FIELD_ID, FIELD_VALUE, REPORT_ID, REPORT_DATE, SHOW_DATE, KEY_INDICATOR)
        VALUES(
                  'S32_W',
            to_char(((SELECT COUNT(*)
        FROM ARADMIN.NOC_SITE_ALERTS_HISTORY
          WHERE UDF_CONVERT_UNIX_DATETIME(CREATE_DATE, 'US/Eastern') >= (TRUNC(SYSDATE) - INTERVAL '7' DAY) AND UDF_CONVERT_UNIX_DATETIME(CREATE_DATE, 'US/Eastern') < (TRUNC(SYSDATE) - INTERVAL '0' DAY)
            AND WS_MODIFIED_BY IS NULL
            AND UDF_CONVERT_UNIX_DATETIME(CREATE_DATE, 'US/Eastern') <= UDF_CONVERT_UNIX_DATETIME(TICKET_CREATE_DATE, 'US/Eastern') + INTERVAL '15' MINUTE)
        / 6),'9999999.99')
          ,'SO-WKLY-00',TRUNC(SYSDATE),TO_CHAR(SYSDATE-1, 'DAY')
          , '% Site Alerts Executed Within 15 Minutes of Ticket Creation');
0
 
LVL 51

Expert Comment

by:HainKurt
ID: 34087075
replace

(SELECT   CASE
                                  WHEN COUNT ( * ) = 0 THEN NULL
                                  ELSE COUNT ( * )
                               END
                        FROM   ARADMIN.NOC_SITE_ALERTS_HISTORY
                       WHERE       UDF_CONVERT_UNIX_DATETIME (
                                      TICKET_CREATE_DATE,
                                      'US/Eastern'
                                   ) >= (TRUNC (SYSDATE) - INTERVAL '7' DAY)
                               AND UDF_CONVERT_UNIX_DATETIME (
                                     TICKET_CREATE_DATE,
                                     'US/Eastern'
                                  ) < (TRUNC (SYSDATE) - INTERVAL '0' DAY)
                               AND WS_MODIFIED_BY IS NULL)

with 6
0
 
LVL 51

Expert Comment

by:HainKurt
ID: 34087092
final qry is:
INSERT INTO NOC_KEY_INDICATOR_VALUES (

                                         FIELD_ID,

                                         FIELD_VALUE,

                                         REPORT_ID,

                                         REPORT_DATE,

                                         SHOW_DATE,

                                         KEY_INDICATOR

           )

  VALUES   (

               'S32_W',

               TO_CHAR (

                  ( (SELECT   COUNT ( * )

                       FROM   ARADMIN.NOC_SITE_ALERTS_HISTORY

                      WHERE   UDF_CONVERT_UNIX_DATETIME (CREATE_DATE,

                                                         'US/Eastern') >=

                                 (TRUNC (SYSDATE) - INTERVAL '7' DAY)

                              AND UDF_CONVERT_UNIX_DATETIME (CREATE_DATE,

                                                             'US/Eastern') <

                                    (TRUNC (SYSDATE) - INTERVAL '0' DAY)

                              AND WS_MODIFIED_BY IS NULL

                              AND UDF_CONVERT_UNIX_DATETIME (CREATE_DATE,

                                                             'US/Eastern') <=

                                    UDF_CONVERT_UNIX_DATETIME (

                                       TICKET_CREATE_DATE,

                                       'US/Eastern'

                                    )

                                    + INTERVAL '15' MINUTE)

                   / 6),

                  '9999999.99'

               ),

               'SO-WKLY-00',

               TRUNC (SYSDATE),

               TO_CHAR (SYSDATE - 1, 'DAY'),

               '% Site Alerts Executed Within 15 Minutes of Ticket Creation'

           );

Open in new window

0
 

Author Comment

by:Maliki Hassani
ID: 34087563
Great!  Now what if I want it to come out exactly like .82%  Meaning 2 decimal places and with a percent sign?
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:Maliki Hassani
ID: 34087609
it is currently showing as 82
0
 
LVL 31

Expert Comment

by:awking00
ID: 34087793
Which query did you use for that result?
0
 
LVL 58

Accepted Solution

by:
cyberkiwi earned 250 total points
ID: 34087805
.82% means 0.0082 of the total, is that right?
82% = 0.82 ...
Is there some confusion?

The to_char and '9999999.99' should return it to 2 decimal places, so just add || '%', i.e.

INSERT INTO NOC_KEY_INDICATOR_VALUES (FIELD_ID, FIELD_VALUE, REPORT_ID, REPORT_DATE, SHOW_DATE, KEY_INDICATOR)

        VALUES(

                  'S32_W',

            to_char(((SELECT COUNT(*)

        FROM ARADMIN.NOC_SITE_ALERTS_HISTORY

          WHERE UDF_CONVERT_UNIX_DATETIME(CREATE_DATE, 'US/Eastern') >= (TRUNC(SYSDATE) - INTERVAL '7' DAY) AND UDF_CONVERT_UNIX_DATETIME(CREATE_DATE, 'US/Eastern') < (TRUNC(SYSDATE) - INTERVAL '0' DAY)

            AND WS_MODIFIED_BY IS NULL

            AND UDF_CONVERT_UNIX_DATETIME(CREATE_DATE, 'US/Eastern') <= UDF_CONVERT_UNIX_DATETIME(TICKET_CREATE_DATE, 'US/Eastern') + INTERVAL '15' MINUTE)

        / 6),'9999999.99') || '%'

          ,'SO-WKLY-00',TRUNC(SYSDATE),TO_CHAR(SYSDATE-1, 'DAY')

          , '% Site Alerts Executed Within 15 Minutes of Ticket Creation');

Open in new window

0
 
LVL 31

Assisted Solution

by:awking00
awking00 earned 250 total points
ID: 34087808
to_char(yourexpression/100)||'%'
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
From implementing a password expiration date, to datatype conversions and file export options, these are some useful settings I've found in Jasper Server.
This video shows how to recover a database from a user managed backup
This video shows how to configure and send email from and Oracle database using both UTL_SMTP and UTL_MAIL, as well as comparing UTL_SMTP to a manual SMTP conversation with a mail server.

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now