ORA-01476: divisor is equal to zero

Hello
To avoid the error oracle ORA-01476 (in sql, pl/sql not) I check the divider first - so it don't not to zero - and then make the division.
For example:

with sample_data(n1, n2) as
(select 6, 4 from dual union all
 select 8, 0 from dual)
 select case when n2<>0 then n1/n2 else 0 end
  from sample_data

Is there another way to avoid division by zero error?


I ask this question because, recently, I've been faced with a situation in which I got a part of the SQL like this:

...
case when dxy+dey+kty+kay-kts<>0 then round(100*(ypol/ sum(case when eidos<>'1' then dxy+dey+kty+kay-kts  end) over(partition by ylik_cd)) 
.....

But if I had a requirement that multiple "when" conditions should be included - as the divider - writing which precedes
solution would be complex and prone to errors (in which case I forgot a "when" clause). For example if I had:

.....
round(100*(ypol/ sum(case when eidos='1' then dxy+dey+kty+kay-kts when eidos<>'1' and dxy=0 then dxy+dey+kty+kay end) over(partition by ylik_cd))
.......


Note:
I'm using OraDb 11 g v.2

Thank you
SIM

Hello

Instead of

CASE

WHEN n2 <> 0

THEN n1 / n2

0 OTHERWISE

END

You can tell

N1 / NULLIF (n2, 0)

This returns NULL when n2 = 0, which is probably less misleading: return 0 in fact resemble the division could be made and n1 = 0.

If you really want to return 0 if n2 is ZERO, then

NVL (n1 / NULLIF (n2, 0))

0

)

Unlike the CASE expression, this returns 0 when the n1 or n2 is NULL.

If you really want the same results as the CASE expression gives you, then the CASE expression is the best way, i.e. repeat n2.  If n2 is a complicated expression, then you can calculate it in a subquery, so all you have to repeat in the expression BOX (in the Super-requete) is his name.

Tags: Database

Similar Questions

  • EXISTS, and ORA-01476: divisor is equal to zero

    Hello

    Who can explain, what is?

    SQL> select 1 from dual where exists (select 1 / 0 from dual);
             1
    ----------
             1
    
    SQL> select * from v$version;
    BANNER
    --------------------------------------------------------------------------------
    Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
    PL/SQL Release 11.2.0.3.0 - Production
    CORE    11.2.0.3.0    Production
    TNS for HPUX: Version 11.2.0.3.0 - Production
    NLSRTL Version 11.2.0.3.0 - Production
    
    SQL> 
    

    Ok... I know that the condition EXISTS, expression in the inner query don't cheking but if inner query returns error why external query returns a line? ))))

    ----

    Ramin Hashimzade

    The query is rewritten by the CBO:

    SQL > set autotrace traceonly explain

    SQL > select 1 in double where exists (select 1 / 0 double);

    Execution plan

    ----------------------------------------------------------

    Hash value of plan: 1685426719

    -----------------------------------------------------------------

    | ID | Operation | Name | Lines | Cost (% CPU). Time |

    -----------------------------------------------------------------

    |   0 | SELECT STATEMENT |      |     1.     4 (0) | 00:00:01 |

    |*  1 |  FILTER |      |       |            |          |

    |   2.   QUICK DOUBLE |      |     1.     2 (0) | 00:00:01 |

    |   3.   QUICK DOUBLE |      |     1.     2 (0) | 00:00:01 |

    -----------------------------------------------------------------

    Information of predicates (identified by the operation identity card):

    ---------------------------------------------------

    1 Filter (EXISTS (SELECT 'SYS' 0.)) (("'" 'DOUBLE'))

  • Rectification of divisor is equal to zero

    I'm a divisor is equal to zero error when I try to run this calculation.

    ROUND ((r.r_intercept-p.sutff_5000) / r.r_slope, 2) as NEW_STUFF5000

    Chloe_19 wrote:
    Yes.

    I guess that you just have to find 0

    Try
    cases where around are.r_slope = 0 else then 0 ((r.r_intercept-p.sutff_5000) / r.r_slope, 2) end as NEW_STUFF5000

  • 'Tools of sea for Windows' error: 'length' argument must be greater than or equal to zero. System. rope mi (System. sting. int32 int32).

    Original title: HOW to FIX THIS? 'length' argument must be greater than or equal to zero. System. Middle string (System. sting int32 int32.)

    Hi everyone in the Microsoft community,

    I am a novice at this stuff to pc, so excuse me if I ask a stupid question!

    I try to use Seatoolsforwindows, but during the research phase, this message comes on the screen...

    'length' argument must be greater than or equal to zero. System. Middle string (System. sting int32 int32.)

    I uninstalled and reinstalled Seatools, but I get the same results.
    I sought answers from Google and could not find a suggestion to install
    Microsoft Visual C ++ 2005 and Microsoft Visual C ++ 2008. I have 5 versions of this software installed.

    Details of the system
    Card mother Gigabyte X48T DQ6
    Intel Q6600 CPU
    8 GB of DDR3 RAM Corsair
    Card MSI GTX680 tiun graphic Frozr
    PSU Corsair 620W
    Operating system Windows 7 Pro
    Hard Seagate and Samsung drives

    I would appreciate if someone can help me on this one.

    Thank you

    Tim B

    Instead of using the version of win, try the bootable version

  • Select only records where the column values are not all equal to zero

    Hi everyone, it seems so easy, but it has left me speechless on the research in a way that is clean, easy to achieve. I know when someone replies, I'm going to kick me. So, let's assume this is what I have:
    with mytable as (
    select 'Type 1' as itemtype, 'JAN' as monthname, 0 as theval from dual union all
    select 'Type 1' as itemtype, 'FEB' as monthname, 1 as theval from dual union all
    select 'Type 1' as itemtype, 'MAR' as monthname, 5 as theval from dual union all
    select 'Type 1' as itemtype, 'APR' as monthname, 1 as theval from dual union all
    select 'Type 1' as itemtype, 'MAY' as monthname, 4 as theval from dual union all
    select 'Type 1' as itemtype, 'JUL' as monthname, 0 as theval from dual union all
    select 'Type 1' as itemtype, 'AUG' as monthname, 0 as theval from dual union all
    select 'Type 1' as itemtype, 'SEP' as monthname, 1 as theval from dual union all
    select 'Type 1' as itemtype, 'OCT' as monthname, 7 as theval from dual union all
    select 'Type 1' as itemtype, 'NOV' as monthname, 1 as theval from dual union all
    select 'Type 1' as itemtype, 'DEC' as monthname, 2 as theval from dual union all
    
    select 'Type 2' as itemtype, 'JAN' as monthname, 0 as theval from dual union all
    select 'Type 2' as itemtype, 'FEB' as monthname, 0 as theval from dual union all
    select 'Type 2' as itemtype, 'MAR' as monthname, 0 as theval from dual union all
    select 'Type 2' as itemtype, 'APR' as monthname, 0 as theval from dual union all
    select 'Type 2' as itemtype, 'MAY' as monthname, 0 as theval from dual union all
    select 'Type 2' as itemtype, 'OCT' as monthname, 0 as theval from dual union all
    select 'Type 2' as itemtype, 'NOV' as monthname, 0 as theval from dual union all
    select 'Type 2' as itemtype, 'DEC' as monthname, 0 as theval from dual
    )
    select
      itemtype,
      sum (case monthname when 'JAN' then theval else 0 end) as JAN,
      sum (case monthname when 'FEB' then theval else 0 end) as FEB,
      sum (case monthname when 'MAR' then theval else 0 end) as MAR,
      sum (case monthname when 'APR' then theval else 0 end) as APR,
      sum (case monthname when 'MAY' then theval else 0 end) as MAY,
      sum (case monthname when 'JUN' then theval else 0 end) as JUN,
      sum (case monthname when 'JUL' then theval else 0 end) as JUL,
      sum (case monthname when 'AUG' then theval else 0 end) as AUG,
      sum (case monthname when 'SEP' then theval else 0 end) as SEP,
      sum (case monthname when 'OCT' then theval else 0 end) as OCT,
      sum (case monthname when 'NOV' then theval else 0 end) as NOV,
      sum (case monthname when 'DEC' then theval else 0 end) as DEC
    from mytable
    group by itemtype
    order by itemtype
    I need an external application around it or something which will select only 'Type 1'... that is, if all months are each equal to zero, do not include the record in the result set.

    In summary to get a total of zero is not an option, because I could have-15 and + 15 in different columns, in which case, the recording should be displayed.

    Something as simple as... 'not the case (oct = 0 and 0 nov and dec = 0...) at the end is all it seems to me necessary. I thought to add a case for each column clause, but that seems not very effective. Ideas?

    Thanks in advance!
    Mark

    Edit... I know not what follows will work using the MINUS operator, but my actual query is really huge, and I don't want to have to write it twice...
    {code}
    Select
    ItemType,
    sum (case monthname when "JAN" then Val else 0 end) such as JAN,.
    sum (case when monthname 'FEB', then Val 0 otherwise end) by Feb.
    sum (case when monthname 'MAR', then Val 0 otherwise end) like MARS,
    sum (case monthname when "APR" then Val else 0 end) as APR.
    sum (case when monthname 'MAY', then Val else 0 end) either.
    sum (case when monthname "JUN", then Val 0 otherwise end) as JUN.
    sum (case monthname when "JUL" then Val else 0 end) as JUL,.
    sum (case monthname when "AUG" then Val else 0 end) as AUG.
    sum (case monthname when "MS" then Val else 0 end) as MS.
    sum (case monthname when "OCTS" then Val else 0 end) OCT.
    sum (case monthname when "NOV" then Val else 0 end) as NOV.
    sum (case monthname when 'DEC' then Val else 0 end) as DEC
    FROM MyTable
    Group of itemtype

    less

    Select
    ItemType,
    Jan, Feb, mar, Apr, may, June, July, August, Sept, oct, nov, dec
    de)
    Select
    ItemType,
    sum (case monthname when "JAN" then Val else 0 end) such as JAN,.
    sum (case when monthname 'FEB', then Val 0 otherwise end) by Feb.
    sum (case when monthname 'MAR', then Val 0 otherwise end) like MARS,
    sum (case monthname when "APR" then Val else 0 end) as APR.
    sum (case when monthname 'MAY', then Val else 0 end) either.
    sum (case when monthname "JUN", then Val 0 otherwise end) as JUN.
    sum (case monthname when "JUL" then Val else 0 end) as JUL,.
    sum (case monthname when "AUG" then Val else 0 end) as AUG.
    sum (case monthname when "MS" then Val else 0 end) as MS.
    sum (case monthname when "OCTS" then Val else 0 end) OCT.
    sum (case monthname when "NOV" then Val else 0 end) as NOV.
    sum (case monthname when 'DEC' then Val else 0 end) as DEC
    FROM MyTable
    Group of itemtype
    )
    where (oct = 0 & nov = 0 and dec = 0 and jan = 0 and 0 = Feb and mar = 0
    apr = 0 and may = 0 and = 0 jun and Jul = 0 and aug = 0 and Ms = 0
    )
    order of itemtype
    {code}

    Change again... OK, I guess that I am answering my own question here, but I think that by using a WITH to write the main request once clause and then selecting * twice using the MINUS operator between where the second query is where (oct = 0, etc.) is what I need. If anyone has better suggestions, please let me know! Here's the logic of nickname for what I come up with to date...

    {code}
    WITH mainquery as (select all)
    Select * from mainquery
    less
    Select * from mainquery where (oct = 0, nov = 0, etc...)
    {code}

    Thanks again!
    Mark

    Published by: user455268 on March 1, 2012 19:13

    Published by: user455268 on March 1, 2012 19:16

    Hello

    You can do it with a HAVING clause:

    select
      itemtype,
      sum (case monthname when 'JAN' then theval else 0 end) as JAN,
      sum (case monthname when 'FEB' then theval else 0 end) as FEB,
      sum (case monthname when 'MAR' then theval else 0 end) as MAR,
      sum (case monthname when 'APR' then theval else 0 end) as APR,
      sum (case monthname when 'MAY' then theval else 0 end) as MAY,
      sum (case monthname when 'JUN' then theval else 0 end) as JUN,
      sum (case monthname when 'JUL' then theval else 0 end) as JUL,
      sum (case monthname when 'AUG' then theval else 0 end) as AUG,
      sum (case monthname when 'SEP' then theval else 0 end) as SEP,
      sum (case monthname when 'OCT' then theval else 0 end) as OCT,
      sum (case monthname when 'NOV' then theval else 0 end) as NOV,
      sum (case monthname when 'DEC' then theval else 0 end) as DEC
    from mytable
    group by itemtype
    HAVING      MIN (theval)     != 0
    OR      MAX (theval)     != 0
    order by itemtype
    ;
    

    If the values are all 0, then the MIN and MAX will be 0.
    If the MIN or MAX is not 0, the values are all 0.

    This assumes that the combination (itemtype, monthname) is unique, because it is in your sample data.
    If this is not the case, start with a subquery that GROUPs BY itemtype, monthname, so that when you get to the main request, this combination will be unique.

  • Newbie here... try to make HasValue (field) if equal to zero null... any suggestions?

    HasValue (PointsQuestion1) + HasValue (PointsQuestion2) + HasValue (PointsQuestion3) + HasValue (PointsQuestion4)

    HasValue (PointsQuestion5) + HasValue (PointsQuestion6) + HasValue (PointsQuestion7)

    HasValue (PointsQuestion8) + HasValue (PointsQuestion9) + HasValue (PointsQuestion10) + HasValue (PointsQuestion11)

    I want this (area 1) to be nulled out when it is equal to zero. can someone please help?

    Also, when I divide 2 field by field 1, it calculates, but I always get an error message when you open the PDF file. Is it because the field 1 is equal to zero (and you cannot divide by zero)?

    picture.JPG

    I want to zero in the intermediate zone to not appear. Any help is appreciated. I can't understand.

    To get rid of the zero you just put an if statement into something like (in formcalc):

    If ($ == 0) then

    $ = ""

    endif

    You do the same thing for the calculation with the error:

    If (Field1 <> 0 and Field1.isNull == 0) then

    $ = Field2 / Field1

    endif

  • ORA-01436: CONNECT loop in the user data, but CONNECT_BY_ISCYCLE is equal to ZERO all the

    Hello

    When I run query below, it always throws the below error:
    SELECT connect_by_root code AS code_root,
        CODE,
        CODE_DESC,
        UP_CODE 
      FROM DI_CODE_LEVEL
      WHERE TYPE_CODE='SP'
        CONNECT BY PRIOR CODE=UP_CODE;
    
    ORA-01436: CONNECT BY loop in user data
    01436. 00000 -  "CONNECT BY loop in user data"
    But when I use NOCLYCLE and CONNECT_BY_ISCYCLE to see which line is in question.
    It shows nothing, which means CONNECT_BY_ISCYCLE = ZERO for all rows.
    select * from (
        SELECT connect_by_root code AS code_root,
            CODE,
            CODE_DESC,
            UP_CODE ,
            CONNECT_BY_ISCYCLE AS ISCYCLE
          FROM DI_CODE_LEVEL
          WHERE TYPE_CODE='SP'
            CONNECT BY NOCYCLE PRIOR CODE=UP_CODE
        ) 
    where ISCYCLE>0;
    Is there another reason that sql would lift ORA-01436?
    If there is a loop, then will the combination of NOCYCLE, CONNECT_BY_ISCYCLE will show?

    Thank you

    Hello

    Apparently, one or more of the "SP" lines are at the origin of the problem.
    The WHERE clause is applied after the CONNECT BY is finished, saying:

    select * from (
        SELECT connect_by_root code AS code_root,
            CODE,
            CODE_DESC,
            UP_CODE ,
            CONNECT_BY_ISCYCLE AS ISCYCLE
          FROM DI_CODE_LEVEL
          WHERE TYPE_CODE='SP'
            CONNECT BY NOCYCLE PRIOR CODE=UP_CODE
        )
    where ISCYCLE>0;
    

    is equivalent to

    select * from (
        SELECT connect_by_root code AS code_root,
            CODE,
            CODE_DESC,
            UP_CODE ,
            CONNECT_BY_ISCYCLE AS ISCYCLE
          FROM DI_CODE_LEVEL
            CONNECT BY NOCYCLE PRIOR CODE=UP_CODE
        )
    WHERE    TYPE_CODE = 'SP'
    AND     ISCYCLE   > 0;
    

    To see where the loop occurs, you must include the lines where type_code = "SP".

    When you debug "ORA-01436: CONNECT IN a loop in the user data ', view SYS_CONNECT_BY_PATH (uk,...), where the United Kingdom is a unique key. That will tell you much more than just the root information. You might want this:

    SELECT  connect_by_root code                AS code_root,
            CODE,
            CODE_DESC,
            UP_CODE
    ,     SYS_CONNECCT_BY_PATH (code, '/')     AS path          -- For debugging
    ,       CONNECT_BY_ISCYCLE                AS ISCYCLE     -- For debugging
    FROM      DI_CODE_LEVEL
    -- WHERE TYPE_CODE = 'SP'     -- Commented out for debugging
    where      ISCYCLE > 0          -- For debugging
    CONNECT BY NOCYCLE      PRIOR CODE = UP_CODE
    

    I hope that answers your question.
    If not, post a small example data (CREATE TABLE and only relevant columns, INSERT statements), and the results you want from this data.
    Explain how you get these results from these data.
    Always tell what version of Oracle you are using.

  • If higher, a value equal to zero

    Hello! I'm writing a basic if exposed at the end of my VI (the side far right, outside the while loop).

    I wish that all numbers greater than 2.59 X 10 ^ 6 to write on the worksheet as zero. Numbers less than this threshold, should be written as they are calculated.

    It seems to be a very basic concept but I'm running out of problems with having the wrong form of the data...? As well as to get the output of zero to write on the worksheet if it's actually superior to 2.59 X 10 ^ 6.

    Thanks for your help!

    Hello

    Confuse you the data types. Boolean and double... I have attached a simple VI which seems to solve your problem.

    / Patrik

  • Concurrent Manager actual is equal to zero, and target has some value

    Hi all
    In our test environment, a developer said today his request completed by idle, nomanager. I checked the concurrent Manager related to this request, is to show real is zero and target as 4. This means that manager special simultaneous is broken?...

    I checked the status of Manager simultaneous using adcmctl.sh. It shows the internal crib not active at the moment. Concurrent active users request completed successfully in manager.what standard, but does that mean?

    Please help me solve this problem.

    Thank you, Jay

    Published by: user9956349 on June 2, 2011 12:07 AM

    In our test environment, a developer said today his request completed by idle, nomanager. I checked the concurrent Manager related to this request, is to show real is zero and target as 4. This means that manager special simultaneous is broken?...

    Yes.

    I checked the status of Manager simultaneous using adcmctl.sh. It shows the internal crib not active at the moment. Concurrent active users request completed successfully in manager.what standard, but does that mean?

    Check this log file specific CM for more details about the error. Also, bounce the CM using check and adcmctl.sh script then (you may need to run the cmclean.sql script before raising services).

    Thank you
    Hussein

  • Division equals zero exception handling

    Hi all

    I'm new to this forum

    I created a trigger, but it does not work.

    DECLARE

    v_width INTEGER.

    v_height INTEGER: = 0;

    v_area INTEGER: = 6;

    BEGIN

    v_width: = v_area / v_height;

    DBMS_OUTPUT. Put_line ('v_width =' | v_width);

    EXCEPTION

    WHEN NO_DATA_FOUND THEN

    DBMS_OUTPUT. Put_line ("Division by zero");

    END;

    /



    However, I always get this error

    ERROR on line 1:

    ORA-01476: divisor is equal to zero

    ORA-06512: at line 7

    I can't debug. I need to deal with in the right way, all exceptions must be considered.

    The best solution is to never divide by zero in the first place, for example:

    DECLARE

    v_width INTEGER.

    v_height INTEGER: = 0; / * no doubt it is affected in any other way * /.

    v_area INTEGER: = 6;

    BEGIN

    IF v_height > 0 THEN

    v_width: = v_area / v_height;

    DBMS_OUTPUT. Put_line ('v_width =' | v_width);

    ON THE OTHER

    Dbms_output.put_line ('v_width is undefined');

    END IF;

    END;

    /

    Also, don't handle unexpected exceptions with nothing but debug output - protect against them, manipulate them in a meaningful way, or allow them to be propagated to the caller.

  • Calculation divisor zero SQL

    Hello

    I have some problems with the calculations, how to manipulate divisor of 0

    Table 1:

    ID sum

    1 100

    2 100

    of 3 100

    4 100

    Table2:

    percentage of ID

    1 0.7

    Table 3:

    amount of ID

    1 0

    Sum ((table1. Sum * table2.percentage) / table3. Sum)

    Error: ORA-01476 divisor is equal to zero

    Hello

    Try this,

    SQL > select * from t1;

    ID SUM YEAR
    --------- --------- ----
    1 100 2011
    2 100 2011
    3 100 2011
    4 100 2011

    5 500 2012

    SQL > select * from t2;

    ID PERC YEAR
    --------- --------- ----
    1.7 2011
    2.2 2012

    SQL > select * T3;

    ID SUM YEAR
    --------- --------- ----
    1 0 2011
    2 100 2011

    3 100 2012

    (Select t1.year,nvl(sum((t1.sum*t2.perc)/t3.sum), 0) calc

    Of

    T1 (select year, sum (sum) sum of group t1 annually).

    T2 (select year, sum (perc) perc of the t2 by year group),

    T3 (sum select year, sum (sum) of the t3 by year group)

    where t1.year = t2.year and t1.year = t3.year and t3.sum > 0 t1.year group

    /

    YEAR CALC

    ---- ---------

    2011 2.8

    1 2012

    Post edited by: Priyasagi

    Post edited by: Priyasagi inserted data from the year 2012 for purpose of illustration

  • ORA-06503: PL/SQL: function returned no value ORA-06512:

    Hi all

    SQL > set serveroutput on

    SQL > CREATE OR replace FUNCTION qty_value (p_item_id number)

    2 RETURN NUMBER

    3 EAST

    4 v_qty_arrival NUMBER;

    5 BEGIN

    6. SELECT THE CASE SENSITIVE OPTION

    7. WHAT (SUM (b.quantity) - SUM (b.quantity_received)) < = 0 THEN 0

    8 ELSE (SUM (b.quantity) - SUM (b.quantity_received))

    9 END Qty_Arrival

    10 INTO v_qty_arrival

    Po_lines_all 11 a,

    po_line_locations_all 12 b

    13 WHERE a.po_line_id = b.po_line_id

    14 AND a.item_id = p_item_id;

    15 EXCEPTION

    16 THEN THAN OTHERS THEN

    17 v_qty_arrival: = NULL;

    18 RETURN v_qty_arrival;

    19 END qty_value;

    20.

    The function is created.

    SQL >

    SQL > select xxc_qty_arrivale (214960) double

    2.

    Select xxc_qty_arrivale (214960) double

    *

    ERROR on line 1:

    ORA-06503: PL/SQL: function returned no value

    ORA-06512: at the 'APPS '. XXC_QTY_ARRIVALE', line 19

    Back AFTER using the exception block is fine as long as your code actually REACHED the exception block.

    When there are no errors, then your code will not enter the exception block, but you still NEED to return a value, since it is what functions a function wants to return a value, that's what the functions are made for.

    Spot the differences between the following 3 functions. Understand how they work.

    The first function has only a return in the exception block but runs correctly. Result: error, because the back is missing in the code block.

    The second function has a return in the exception block and one in the block of code and runs correctly. Result: no error, because the return is not missing in the code block.

    The third function has a return in the exception block and one in the block of code and is forced into an error. Result: no error, because the return of the exception handler is used (instead of retriggering of the error, which you would normally do).

    SQL > create or replace function myfunc

    2 return number

    3 as

    4 start

    5 dbms_output.put_line ('in the section of code');

    6 null;

    7 exception

    8 then than others

    9. can

    10 dbms_output.put_line (' in the exception handler ' |) SQLERRM);

    11      --

    12 return 0;

    13      --

    14 end;

    15.

    The function is created.

    SQL > select double myfunc;

    Select double myfunc

    *

    ERROR on line 1:

    ORA-06503: PL/SQL: function returned no value

    ORA-06512: at "GHPLUS. MYFUNC", line 14

    In the section of code

    SQL > create or replace function myfunc

    2 return number

    3 as

    4 start

    5 dbms_output.put_line ('in the section of code');

    6 null;

    7    --

    8 return 1;

    9    --

    10 exceptional

    11 so that others

    12. can

    13 dbms_output.put_line (' in the exception handler ' |) SQLERRM);

    14      --

    15 return 0;

    16      --

    end 17;

    18.

    The function is created.

    SQL > select double myfunc;

    MYFUNC

    ----------

    1

    1 selected line.

    In the section of code

    SQL > create or replace function myfunc

    2 return number

    3 as

    n number 4;

    5. start

    6 dbms_output.put_line ('in the section of code');

    7 n: = 1/0; -force an error (zero divisor) to join the exception handler

    8    --

    9 return 1;

    10-

    exception 11

    12 so that others

    13. can

    14 dbms_output.put_line (' in the exception handler ' |) SQLERRM);

    15      --

    16 return 0;

    17      --

    18 end;

    19.

    The function is created.

    SQL > select double myfunc;

    MYFUNC

    ----------

    0

    1 selected line.

    In the section of code

    In the handler for exception ORA-01476: divisor is equal to zero

    SQL >

  • Division by zero error.

    Hi all
    I get division by zero error in one of the reports that has been developed by one of our programmers. I think that this can be easily corrected in decoding or using a Case statement. I'm not sure how to use it below scenario.
    SUM( round((nvl("TRIP"."DRY_MAT",0))  
     / nvl("TRIP"."SPREAD_MILES",1) * 2000,2) ) over(partition by "TRIP"."TRIP_NO", 
    Published by: Lucy discover on December 15, 2010 12:41

    Lucy Discover wrote:

    I'm missing error keyword with cursor pointing to nearly 2,000 in the code below.

    Just a hunch, but the version of your database includes analytical functions?
    After the output of the query.

    select * from v$version;
    

    In all cases, the original query fails if spread_miles_total is set to 0, as follows-

    SQL>
    SQL> --
    SQL> WITH sim_trip AS
      2       (SELECT 10 AS operator_counter,
      3               11 AS trip_no,
      4               0 AS spread_miles_total,
      5               'D' AS dry_mat_code,
      6               13 AS dry_mat_used,
      7               'L' AS liquid_mat_code,
      8               14 AS liq_mat_used
      9          FROM DUAL),
     10       sim_operator AS
     11       (SELECT 10 AS operator_counter,
     12               'X' AS operator_name,
     13               DATE '2010-1-1' AS operator_date,
     14               'R' AS region,
     15               'RS' AS residency,
     16               'SO' AS sub_org,
     17               'SH' AS shift
     18          FROM DUAL)
     19  --
     20  SELECT sim_operator.operator_counter,
     21         sim_operator.operator_date,
     22         sim_operator.region,
     23         sim_operator.residency,
     24         sim_operator.sub_org,
     25         sim_operator.shift,
     26         sim_trip.trip_no,
     27         sim_operator.operator_name,
     28         sim_trip.spread_miles_total,
     29         sim_trip.dry_mat_code,
     30         sim_trip.dry_mat_used,
     31         SUM (ROUND ((NVL (sim_trip.dry_mat_used, 0)) / NVL (sim_trip.spread_miles_total, 1) * 2000, 2 ))
     32           OVER (PARTITION BY sim_trip.trip_no,
     33                              sim_trip.dry_mat_code,
     34                              sim_trip.liquid_mat_code,
     35                              sim_trip.dry_mat_used,
     36                              sim_trip.liq_mat_used,
     37                              sim_trip.spread_miles_total
     38             ) AS dry_appl_rate,
     39         sim_trip.liq_mat_used,
     40         sim_trip.liquid_mat_code,
     41         SUM (ROUND ((NVL (sim_trip.liq_mat_used, 0)) / NVL (sim_trip.spread_miles_total, 1), 2 ))
     42           OVER (PARTITION BY sim_trip.trip_no,
     43                              sim_trip.dry_mat_code,
     44                              sim_trip.liquid_mat_code,
     45                              sim_trip.dry_mat_used,
     46                              sim_trip.liq_mat_used,
     47                              sim_trip.spread_miles_total
     48             ) AS "LIQ_APPL_RATE"
     49    FROM sim_trip sim_trip,
     50         sim_operator sim_operator
     51   WHERE sim_operator.operator_counter = sim_trip.operator_counter
     52  /
           SUM (ROUND ((NVL (sim_trip.liq_mat_used, 0)) / NVL (sim_trip.spread_miles_total, 1), 2 ))
                                                        *
    ERROR at line 41:
    ORA-01476: divisor is equal to zero
    
    SQL>
    SQL>
    SQL>
    

    You try to do the following?

    (1) if spread_miles_total is set to NULL, use instead 1.
    (2) if spread_miles_total is not null and is equal to 0, then use 1.
    (3) if spread_miles_total is not null and is equal to 0, then retains its value.

    If so, then use the CASE expression as follows-

    SQL>
    SQL> --
    SQL> WITH sim_trip AS
      2       (SELECT 10 AS operator_counter,
      3               11 AS trip_no,
      4               0 AS spread_miles_total,
      5               'D' AS dry_mat_code,
      6               13 AS dry_mat_used,
      7               'L' AS liquid_mat_code,
      8               14 AS liq_mat_used
      9          FROM DUAL),
     10       sim_operator AS
     11       (SELECT 10 AS operator_counter,
     12               'X' AS operator_name,
     13               DATE '2010-1-1' AS operator_date,
     14               'R' AS region,
     15               'RS' AS residency,
     16               'SO' AS sub_org,
     17               'SH' AS shift
     18          FROM DUAL)
     19  --
     20  SELECT sim_operator.operator_counter,
     21         sim_operator.operator_date,
     22         sim_operator.region,
     23         sim_operator.residency,
     24         sim_operator.sub_org,
     25         sim_operator.shift,
     26         sim_trip.trip_no,
     27         sim_operator.operator_name,
     28         sim_trip.spread_miles_total,
     29         sim_trip.dry_mat_code,
     30         sim_trip.dry_mat_used,
     31         SUM (ROUND ((NVL (sim_trip.dry_mat_used, 0)) / case when sim_trip.spread_miles_total != 0
     32                                                             then sim_trip.spread_miles_total
     33                                                             else 1
     34                                                        end * 2000, 2 ))
     35           OVER (PARTITION BY sim_trip.trip_no,
     36                              sim_trip.dry_mat_code,
     37                              sim_trip.liquid_mat_code,
     38                              sim_trip.dry_mat_used,
     39                              sim_trip.liq_mat_used,
     40                              sim_trip.spread_miles_total
     41             ) AS dry_appl_rate,
     42         sim_trip.liq_mat_used,
     43         sim_trip.liquid_mat_code,
     44         SUM (ROUND ((NVL (sim_trip.liq_mat_used, 0)) / case when sim_trip.spread_miles_total != 0
     45                                                             then sim_trip.spread_miles_total
     46                                                             else 1
     47                                                        end, 2 ))
     48           OVER (PARTITION BY sim_trip.trip_no,
     49                              sim_trip.dry_mat_code,
     50                              sim_trip.liquid_mat_code,
     51                              sim_trip.dry_mat_used,
     52                              sim_trip.liq_mat_used,
     53                              sim_trip.spread_miles_total
     54             ) AS "LIQ_APPL_RATE"
     55    FROM sim_trip sim_trip,
     56         sim_operator sim_operator
     57   WHERE sim_operator.operator_counter = sim_trip.operator_counter
     58  /
    
    OPERATOR_COUNTER OPERATOR_ R RE SU SH    TRIP_NO O SPREAD_MILES_TOTAL D DRY_MAT_USED DRY_APPL_RATE LIQ_MAT_USED L LIQ_APPL_RATE
    ---------------- --------- - -- -- -- ---------- - ------------------ - ------------ ------------- ------------ - -------------
                  10 01-JAN-10 R RS SO SH         11 X                  0 D           13         26000           14 L            14
    
    1 row selected.
    
    SQL>
    SQL>
    SQL>
    

    HTH,
    isotope

  • Exception management - inside the procedure

    Hello

    I'm trying to insert records into our target within a cursor table.

    (For after the analysis of the values of the Source table and to make changes in the format of the value and insert into the target table)

    I need to capture the exception within the cursor and save these exception in an error table.

    I use the exception within the cursor for loop block.

    example code:

    C1 loop c_cursor1

    Start

    ... Insert the statement after the analysis of the values...

    exception

    while others

    then

    DBMS_OUTPUT. Put_line (' error code: ' |) SQLCODE);

    dbms_output.put_line (' error: ' |) SQLERRM);

    end;

    end loop;

    Examples of exception scenarios:

    1)

    Error report:

    ORA-01476: divisor is equal to zero

    ORA-06512: at "APX_DEVELOPMENT. PKG_CUSTOMER_FEDERATION', line 165

    ORA-06512: at line 3 level

    01476 00000 - "the divisor is equal to zero.

    Error code: - 1476

    Error message: ORA-01476: divisor is equal to zero

    2)

    Error report:

    ORA-12899: value too large for column 'APX_DEVELOPMENT '. "" "" RG_ORIGINATOR '. "" CREATED_BY' (real: 14, maximum: 10)

    ORA-06512: at "APX_DEVELOPMENT. PKG_CUSTOMER_FEDERATION', line 133

    ORA-06512: at line 3 level

    12899 00000 - "value too large for column %s (actual: %s, maximum: %s)).

    Error code: - 12899

    Error message: ORA-12899: value too large for column 'APX_DEVELOPMENT '. "" "" RG_ORIGINATOR '. "" CREATED_BY' (real: 14, maximum: 10)

    I use SQLCODE and SQLERRM to capture the codes and messages.

    But how to capture the package or the procedure name, and line number.

    for example. I need to capture something like below

    ORA-06512: at "APX_DEVELOPMENT. PKG_CUSTOMER_FEDERATION', line 165

    ORA-06512: at "APX_DEVELOPMENT. PKG_CUSTOMER_FEDERATION', line 133

    How to get to this

    Thanks in advance for your help.

    Please let me know for further details.

    Use dbms_utility.format_error_backtrace... Check below...

    http://docs.Oracle.com/database/121/ARPLS/d_util.htm#i1003874

    Thank you

    Ann

  • Try to handle the exception of another block, do not get it... Precious need help please...

    Hi, fields,

    I want to RAISE an exception through my first procedure and want to manage it in the second procedure. [I think it's concept of reproduction or multiplication exception].

    Not able to do, need your valuable advice.


    create or replace procedure test_excep1 (a number, b number)
    is
    c number;
    external_exception exception;
    Start
    c: = a / b;
    dbms_output.put_line ('Came out' | c);
    exception
    When zero_divide then
    raise external_exception;
    end;

    Start
    test_excep (2,0);
    end;

    When executing procedure above with divisor of zero, I get the error message below

    ORA-06510: PL/SQL: not supported by the user-defined exception
    ORA-06512: at "SONARDBO. TEST_EXCEP', line 10
    ORA-01476: divisor is equal to zero
    ORA-06512: at line 2


    Now if I try to catch this exception by another procedure, it does not help me. -This is my exact requirement.


    Create procedure test_excep2 (in numbers, number e d)
    is
    external_exception exception;
    Start
    test_excep (d, e);
    exception when external_exception then
    dbms_output.put_line ("' work of exception management");
    end;

    Start
    test_excep2 (2,0);
    end;

    When running over block, get the message below.

    ORA-06510: PL/SQL: not supported by the user-defined exception

    ORA-06512: at "SONARDBO. TEST_EXCEP', line 10

    ORA-01476: divisor is equal to zero

    ORA-06512: at "SONARDBO. TEST_EXCEP2', line 5

    ORA-06512: at line 2

    Thanks a ton in advance for help.

    Everything simply because you called an undefined exception 'external_exception' in a unit of code, and then reuse the name in another--does not mean that the variables of these exceptions are for the same exception. Common names mean nothing in this case. Using the same name for the variables or constants and exceptions across modules/units of code, does not mean that they are now the same.

Maybe you are looking for