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

Tags: Database

Similar Questions

  • Mike 11 error: Floating Point of Division by zero error

    I use Windows 7 for running software MIKE11 . I used the same software to simulate the model in another Windows 7 PC operated and it worked correctly. But when I want to use the software in the PC, it returns me the error each time. How can I solve the problem?

    'Division by zero' errors are triggered by the application, not by Windows. You must ask the supplier for advice.

  • Handful of division by zero error in SQL

    Hello


    a few messages back, someone asked about how best to manage divide them by zero.

    Can I come back to this topic with, what is the best way to manage divide them by error in SQL without repeating the code...

    What I have in mind is often divided by error appears as the result of a long formula calculation - and trying to bury a long a long calculation formula in a case statement gives you an extremely long result, but is not ideal for the maintenance of the code.

    Encapsulating the manipulation in a function is not great for performance reasons.


    So is there a simple way to do the equivalent of (pseudo)


    Select IFerr (real / (RidiculouslyLongConvulutedFormulaHereWhichSometimesYieldsZeroValues), 0) of the double

    Where IFerr works as NVL - except that it gives 0 when the result is a wrong number or the result otherwise?



    Thank you

    Robert.

    Hello

    a few messages back, someone asked about how best to manage divide them by zero.

    I saw this thread, but it mentions the NULLIF function?

    You can apply it to each denominator in your formula, so it returns NULL in which case it is set to 0.

    For example,.

    with t as (
     select 1 numerator,
            0 denominator
     from dual
    )
    select numerator/nullif(denominator,0) as div
    from t;
    
  • Handful of division by zero error in the update statement

    My dear welcom

    How and I overcame this problem in my update statement
    for exwmple, it comes to the table
    CREATE TABLE TEST4
    (
    A1 NUMBER,
    A2 NUMBER OF,
    A3 NUMBER
    )

    Insert into TEST4 a1, a2, values (15.3);
    Insert into TEST4 a1, a2, values (9.3);
    Insert into TEST4 a1, a2, values (12.0);

    commit;


    now, I'm trying to update the column a3 in Division a1/12

    Start
    update set of test4
    A3 = a1/a2;
    exception
    WHEN ZERO_DIVIDE THEN
    update set of test4
    A3 = 0;
    end;
    After you validate THE VALUE of A3 = 0;

    Can any onle help me


    I use oracle 10g R2
    Thanks in advance
    SQL> select  *
      2    from  test4
      3  /
    
            A1         A2         A3
    ---------- ---------- ----------
            15          3
             9          3
            12          0
    
    SQL> update  test4
      2     set  a3 = case a2 when 0 then 0 else a1 / a2 end
      3  /
    
    3 rows updated.
    
    SQL> select  *
      2    from  test4
      3  /
    
            A1         A2         A3
    ---------- ---------- ----------
            15          3          5
             9          3          3
            12          0          0
    
    SQL> 
    

    SY.

  • 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.

  • Division by zero weird problem on HP 8200 Elite SFF

    Greetings,

    I posted my message here, it appears now that my problem is hardware specific.  My machine has the following specifications:

    HP Compaq 8200 Elite SFF
    Intel Core i5-2500 Duo @3.3 GHz processor
    8 GB memory

    Windows 7 x 64

    (I can provide more details if necessary)

    This has been me puzzled for more than a week now!

    We have an application where we lack in a division by zero. That request is deliberately built to raise exceptions in this case, with a call to the function _controlfp_s for edit masks on floating point exceptions.

    Now, when you run in a division by zero pretty much all of our machines, Visual Studio 2005 debugger breaks in the right place in our source files. However, on this machine, the location of the break is in every sense and seems to be unrelated to the real cause of the failure. So as a test, I built a simple win32 C program with just the following lines of code:

    int main (int argc, char * argv [])
    {
    float temp1, temp2, temp3;
    unsigned int control;

    _controlfp_s (& control, _EM_UNDERFLOW + _EM_INEXACT, _MCW_EM);

    Temp1 = 1.0;
    Temp2 = 0.0;
    Temp3 = temp1/temp2;

    return 0;
    }

    On all these 'good' machines, the code breaks when the temp3.  Among the other machines tested successfully, I had various hardware and operating systems, including Server 2008 R2, Windows XP x 32 and Windows 7 Pro x 64.  However, on this machine, the code stops at:

    C:\Program Files (x 86) \Microsoft Visual Studio 8\VC\crt\src\tidtable.c

    function:

    __set_flsgetvalue()

    In reviewing the records I have change the assembler code, everything seems fine until I hit the "ptsps" statement... then all records seem to be messed up (vs research as expected on a good machine). When comparing the stack on the good vs. bad, I also see entries of pile on the wrong machine, I don't see a good...

    Now... Here's what I did to solve problems:
    1. a disc image of the original disc HP on a hot spare and the original picture restored.
    2. only installed Visual Studio 2005 Pro - portion of C++.
    3 - tested above, code has always failed.

    4 - update all service packs Windows and tested above code.  Failed.

    5 - update all service packs, the Studio 2005 and tested above code. Failed.

    6 uninstalling all the bloatware and tested above code. Failed.

    7 - updating the BIOS and firmware and tested above code. Failed.

    8. install Visual Studio 2010 and tested above code. Failed.

    Then... I decided to take my spare disk image and install it on a similar, but a little older HP computer that we have, which has the following specifications:

    HP Compaq 8000 Elite SFF
    Intel Core Duo E8400 #3 GHz
    4 GB memory

    I went through the process of installation very well, even though she used the typewriter 8200 recovery partition.  On this machine, I simply installed the operating system and Visual Studio 2005 Pro - portion of C++.  No service packs not whatsoever (even if the Studio 2005 requires an update for 'vista') and the code worked as expected!

    So, that leaves me about almost everything but the material!  Also note that I tried to disable several processors and all optimization of the BIOS on the 8200, without success.

    I don't see anything else I can try... Please help!

    Wow!

    After the posting of this message to a friend... He found a document showing very similar symptoms on some of their CPUs from intel... I then found the exact document who applied to our specific processor (intel i5-2500) here:

    http://www.Intel.com/content/dam/www/public/us/en/documents/specification-updates/2nd-Gen-core-desktop-specification-update.PDF

    See Erratum BJ1

    This article describes pretty much exactly what I run into!  (Seriously), I never thought this would be a problem at THIS level!

  • CVI division by zero defects

    Hello

    I use NI LabWindows CVI 2012.

    I have a piece very simple code:

    Double a = 4/0;

    This piece of code, I would like to return NaN, or at least do something that isn't to stop the execution on the compilation.  "Is there a way to turn NaN handling functionality or add an exception for the compiler that said: if division by zero is found, returns zero" or something?

    Here, any help would be greatly appreciated

    Hello

    It's probably doing an entire division and then by converting the result in duplicate.  Division by zero with an integer will crash your application.  I would try this:

    Double a = 4.0/0,0;

    If adding le.0 in the end tells the compiler that it is a floating point type, where division by zero is not as bad.  Moreover,.

    Double;

    a = NotANumber ();

    Can also do what you want.  If you want to check for NaN you can do something like this:

    If (IsNotANumber (a))

    a = 0.0;

  • Division by zero floating-point

    Anyone has an idea why I would occasionally get the pop up window with the message "floating point division by zero" when you install a program on Windows 7?

    See if they give you ideas as to what could be the cause.

    Divide by zero
    http://www.Tek-Tips.com/viewthread.cfm?QID=1254517

    http://www.google.com/search?q=%22floating+point+division+by+zero%22&sourceid=ie7&rls=com.microsoft:-to the: IE-SearchBox & oe and ie ==.

  • Division by zero at t.

    Hi all

    I have a problem with QoQ when the division is zero. I usually use nullif in oracle queries, but it's not allowing in t/t.

    How can I solve this problem?

    Example code:

    < cfquery name = "qrySum", dbtype = "query" >

    Select "Item01" as DESCR

    < cfloop from = "2011" to index "2016" = "o" = >

    sum(FY_#y#) as FY_ #y #.

    sum(COST_#y#) as COST_ #y #.

    , sum(COST_#y#) / sum(FY_#y#) like PERC_ #y #.

    < / cfloop >

    of qryItems

    Group of DESCR

    < / cfquery >

    where for a year 2014 the sum (FY) = 0 and sum (COST) = 0

    Thank you

    Johnny

    Playing sometimes dumb is the way to go. How about this:

    Sum (FY_2011) as FY_2011, sum (FY_2012) as FY_2012, sum (FY_2013) as FY_2013, sum (FY_2014) as FY_2014, sum (FY_2015) as FY_2015, sum (FY_2016) as FY_2016

    of qryItems

    Select "Item01" as DESCR

    , #FYsum.FY_2011 # as FY_2011, #FYsum.FY_2012 # as FY_2012, #FYsum.FY_2013 # as FY_2013, #FYsum.FY_2014 # as FY_2014, #FYsum.FY_2015 # as FY_2015, #FYsum.FY_2016 # as FY_2016

    sum (COST_2011) as COST_2011, sum (COST_2012) as COST_2012, sum (COST_2013) as COST_2013, sum (COST_2014) as COST_2014, sum (COST_2015) as COST_2015, sum (COST_2016) as COST_2016

    , sum (COST_2011) / #FYsum.FY_2011 # as PERC_2011, sum (COST_2012) / #FYsum.FY_2012 # as PERC_2012, sum (COST_2013) / #FYsum.FY_2013 # as PERC_2013, sum (COST_2014) / #FYsum.FY_2014 # as PERC_2014, sum (COST_2015) / #FYsum.FY_2015 # as PERC_2015, sum (COST_2016) / #FYsum.FY_2016 # as PERC_2016

    of qryItems

    Group of DESCR

  • Zero error of the client certificate provided is not rooted in the devices certificate store after upgrade to the Horizon view 6

    We have just updated our infrastructure VMware View Horizon of 5.3 to 6.0.1 and all zero clients are provided certificate is not rooted in the devices certificate store.  The certificate on the brokers of the connection has not changed.  Customer relationship connections Horizon view a connection, as well as when we connect to the connection to the server via a web browser.  We had no cert errors before the upgrade.

    You need to add the following as PEM files to fix the problem on the zero client.

    The intermediate certificate - DigiCertCA.crt

    The root - TrustedRoot.crt certificate

  • Zero error of iteration - the treatment of dynamic sql statements in dbms_xmlgen

    Hello

    I have a procedure that creates a dynamic sql v_sql

    cursor v_curr is
    Select *.
    of btctl_msg_log;

    BEGIN
    Select count (*) in the v_cnt of btctl_msg_log;

    IF v_cnt > 0 THEN
    C1 in v_curr
    LOOP
    v_sql: = "' | ' SELECT * from '. C1.msg_rcrd_src_tbl_nm | |' where rowid = ' | " ' ||'' ' || C1.msg_rcrd_src_tbl_id | " ' ||'' ' ||'' ' ;
    Select DBMS_XMLGEN.getXMLtype (v_sql) in the double v_xml;

    gives me an error

    ORA-19202: an error has occurred in the processing of XML
    ORA-24333: zero number of iterations
    ORA-06512: at "SYS." DBMS_XMLGEN", line 288
    ORA-06512: at line 1

    I don't know why is this error happening.
    Any help much appreciated.

    881575 wrote:
    Hello

    I have a procedure that creates a dynamic sql v_sql

    cursor v_curr is
    Select *.
    of btctl_msg_log;

    BEGIN
    Select count (*) in the v_cnt of btctl_msg_log;

    IF v_cnt > 0 THEN
    C1 in v_curr
    LOOP
    v_sql: = "' | ' SELECT * from '. C1.msg_rcrd_src_tbl_nm | |' where rowid = ' | " ' ||'' ' || C1.msg_rcrd_src_tbl_id | " ' ||'' ' ||'' ' ;
    Select DBMS_XMLGEN.getXMLtype (v_sql) in the double v_xml;

    gives me an error

    ORA-19202: an error has occurred in the processing of XML
    ORA-24333: zero number of iterations
    ORA-06512: at "SYS." DBMS_XMLGEN", line 288
    ORA-06512: at line 1

    I don't know why is this error happening.
    Any help much appreciated.

    Standard when boards (ab) use of EXECUTE IMMEDIATE is to compose the SQL statement in a single VARCHAR2 variable
    Then print the variable before passing to EXECUTE IMMEDIATE.
    COPY the statement & PASTE in sqlplus to validate its correctness.

  • Calculator simple division by zero help

    Hello, I'm doing a simple calculator with four basic operations. I want an LED light up when I'm dividing by zero. However, if I divide by zero, the LED lights up, and then when I switch to another operation, the LED stays on until I turn to 'divide' and the denominator is not zero. Can someone help me with this problem? Thank you. My VI file is attached.

    RavensFan wrote:

    # No, if wire you a False constant out to other cases.

    ... or just thread out from the case of the divide and set the tunnel exit to "use default if thread continues. It turns on only if the divide operation runs AND the divisor is zero. If can be skewed (off) in all other conditions.

  • ZERO ERROR - Please HELP

    Hi all

    When I open the LR5, I get an error that says, ?: 0: attempt to index a nil value and can not open my library; How can I fix this?

    Thank you in advance...

    Try to rename the folder presets.

    Go to preferences > Presets tab and click on "show Lightroom Presets folder.
    Rename the folder "Lightroom" presets "Lightroom-old."
    Quit and then restart LR.

    You will need to find your catalog manually under:

    File > open recent

  • Divide by ZERO error.

    Hello
    I need a little help. I get divsor is equal to 0 error on the two 6i devloper and oracle pl/sql report writer
    In the report designer, I have a column of formulas with the following:

    Return ((:-: / b): a) * 100;

    What is a simple way around the divide by 0 error?
    Thank you.

    Make sure that: a is always greater than 0, otherwise do not run the formula.

    if :a > 0
    then
       return ((:a - :b)/:a) *100;
    else
       return 0; -- or whatever you want
    end if;
    
  • Avoid a divide by error to zero using offset

    Version: 11g

    Hello

    Yesterday was a great help by Frank et Al concerning a request for the increase of the % of the previous year

    SQL to get % increase in the amount of the previous year

    One problem that I'm faced with this is that if the specific 'exp_type' does not exist in the table for a given year, I get the "division by zero error.

    It works fine when there are values for all years. Is there a way to get around this? Maybe the value null or 0 but not raise an error. I tried to use NVL but did not work

    {code}


    WITH total AS
    (

    TO_CHAR (date_exp, 'YYYY') SELECT an
    SUM(CASE WHEN exp_type =:P1_YOY_PERCENT_LIST THEN exp_amt ELSE 0 END) AS Type
    Of exp_main
    TO_CHAR GROUP (date_exp, 'YYYY')

    )
    SELECT year 'year '.
    Type
    TO_CHAR ((Type/Type of NVL (LAG (Type) (any ORDER PER year)), * 100)-100, '999990') | ' %' "% increase.
    OF THE total amount
    ORDER BY year DESC

    {code}


    FYI - the: P1_YOY_PERCENT_LIST is just a value in the Apex that I use to allow users to select any 'exp_type' for who they want to see the increase in % of the previous year.

    Thank you
    Ryan

    Published by: ryansun on November 29, 2012 12:37 AM

    Published by: ryansun on November 29, 2012 01:02

    Hi, Ryan.

    ryansun wrote:
    Version: 11g

    Hello

    Yesterday was a great help by Frank et Al concerning a request for the increase of the % of the previous year

    SQL to get % increase in the amount of the previous year

    One problem that I'm faced with this is that if the specific 'exp_type' does not exist in the table for a given year, I get the "division by zero error.

    It works fine when there are values for all years. Is there a way to get around this? Maybe the value null or 0 but not raise an error. I tried to use NVL but did not work

    {code}

    WITH total AS
    (

    TO_CHAR (date_exp, 'YYYY') SELECT an
    SUM(CASE WHEN exp_type =:P1_YOY_PERCENT_LIST THEN exp_amt ELSE 0 END) AS Type
    {code}

    You are actually providing the 0 value in the ELSE clause. If you leave just off of the ELSE clause, then SUM returns NULL when there is no line with the given exp_type.
    {code}
    Sum(case when exp_type =:P1_YOY_PERCENT_LIST Then exp_amt end) AS Type
    {code}
    There is always a problem if exp_amt can really be 0 or exp_amt can be a combination of positive and negative numbers which could total 0.

    {code}
    Of exp_main
    TO_CHAR GROUP (date_exp, 'YYYY')

    )
    SELECT year 'year '.
    Type
    TO_CHAR ((Type/Type of NVL (LAG (Type) (any ORDER PER year)), * 100)-100, '999990') | ' %' "% increase.
    OF THE total amount
    ORDER BY year DESC

    {code}

    FYI - the: P1_YOY_PERCENT_LIST is just a value in the Apex that I use to allow users to select any 'exp_type' for who they want to see the increase in % of the previous year.

    Thank you
    Ryan

    The standard method to avoid division by 0 in x errors / when there may be 0 is
    {code}
    x / NULLIF (y, 0)
    {code}
    This returns null if y = 0. In your case, which would result in:
    {code}
    To_char ((Type
    / NULLIF (NVL (LAG (Type) (ORDER BY year)
    Type
    )
    0
    ) * 100
    ) - 100
    '999990'
    ) || '%' "% increase.
    {code}
    which guarantees that you will get the NULL value instead of the division by 0 error, but that means that the whole expression will be "%" when the number is NULL. If you really want the % sign in the set of results and not just the head, then use CASE, as Boneist suggested and cumulative Sven.

Maybe you are looking for