Solved

SQL ORACLE: Divisor is equal to zero

Posted on 2010-11-22
4
1,411 Views
Last Modified: 2012-05-10
Experts,

I am getting an error message when I try to run my query.  Here is the error message;

> Script lines: 1-34 -------------------------
 ORA-12801: error signaled in parallel query server P002, instance storm:forge2 (2)
ORA-01476: divisor is equal to zero
 Script line 1, statement line 1, column 0 


I need to find a way to make it show up as 0 or null for the
THEN (FIELD_VALUE/ENDING_PLAN) END)

This is the part that is causing the issue.  See code

Thanks

Using Oracle 10 g
SELECT
FIELD_ID, KEY_INDICATOR,
max(CASE WHEN SHOW_DATE = 'MONDAY   'AND REPORT_ID = 'SO-DYLY-01'  THEN ENDING_PLAN END) MONDAY_E_P_SO_D_1,
max(CASE WHEN SHOW_DATE = 'MONDAY   'AND REPORT_ID = 'SO-DYLY-01'  THEN FIELD_VALUE END) MONDAY_SO_D_1,
max(CASE WHEN SHOW_DATE = 'MONDAY   'AND REPORT_ID = 'SO-DYLY-01'  THEN (FIELD_VALUE/ENDING_PLAN) END) MONDAY_VAR_SO_D_1,

max(CASE WHEN SHOW_DATE = 'TUESDAY  'AND REPORT_ID = 'SO-DYLY-01'  THEN ENDING_PLAN END) TUESDAY_E_P_SO_D_1,
max(CASE WHEN SHOW_DATE = 'TUESDAY  'AND REPORT_ID = 'SO-DYLY-01'  THEN FIELD_VALUE END) TUESDAY_SO_D_1,
max(CASE WHEN SHOW_DATE = 'TUESDAY  'AND REPORT_ID = 'SO-DYLY-01'  THEN (FIELD_VALUE/ENDING_PLAN) END) TUESDAY_VAR_SO_D_1,

max(CASE WHEN SHOW_DATE = 'WEDNESDAY'AND REPORT_ID = 'SO-DYLY-01'  THEN ENDING_PLAN END) WEDNESDAY_E_P_SO_D_1,
max(CASE WHEN SHOW_DATE = 'WEDNESDAY'AND REPORT_ID = 'SO-DYLY-01'  THEN FIELD_VALUE END) WEDNESDAY_SO_D_1,
max(CASE WHEN SHOW_DATE = 'WEDNESDAY'AND REPORT_ID = 'SO-DYLY-01'  THEN (FIELD_VALUE/ENDING_PLAN) END) WEDNESDAY_VAR_SO_D_1,

max(CASE WHEN SHOW_DATE = 'THURSDAY 'AND REPORT_ID = 'SO-DYLY-01'  THEN ENDING_PLAN END) THURSDAY_E_P_SO_D_1,
max(CASE WHEN SHOW_DATE = 'THURSDAY 'AND REPORT_ID = 'SO-DYLY-01'  THEN FIELD_VALUE END) THURSDAY_SO_D_1,
max(CASE WHEN SHOW_DATE = 'THURSDAY 'AND REPORT_ID = 'SO-DYLY-01'  THEN (FIELD_VALUE/ENDING_PLAN) END) THURSDAY_VAR_SO_D_1,

max(CASE WHEN SHOW_DATE = 'FRIDAY   'AND REPORT_ID = 'SO-DYLY-01'  THEN ENDING_PLAN END) FRIDAY_E_P_SO_D_1,
max(CASE WHEN SHOW_DATE = 'FRIDAY   'AND REPORT_ID = 'SO-DYLY-01'  THEN FIELD_VALUE END) FRIDAY_SO_D_1,
max(CASE WHEN SHOW_DATE = 'FRIDAY   'AND REPORT_ID = 'SO-DYLY-01'  THEN (FIELD_VALUE/ENDING_PLAN) END) FRIDAY_VAR_SO_D_1,

max(CASE WHEN SHOW_DATE = 'SATURDAY 'AND REPORT_ID = 'SO-DYLY-01'  THEN ENDING_PLAN END) SATURDAY_E_P_SO_D_1,
max(CASE WHEN SHOW_DATE = 'SATURDAY 'AND REPORT_ID = 'SO-DYLY-01'  THEN FIELD_VALUE END) SATURDAY_SO_D_1,
max(CASE WHEN SHOW_DATE = 'SATURDAY 'AND REPORT_ID = 'SO-DYLY-01'  THEN (FIELD_VALUE/ENDING_PLAN) END) SATURDAY_VAR_SO_D_1,

max(CASE WHEN SHOW_DATE = 'SUNDAY   'AND REPORT_ID = 'SO-DYLY-01'  THEN ENDING_PLAN END) SUNDAY_E_P_SO_D_1,
max(CASE WHEN SHOW_DATE = 'SUNDAY   'AND REPORT_ID = 'SO-DYLY-01'  THEN FIELD_VALUE END) SUNDAY_SO_D_1,
max(CASE WHEN SHOW_DATE = 'SUNDAY   'AND REPORT_ID = 'SO-DYLY-01'  THEN (FIELD_VALUE/ENDING_PLAN) END) SUNDAY_VAR_SO_D_1

FROM NOC_KEY_INDICATOR_VALUES
WHERE REPORT_ID = 'SO-DYLY-01' AND SHOW_DATE IN ( 'SUNDAY   ','SATURDAY ','FRIDAY   ','THURSDAY ','WEDNESDAY','TUESDAY  ','MONDAY   ')
GROUP BY FIELD_ID, KEY_INDICATOR
ORDER BY CAST(REGEXP_REPLACE(Field_ID, '[^[:digit:]]', '') AS INTEGER)

Open in new window

0
Comment
Question by:Maliki Hassani
  • 3
4 Comments
 
LVL 73

Accepted Solution

by:
sdstuber earned 500 total points
ID: 34189629
THEN decode(ending_plan, 0, 0, FIELD_VALUE/ENDING_PLAN)
0
 
LVL 73

Expert Comment

by:sdstuber
ID: 34189642
you could use case as well

case when ending_plan = 0 then 0 else field_value/ending_plan end
0
 
LVL 73

Expert Comment

by:sdstuber
ID: 34189646
or, if you want null instead of 0


field_value / nullif(ending_plan,0)
0
 

Author Closing Comment

by:Maliki Hassani
ID: 34189667
Thnaks,  I remeber you helping me out with a similar issue but it was a little different syntax.  Thanks!
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I'm trying, I really am. But I've seen so many wrong approaches involving date(time) boundaries I despair about my inability to explain it. I've seen quite a few recently that define a non-leap year as 364 days, or 366 days and the list goes on. …
This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
This video explains at a high level about the four available data types in Oracle and how dates can be manipulated by the user to get data into and out of the database.
This video shows syntax for various backup options while discussing how the different basic backup types work.  It explains how to take full backups, incremental level 0 backups, incremental level 1 backups in both differential and cumulative mode a…

810 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