SQL - how the sum on specific lines

Hello

Forever, the line, I want to show MySQL for previous lines, only when the previous values are equal = 1,.

and only for successive lines.

for example, the result expected on the column 'result '.

Result of ID value

100 1-

130 1 2-> (current 1 + pre 1)

3 500-

1 600-

2-1-700-> (current 1 + pre 1)

1000-1-3-> (current 1 + precedent1 + 1 previous pre)

4 1 1200

How can do us it easily?

I thank everyone in advance.

Here's a way...

with t (id, value) :)

Select 100.1 in union double all the

Select 130.1 Union double all the

Select 500,3 Union double all the

Select 600,1 Union double all the

Select 700,1 Union double all the

Select 1000,1 Union double all the

Select double 1200,1

)

Select

ID

value

case

When start_of_group = 0 and = 1 value

then MySQL over (partition by group_num by id order)

Another null

end result

de)

Select sum (start_of_group) (any order by id) as group_num

start_of_group

id

value of)

Select

case

When lag(value,1,0) (any order by id)! = 1 then 1

0 otherwise

end as start_of_group

id

value

t

)

)

order by id

;

Kind regards

Bob

Tags: Database

Similar Questions

  • How the SUM cells including the text and the number?

    Hello world

    Someone can tell me how the SUM cells include the text and the number?

    1 Bob 20

    2 30 Jane

    3 50 Jame

    Total 100

    Thank you

    Hi Jordan,.

    If the numbers are not always two digits, FIND the position of the space between the number and name:

    Formula in B2 (fill down)

    = FIND("",A2)

    Then use the LEFT function to get the number in the column C:

    Formula in C2 (fill down)

    = LEFT (A2, B2)

    This will give a text string (Tip: left-aligned).

    Convert to a numeric value in the D column with the VALUE function:

    Formula in D2 (fill down)

    VALUE = (C2)

    (Tip: propped right)

    Table 1 has a header row and footer of the line, and the SUM is easy. Formula to the D8 footer line:

    = SUM (D)

    Kind regards

    Ian.

    Edit: You can hide columns B and C

    Ian.

  • How to determine a specific line in the table clicked on

    Hello-

    I need to determine the specific line of a table control that is right-mouse-clicking.  I think that this is possible by using the context Menu Activation? event for the control of the table and get the vertical coordinate in the Coords filter options.

    He is performing experiments to determine the vertical amplitude of each row in the table, or maybe in determining the width of a line and using a linear relationship to determine the possible range of the following lines.  Do you feel it is the best strategy or is it maybe an another easier way to get this information?

    Thank you

    Don

    You can use the CtlRef with the Point in the array to the method line for the information.

    Ben64

    I was too slow to respond...

  • How graphic how the sum of several metrics of in a dashboard.

    I'm looking to find out how the graph of the sum of multiples of the metric, as CPU ready, or latency of disk in one graph on a dashboard / report.

    An example would be showing collective management s VM in balloning of CPU and memory of the pool on line on a chart.

    Thank you!

    If you want the chart to reflect everything that you can do the stacking graphics option which will be sleeping all values.

  • SQL for the sum of a column while avoiding the repetition of values

    Dear all
    I have this table called Loans_installments that contains the client's loan payments.

    sample data:
    the client_id loan_no inst_mat_date inst_seq original_inst_amt int_amt currency management
    110 2 222 100 1/1/2013 1 0 50
    110 2 222 100 1/2/2013 2 0 52
    110 2 222 100 1/3/2013 3 0 54
    110 2 222 100 1/4/2013 4 500 90
    110 2 222 100 1/5/2013 5 0 50
    110 2 222 100 1/6/2013 6 0 51
    110 2 222 100 7/1/2013 7 0 50
    110 2 222 100 1/8/2013 8 600 105
    110 2 222 100 1/9/2013 9 0 50
    110 2 222 10 100 1/10 / 2013 0 54
    110 2 222 100 1/11 / 2013 11 0 50
    110 2 222 100 1/12 / 2013 12 700 120



    now what I want to do the sum of int_amt field based on original_inst_amt value (0 or a value) and put the result on the int_amt who has an orig_inst_amt value <>0.

    the result should be like this:


    the client_id loan_no inst_mat_date inst_seq original_inst_amt int_amt currency management
    110 2 222 100 1/1/2013 1 0 0
    110 2 222 100 1/2/2013 2 0 0
    110 2 222 100 1/3/2013 3 0 0
    110 2 222 100 1/4/2013 4 500 246
    110 2 222 100 1/5/2013 5 0 0
    110 2 222 100 1/6/2013 6 0 0
    110 2 222 100 7/1/2013 7 0 0
    110 2 222 100 1/8/2013 8 600 256
    110 2 222 100 1/9/2013 9 0 0
    110 2 222 100 1/10 / 2013 10 0 0
    110 2 222 100 1/11 / 2013-11 0 0
    110 2 222 100 1/12 / 2013 12 700 274


    any help please.

    With the help of the clause type

    SQL> with t
      2  as
      3  (
      4  select 110 branch, 2 currency, 222 client_id, 100 loan_no, to_date('1/1/2013','mm/dd/yyyy') inst_mat_date, 1  inst_seq, 0   original_inst_amt, 50 int_amt from dual
      5  union all
      6  select 110 branch, 2 currency, 222 client_id, 100 loan_no, to_date('1/2/2013','mm/dd/yyyy') inst_mat_date, 2  inst_seq, 0   original_inst_amt, 52 int_amt from dual
      7  union all
      8  select 110 branch, 2 currency, 222 client_id, 100 loan_no, to_date('1/3/2013','mm/dd/yyyy') inst_mat_date, 3  inst_seq, 0   original_inst_amt, 54 int_amt from dual
      9  union all
     10  select 110 branch, 2 currency, 222 client_id, 100 loan_no, to_date('1/4/2013','mm/dd/yyyy') inst_mat_date, 4  inst_seq, 500 original_inst_amt, 90 int_amt from dual
     11  union all
     12  select 110 branch, 2 currency, 222 client_id, 100 loan_no, to_date('1/5/2013','mm/dd/yyyy') inst_mat_date, 5  inst_seq, 0   original_inst_amt, 50 int_amt from dual
     13  union all
     14  select 110 branch, 2 currency, 222 client_id, 100 loan_no, to_date('1/6/2013','mm/dd/yyyy') inst_mat_date, 6  inst_seq, 0   original_inst_amt, 51 int_amt from dual
     15  union all
     16  select 110 branch, 2 currency, 222 client_id, 100 loan_no, to_date('1/7/2013','mm/dd/yyyy') inst_mat_date, 7  inst_seq, 0   original_inst_amt, 50 int_amt from dual
     17  union all
     18  select 110 branch, 2 currency, 222 client_id, 100 loan_no, to_date('1/8/2013','mm/dd/yyyy') inst_mat_date, 8  inst_seq, 600 original_inst_amt, 105 int_amt from dual
     19  union all
     20  select 110 branch, 2 currency, 222 client_id, 100 loan_no, to_date('1/9/2013','mm/dd/yyyy') inst_mat_date, 9  inst_seq, 0   original_inst_amt, 50 int_amt from dual
     21  union all
     22  select 110 branch, 2 currency, 222 client_id, 100 loan_no, to_date('1/10/201','mm/dd/yyyy') inst_mat_date, 10 inst_seq, 0   original_inst_amt, 54 int_amt from dual
     23  union all
     24  select 110 branch, 2 currency, 222 client_id, 100 loan_no, to_date('1/11/201','mm/dd/yyyy') inst_mat_date, 11 inst_seq, 0   original_inst_amt, 50 int_amt from dual
     25  union all
     26  select 110 branch, 2 currency, 222 client_id, 100 loan_no, to_date('1/12/201','mm/dd/yyyy') inst_mat_date, 12 inst_seq, 700 original_inst_amt, 120 int_amt from dual
     27  )
     28  select branch
     29       , currency
     30       , client_id
     31       , loan_no
     32       , inst_mat_date
     33       , inst_seq
     34       , original_inst_amt
     35       , decode(original_inst_amt, 0, 0, sum(int_amt) over(partition by cnt)) int_amt
     36    from (
     37            select branch
     38                 , currency
     39                 , client_id
     40                 , loan_no
     41                 , inst_mat_date
     42                 , inst_seq
     43                 , original_inst_amt
     44                 , int_amt
     45                 , cnt
     46              from t
     47             model
     48             dimension by
     49             (
     50                inst_seq
     51             )
     52             measures
     53             (
     54                branch, currency, client_id, loan_no, inst_mat_date, original_inst_amt, int_amt, 1 cnt
     55             )
     56             rules
     57             (
     58                 cnt[any] = case
     59                                   when original_inst_amt[cv()-1] > 0 then
     60                                      cnt[cv()-1] + 1
     61                                   else
     62                                      nvl(cnt[cv()-1], cnt[cv()])
     63                               end
     64             )
     65         )
     66  /
    
        BRANCH   CURRENCY  CLIENT_ID    LOAN_NO INST_MAT_   INST_SEQ ORIGINAL_INST_AMT    INT_AMT
    ---------- ---------- ---------- ---------- --------- ---------- ----------------- ----------
           110          2        222        100 01-JAN-13          1                 0          0
           110          2        222        100 02-JAN-13          2                 0          0
           110          2        222        100 03-JAN-13          3                 0          0
           110          2        222        100 04-JAN-13          4               500        246
           110          2        222        100 05-JAN-13          5                 0          0
           110          2        222        100 06-JAN-13          6                 0          0
           110          2        222        100 08-JAN-13          8               600        256
           110          2        222        100 07-JAN-13          7                 0          0
           110          2        222        100 09-JAN-13          9                 0          0
           110          2        222        100 11-JAN-01         11                 0          0
           110          2        222        100 10-JAN-01         10                 0          0
           110          2        222        100 12-JAN-01         12               700        274
    
    12 rows selected.
    
    SQL>
    
  • See APEX SQL for the treatment of automatic line

    Hello

    I get an error like this when you try to update with the automatic processing of line:
    ORA-20505: DML error: p_rowid = 89, p_alt_rowid = network_user_mou_id, p_rowid2 =, p_alt_rowid2 is. ORA-06550: line 1, column 17: PL/SQL: ORA-00936: lack of expression ORA-06550: line 1, column 9: PL/SQL: statement ignored
    Is there a way to see the generated SQL code so that I could determine what the problem is?

    Thank you
    Rick

    Rick:

    A way to see the SQL code executed would be to allow "sql_trace" before the process of automatic processing of line. Create a process that fires off the coast before before that the process of automatic line with the following line of code

    alter session set sql_trace=true;
    

    and a process that fires off the coast after the process of automatic line to disable tracing

    alter session set sql_trace=false;
    

    Trace files will occur in the "bdump" or "udump" Directory depending on whether you are using the EPG or OSH.

    As for the error itself, I wonder if it is due to a column that you recently added to the form.

    CITY

  • How the sum of a series of if Athens?

    Given:

    Image.jpg

    I need adding the cost of reception (PM01) breakfast (Cost01), reception cost (Cost02) and lunch cost of reception (Cost03).

    If the cost of each receipt exceeds each meal allowance, use value meal in sum compensation.

    If the cost of each reception is less than or equal to each value of the meal allowance, then use the cost of reception in all.

    You can use a calculation script customized to the field which displays the sum, something like:

    Custom calculation script

    (function () {}

    Get the field values as numbers

    var v1 = + getField("Cost01").value;

    var v2 = + getField("Cost02").value;

    var v3 = + getField("Cost03").value;

    Add the eligible amounts of breakfast, lunch and dinner

    and set the value of this field

    Event.Value = Math.min (v1, 12) + Math.min (v2, 17) + Math.min (v3, 27);

    })();

  • calculation of ratios and rounding - how the sum of last record to give 1

    I'm putting in a single query to calculate the reports for an unknown number of records. I want to turn the ratios to 5 decimal places and I want the total reports of equal to 1.

    for example

    If I have 3 folders with Qty total overal 4,5,6 is 15
    I note 3 lines
    Round (4/15.5),
    Round (5/15.5),
    Round (6/15.5)

    but I want to ensure total = 1
    so I will try to do something like

    Round (4/15.5),
    Round (5/15.5),
    1 - round(4/15,5) - round(5/15,5)

    can someone help show me the sql construction? I've been trying and failing using where clause

    of course this example would add to 1 but other unknown ratios may not match up to 1.

    Published by: user12154024 on November 2, 2009 22:32

    Hello 12154024,

    Welcome to the forum. May not be a more elegant solution, but it shows how it works step by step

    WITH t AS (
    SELECT 4 n FROM dual
    UNION ALL
    SELECT  5 n FROM dual
    UNION ALL
    SELECT 6 n FROM dual
    )
    ,t1 AS (
    SELECT  n
           ,ROUND(RATIO_TO_REPORT(n) OVER (),5) AS rr
           ,COUNT(n) OVER () AS c
           ,ROW_NUMBER() OVER (ORDER BY n) AS rn
    FROM    t
    )
    ,t2 AS (
    SELECT  n
           ,rr
           ,SUM(rr) OVER (ORDER BY n) s
           ,c
           ,rn
    FROM t1
    )
    SELECT  n
           ,rr
           ,CASE WHEN c = rn THEN
                rr + (1 - s)
            ELSE
                rr
            END rr2
           ,s
    FROM    t2
    ORDER BY rn;
    
    N   RR        RR2       S
    --- --------- --------- --------
    4   0.26667   0.26667   0.26667
    5   0.33333   0.33333   0.6
    6   0.4       0.4       1        
    
    3 rows selected
    

    The part "WITH t AS" generates data
    T1 calculate the ratio, counts the number of records and signs a current issue
    T2 to calculate a cumulative ratio
    the last part takes these data and for the last record (number = count running) it allows to adjust the ratio.

    You can see if you are using other data

    WITH t AS (
    SELECT 4.78 n FROM dual
    UNION ALL
    SELECT  5 n FROM dual
    UNION ALL
    SELECT 6 n FROM dual
    )
    ...
    
    N    RR       RR2      S
    ---- -------- -------- --------
    4.78 0.30292  0.30292  0.30292
    5    0.31686  0.31686  0.61978
    6    0.38023  0.38022  1.00001  
    
    3 rows selected
    

    Concerning
    Marcus

  • Weighted average end days: how the sum in different currencies?

    Hello

    I have to introduce a new column named "averages weighted days late" in one of the models.

    It was easily handled by the code in the Oracle report: Aging Ar: calculated as <? If: SUM_PAYMENT < = 0? > 0 <? end if? > <? If: SUM_PAYMENT > 0? > <? SUM_W_DAYS_LATE div SUM_PAYMENT? > <? end if? > UX f

    The customer wants that this weighted means against the different currencies for a single client: How do I implement that?

    Example: Client A - average weighted days late:-16-20 in USD and EUR. = > report displays only the first currency - in this case EUR = >-16 (which is not what is expected)

    Logic: I need to run (-16) +(-20)/2. The logic is simple. However, where should I create this change? Also, this change must be connected to the period during which the report is run for / just for the money? I guess it's related at the same time.

    Thanks in advance

    and then divide it by the number of transactions.

    That's your logic? If yes then ok

    I don't know full logic

    And this must be done in the sql used in the xml file, I guess. Is there an easier option to calculate the end of days average weighted by a modification of the model code? Curious.

    If you already have some fares in the xml file to recalculate, then you can do so by model

    If you do not have the rate, then you can add it to xml format and then calculate by model

    or you can calculate in sql (as an example of data model) and then only show models

    How will be used it is your decision

  • How the sum of these two tables?

    Hello

    I have two tables

    DESC ACTIVITE_EXCEP_FAITE

    NUMBER OF FICHE_ID

    NUMBER OF SERVICES_ID

    NUMBER OF ACTIVITES_EXCEPTIONNELLES_ID

    NUMBER OF TIME

    NUMBER OF ACTIVITE_EXCEP_FAITE_ID

    DESC ACTIVITE_FAITE

    NUMBER OF FICHE_ID

    NUMBER OF ACTIVITES_ID

    NUMBER OF SECTEURS_ID

    LENGTH NUMBER (8.2)

    NUMBER OF ACTIVITE_FAITE_ID

    NUMBER OF TYPE_ACTIVITE_ID

    I want to add the column to the DURATION of the two tables when they get the same FICHE_ID. FICHE_ID is not a join field.

    I've tried this application, but it gives result when two recordings of the two table share the same number FICHE_ID.

    SELECT AF. FICHE_ID, SUM (NVL (AF. LENGTH, 0)) + SUM (NVL (AEF. LENGTH, 0))

    OF AF, ACTIVITE_EXCEP_FAITE AEF ACTIVITE_FAITE

    WHERE AF. FICHE_ID = AEF. FICHE_ID

    GROUP BY AF. FICHE_ID;

    Can you help me write this selection?

    Thank you very much for your help!

    Like this?

    select nvl(af.fiche_id, aef.fiche_id) fiche_id
         , sum(nvl(af.duree,0)) + sum(nvl(aef.duree,0)) duree
      from activite_faite af
      full join
           activite_excep_faite aef
        on af.fiche_id = aef.fiche_id
     group by nvl(af.fiche_id, aef.fiche_id);
    
  • To calculate the sum Vals and LV is higher than its target line LV

    When I answered this thread of application of the hierarchy and the number of subnodes
    I made this question.

    I use Oracle11gR2.

    I want the sum Vals and LV is superior to his LV of the target line to the command by sorkKey.
    Ex if LV 2, sumVal is the sum of this line and another line which LV > 2.
    MyTable
    sortKey  LV  Val
    -------  --  ---
          1   2   10
          3   3   20
          5   4   30
          6   3   40
          7   4   50
          9   2   60
         15   3   70
         16   4   80
    with MyTable(sortKey,LV,Val) as(
    select  1,2,10 from dual union
    select  3,3,20 from dual union
    select  5,4,30 from dual union
    select  6,3,40 from dual union
    select  7,4,50 from dual union
    select  9,2,60 from dual union
    select 15,3,70 from dual union
    select 16,4,80 from dual)
    expected Output
    sortKey  LV  Val  sumVal
    -------  --  ---  ------
          1   2   10     150   (10+20+30+40+50)
          3   3   20      50   (20+30)
          5   4   30      30   (30)
          6   3   40      90   (40+50)
          7   4   50      50   (50)
          9   2   60     210   (60+70+80)
         15   3   70     150   (70+80)
         16   4   80      80   (80)
    If you use subQuerys, the solution is below.
    But it's very complex :-(
    My question is "is it more simple solution?
    For ex using fuction OLAP, model clause etc...
    with MyTable(sortKey,LV,Val) as(
    select  1,2,10 from dual union
    select  3,3,20 from dual union
    select  5,4,30 from dual union
    select  6,3,40 from dual union
    select  7,4,50 from dual union
    select  9,2,60 from dual union
    select 15,3,70 from dual union
    select 16,4,80 from dual)
    select sortKey,LV,Val,
    (select sum(b.Val)
       from MyTable b
      where a.sortKey <= b.sortKey
        and b.sortKey <
            (select nvl(min(c.sortKey),99999)
               from MyTable c
              where c.sortKey > a.sortKey
                and c.LV <= a.LV)) as sumVal
      from MyTable a;

    In fact, it can be simpler:

    with t as (
               select  1 sortkey,2 lv,10 val from dual union all
               select  3,3,20 from dual union all
               select  5,4,30 from dual union all
               select  6,3,40 from dual union all
               select  7,4,50 from dual union all
               select  9,2,60 from dual union all
               select 15,3,70 from dual union all
               select 16,4,80 from dual
              )
    select  sortkey,
            lv,
            val,
            sum(val) over(order by sortkey range between current row and rng following) sumval
      from  (
             select  sortkey,
                     lv,
                     val,
                     nvl(
                         (select min(b.sortkey) from t b where b.sortkey > a.sortkey and b.lv <= a.lv) - a.sortkey - 1,
                         max(sortkey) over() - a.sortkey
                        ) rng
               from  t a
             )
      order by sortkey
    /
    
       SORTKEY         LV        VAL     SUMVAL
    ---------- ---------- ---------- ----------
             1          2         10        150
             3          3         20         50
             5          4         30         30
             6          3         40         90
             7          4         50         50
             9          2         60        210
            15          3         70        150
            16          4         80         80
    
    8 rows selected.
    
    SQL> 
    

    SY.

  • How do I script in DIAdem to include specific lines of code (similar to .ini in LabVIEW files) based on the computer/user?

    I took Basic training courses so DIAdem Advanced and have been scripting for several months.  I am interested in how to include specific lines of code based on the computer.  Told me it would be similar to .ini in LabVIEW files, although I've never used myself .ini files.

    Hi Karen,.

    What do you mean by "includes the lines of code?  Do you mean what happens when you run a command 'ScriptInclude()' or 'ScriptCmdAdd()' in a tiara VBScript?  Or do you mean that you want to run several lines as DIAdem begins, similar to 'ScriptStart() '?

    What do you mean by "computer-based?  Do you mean you want to implement different batch files on different computers, but you are still using the same file (named) command on each target computer?  Or do you mean that you want to implement the same command on all target computers file, but you want different commands to run this file based on the computer on which you are.  In the latter case, how do you determine computer on which you are on - MAC address, logged in user name, or what?

    Brad Turpin

    Tiara Product Support Engineer

    National Instruments

  • How can I change my code the method to set a specific line id in my lov as a default?

    Mr President.

    How can I change my code the method to set a specific line id in my lov as a default value instead of the first value?

        public String defaultDebit() {
    
    
           String debit = (String)getAttributeInternal(DEBIT);
           if (debit == null) {
              COAViewRowImpl coaRow = (COAViewRowImpl)getDebitView1().first();
              if (coaRow != null) {
                 debit = coaRow.getAcctId();
              }
           }
           return debit;
        }
    

    Concerning

    You can see the below example code. This code assumes a view attribute named AcctName and the code returns the AcctId when the AcctName is DEFAULT_DEBIT.

    public String defaultDebit() {}

    String output = (String) getAttributeInternal (DEBIT);
    If (flow == null) {}
    getDebitView1 (.reset ());
    While (getDebitView1 () .hasNext ()) {}
    COAViewRowImpl coaRow = (COAViewRowImpl) getDebitView1 () .next ();
    If (coaRow! = null) {}
    If (coaRow.getAcctName () .equals ("DEFAULT_DEBIT"))
    flow = coaRow.getAcctId ();
    }
    }
    }
    return flow;
    }

    Let us know if this does not work in your case.

    Thank you

  • How to make the sum of the time through SQL?

    Dear friends

    I have a sh_detail table and there are three fields hours1, hours2 hours3. all fields are of type varchar2.

    data are like

    hours1 hours2 total hours3

    02:45 00:18 01:25

    00:38 01:45 00:00

    02:15 02:00 00:15

    1. I want to add on three fields in the total column

    2 and want to make the sum of all areas as select sum (hours1) of sh_detail.

    Please help I will be grateful.

    Kind regards.

    As others have said, use the NUMBER to store times, or the type of data correct INTERVAL, even if the latter cannot be aggregated (using the SUM).

    In the meantime, this will give you the output desired in a few minutes (it is trivial to convert it back in format hh: mm if you wish):

    SQL> with sample_data (id, hours1, hours2, hours3) as (
      2    select 1, '02:45', '00:18', '01:25' from dual union all
      3    select 2, '00:38', '01:45', '00:00' from dual union all
      4    select 3, '02:15', '02:00', '00:15' from dual
      5  )
      6  select id
      7       , sum(h1) h1
      8       , sum(h2) h2
      9       , sum(h3) h3
     10       , sum(h1+h2+h3) as total
     11  from (
     12  select id
     13       , to_number(substr(hours1, 1, 2))*60 + to_number(substr(hours1, 4, 2)) as h1
     14       , to_number(substr(hours2, 1, 2))*60 + to_number(substr(hours2, 4, 2)) as h2
     15       , to_number(substr(hours3, 1, 2))*60 + to_number(substr(hours3, 4, 2)) as h3
     16  from sample_data
     17  )
     18  group by rollup(id) ;
    
            ID         H1         H2         H3      TOTAL
    ---------- ---------- ---------- ---------- ----------
             1        165         18         85        268
             2         38        105          0        143
             3        135        120         15        270
                      338        243        100        681
    
  • How to make SQL * more count the comment and blank line numbers?

    Hello

    Parameter
    Value of the parameter
    Oracle versionEnterprise Edition Release 11.2.0.1.0 - 64 bit
    OPERATING SYSTEMLinux Fedora Core 17 (X86_64)

    I would like to know, is it possible to force SQL * Plus to provide the number of the current in the source file line whenever there is an error? I often put in the first line of my script SQLBLANKLINES the VALUE ON that I may be able to put several consecutive blank lines in my code (I do that sometimes, when I find that it is appropriate to make my code more readable or a sequence of instructions which I believe make their logic more comprehensible for the reader of the Group)

    Now the problem is that SQL * Plus will ignore these empty lines and whenever there is an error, the line number in the error message does not match the actual line number in the source file, but it seems to be the last non-empty line in the file.  Consider the following example:

    SET SQLBLANKLINES ON;

    DECLARE
        var PLS_INTEGER := 10;
    BEGIN


       
        var := 20
    END;
    /

    In the code above on line 9 (also counting blank lines), there is an error (no semicolon at the end of the var: = 20) but when I run the script

    SQL * also, here is the error message I get


    SQL > @myscript.sql;

    END;

    *

    ERROR on line 8:

    ORA-06550: line 8, column 1:

    PLS-00103: encountered the symbol "END" when expected in the following way:

    * & = - + ; <>/ is mod remains not rem

    < an exponent (*) > <>or! = or ~ = > = < = <>and like2 or

    like4 likec between | submultiset of type multiset Member

    The symbol ';' was replaced by 'END' continue.


    SQL >


    As you can see the error message indicates that the error was found on line 8, while in the file, it's really on line 9

    As long as the number of lines in the script is limited, this may not be a problem and we can quickly find the actual line number in the code that causes the error, but for a code, including hundreds (or even thousands) of lines and with many comments and blank lines, find line number given by SQL * error message more becomes complicated.

    So my question: is it possible to make SQ * more properly draw the line numbers, as they appear in the source file?

    Thanks in advance,

    Kind regards

    Dariyoosh

    Hi, Dariyoosh,

    The line numbers in error messages are always from the beginning of the statement, but not the file.  The back-end which checks the errors and generates the error message, has no idea if this statement has appeared in your file, even if the statement was in a file at all, or if it comes from multiple files, each with its own line 1.

    You can divide your scripts into parts, so that the long statements, which may lead to error messages, are each in a separate file, so the statement starts on the line 1 of the file.

    For example, you can call a script called fubar.sql, which looks like this:

    SET SQLBLANKLINES ON;
    
    @@fubar_1
    

    Which calls another script, called fubar_1.sql, located on the same directory as fubar.sql, that looks like this

    DECLARE
        var PLS_INTEGER := 10;
    BEGIN
    
        var := 20
    END;
    /
    

    You never call him directly fubar_1.

Maybe you are looking for