Line number in PL/SQL
Hi,
I want to know the line number in a function where the error has occured.
I have catched that exception but how could i be able to get the line number along with error message.
Thanks,
santhosh
One technique that is fairly common is to use v_loc and number it every 10 in increments. That's not line by line, but block or code section of interest within a procedure/function. When you hit an error, the output can not only output the program name (name of the procedure, as an example, within a package), but also where you were last good in terms of not having an error. In other words, you can see that you made it to location 40 (out of 50) within the current program. General description of this is instrumentation, and there are many ways to instrument code.
Line by line is impractical. Code will fail at the statement level (after compiling) and the line that is output can be far away from where the mistake took place.
Similar Messages
-
Oracle SQL Developer and Errors (Line Number Incorrect)
First, I wanted to state that Oracle SQL Developer 2 is a standout job.
I wanted to report, though, that when Oracle SQL Developer 2 can't compile a block of code or a simple SQL statement has invalid syntax, it does not have an option to accurately go to the line of code in question. GOING TO the erroneous line of code doesn't need to be a feature, but often times the line no. REPORTED by Oracle SQL Developer is incorrect by 50+ lines.
Is this something I could fix on my end? I have five other developers griping about this.
Thank you!I don't know if this is the situation you are talking about, but line numbers for errors in SQL in a SQL Worksheet are not line numbers within the statement but rather line numbers in the worksheet. For example, with the following SQL in the worksheet:
select * from dual;
select * from dual;
select * from dual;
select from dual;Running the "select from dual;" statement (as either statement based on cursor position, selected statement or as script), the error is reported on Line 4, Column 7. As I show line numbers (Tools | Preferences | Code Editor | Line Gutter | Show Line Numbers), this makes sense. Without line numbers showing or having the option to go to the error and with more realistic examples with SQL statements scrolling off the page, I can see that the line number in the errors wouldn't be helpful.
I think -K- is talking about the PL/SQL code editors not reporting the correct line number based on the error line not counting the "create or replace" line at the start of a package (and more for triggers).
theFurryOne -
How to get PL/SQL line number ?
Hello, All !
I have an Error pointing to Line number - "ORA-06512: at "..._PKG", line 295
How do I find out in physical code exactly where this line is ? I used SQL Navigator (it has line count) but It didn't match ! (Function names different in Error message and in Script Editor window and it pointed to a blank line). Does line count start from Package Spec or Body ?
Please Help,
Thanx !The line number is relative to the first line of the body. The most definitive way to identify the exact line would be to use USER_SOURCE ...
SELECT TEXT
FROM USER_SOURCE
WHERE NAME = ...
AND LINE = 295
Richard -
SQL Loader Bad File - Line Number
Is there a way to get line number of records in the bad file or discard file?
Thanks,Hi,
I think you get the line number of the rows failed to load in the log file. The failing rows are the rows you will find in the bad file.
I don't know if the log contains the line numbers of discarded rows.
Liron Amitzi
Senior DBA consultant
[www.dbsnaps.com]
[www.obiumsoftware.com] -
Show the object and the line number, where the error happens in Forms
Hi!
Al lot of our programmer use the ugly when others clause to raise messages like "error <sqlcode> happens in ....". Often this hides the really error in some underlying procedures. Is it possible to call the error stack from forms like in 10g database dbms_utility.format_error_backtrace? Actually FRM-40735 hides all this information. This should be work for client and database pl/sql errors!
With kind regardsFirst of all, send every programmer in your organization a message to STOP doing that. I am afraid there is nothing you can do when you have to call some stupid code from your form that contains the when others then... sequence.
Below is an email I sent out just two months ago. I'll share it with you:
Hi _______,
I looked over the _________ package to try to determine why it was so difficult to find the source of the problem. The problem was that the line number reported when the job failed was line 326, which is the Raise command at the end of the __xyz__ procedure.
When someone writes:
exception when others then raise;it causes line number reporting to fail when an unexpected Oracle error is encountered. Furthermore, the line does absolutely no good, because Oracle will automatically raise unhandled errors without that code.
The only thing that code does is cause problems when someone looks for the source of a failure. Without that code, job failures can be located in just a few minutes.
That same code sequence is repeated three times in the _________ package. The problem may also exist in the __abc___... functions that the _______.lookup_xxxl function calls, since no line numbers were reported from there, either. It would be very helpful if you would remove the problem code, and PLEASE instruct everyone on your staff to never use that sequence anywhere.
- - - - - - - - - - - - - - - - - - - - - - end of email - - - - - - - - - - - - - - - - - - - - - -
Now, in addition, you can trap FRM-40735 in your on-error trigger and then display the message found in DBMS_ERROR_TEXT. In fact, you might try the format_error_backtrace from there, too. -
How to find proc/func name from package name and line number?
Hi,
We are using the pl/sql call stack dump (dbms_utility.format_call_stack) for some debugging purposes. But in the case of a package body execution, the dump does not return the name of the procedure/function that is being executed, but only the name of the package and the line number being executed. So, we have a requirement wherein we need to extract the type and name of a package subunit from the package name and line number.
e.g.
From the information package 'A', line number 739
we should be able to deduce that line 739 is a part of *'function A.f'*
Does the oracle database provide any native mechanism (PL/SQL packages or otherwise) to support such functionality? If it does not, how can we achieve the desired result?
Thanks in advance,
ShashankThe approach we are currently planning to take up is this :
1. Write PL/SQL code to parse the entire source (user_source) and build a database table with a structure like this :
PACKAGE_NAME | UNIT_TYPE | UNIT_NAME | START_LINE | END_LINE
=============================================
A | PROCEDURE | P1 | 20 | 345
A | FUNCTION | F1 | 347 | 629
etc..
2. Start PL/SQL package execution.
3. Keep dumping call stack snapshots whenever a custom debug procedure is called.
4. Dump the package name and line number to a log file.
5. Using the package name and line number, query the table built in step 1 and build the final report which shows the control flow in a readable form.
What we want is to get rid of step 5 and by some means get the logic to extract the unit type and name in step 4 itself.
Keep them coming..
Thanks and regards,
Shashank -
Feature Request: Line Number on Syntax Error
Hi,
When I execute a query in the query window and there is a syntax error, I don't get the line number of where the error is as I normally do in SQLPlus. Is this this something that can be added to the error message?
thanks
-NielsAlternatively, if you feed the SQL into a procedure (or anon block) something like below, this will give you the exact character position of the failure.
I've previously used this in a java/jdbc web-based ad-hoc query solution to good effect, and so blaming java/jdbc is not really valid.......
CREATE OR REPLACE
PROCEDURE parse
(sqlstr IN VARCHAR2)
IS
cur BINARY_INTEGER := DBMS_SQL.OPEN_CURSOR;
errpos BINARY_INTEGER;
fdbk BINARY_INTEGER;
BEGIN
DBMS_SQL.PARSE (cur, sqlstr, DBMS_SQL.NATIVE);
DBMS_SQL.CLOSE_CURSOR (cur);
EXCEPTION
WHEN OTHERS
THEN
errpos := DBMS_SQL.LAST_ERROR_POSITION;
DBMS_OUTPUT.PUT_LINE (SQLERRM || ' at pos ' || errpos);
DBMS_SQL.CLOSE_CURSOR (cur);
END; -
2.1 EA2: is it possible to pass current line number to external tool
When I define external tools (in Tools / External Tools...) I can pass current file name and directory to my external program.
Is it also possible to pass current line number (where is my cursor in open file) to external program as a parameter?
If not then it would be a feature request from me :)
And also - is it possible to develop SQL Developer extensions for syntax color coding of other file types (meaning other than PL/SQL files)?raymonds,
For line numbers, we cannot do it at the moment as it is not exposed in that API, however, you can request it on http://sqldeveloper.oracle.com at the feature request station
For color coding for another language, you can develop a hilighting plugin, but we do not have an easy way of associating the plugin with an editor for a specific file type. Again this would be a feature request.
Remember, all these get evaluated each month and assigned into Enhancements for the tool. If enough folks vote for the feature, it is highly likely it will appear.
Barry -
Retrieving line-number of the last error
Hello !
Is it possible to access the line number where the last error in a PL/SQL procedure occured ?
At example:
CREATE OR REPLACE PROCEDURE do_stupid
IS
tempNum Number;
BEGIN
FOR i IN 1..5
LOOP
temp := sysdate;
END LOOP;
tempNum := 2;
tempNum := tempNum / 0;
tempNum := 3;
EXCEPTION
WHEN OTHERS THEN
-- i want to access the line-number of the error "tempnum / 0"
END do_stupid;
Thank You
FlorianIf you are just trying to debug one procedure, eliminating the exception section and running it from sql*plus will cause it to return an error message that includes the line number. But this won't work if you are trying to trap the error and log it in some table or some such thing.
SQL> CREATE OR REPLACE PROCEDURE do_stupid
2 IS
3 tempnum NUMBER;
4 temp DATE;
5 BEGIN
6 FOR i IN 1..5
7 LOOP
8 temp := SYSDATE;
9 END LOOP;
10 tempnum := 2;
11 tempnum := tempnum / 0;
12 tempnum := 3;
13 END do_stupid;
14 /
Procedure created.
SQL> EXEC do_stupid
BEGIN do_stupid; END;
ERROR at line 1:
ORA-01476: divisor is equal to zero
ORA-06512: at "SCOTT.DO_STUPID", line 11
ORA-06512: at line 1 -
How to go to related line number
hi all,
Cause: FDPSTP failed due to ORA-06502: PL/SQL: numeric or value error: character string buffer too small
ORA-06512: at "APPS.WSH_UTIL_CORE", line 2093
ORA-06512: at "APPS.UML_POS_ORDER_IMPORT_PKG", line 923
This is package and I would like how can I go to line number 923 to check quick results.
Thanksuser9275313 wrote:
hi all,
Cause: FDPSTP failed due to ORA-06502: PL/SQL: numeric or value error: character string buffer too small
ORA-06512: at "APPS.WSH_UTIL_CORE", line 2093
ORA-06512: at "APPS.UML_POS_ORDER_IMPORT_PKG", line 923
This is package and I would like how can I go to line number 923 to check quick results.Open the package in the editor of your choice and use the editor's build in ability to go to the appropriate line.
If the package is wrapped or a built in oracle package, you may struggle to open it, but then that would imply that either there's a bug in the package (ensure you're database is patched and check oracle support for known issues), or you're more likely calling procedures/functions in the package with the wrong parameters. -
SP2-0226: Invalid line number
How can I look up error codes? Also, does anybody know what this means? It doesn't seem to affect the way the procedure runs.
How can I look up error codes?http://www.oracle.com/pls/db92/db92.error_search?remark=homepage&prefill=ORA-
As you can see below, there is no line number 10 in the current SQL buffer to goto.
hence the error.
SQL> select
2 *
3 from
4 scott.emp
5 where
6 rownum < 10 ;
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
7369 SMITH CLERK 7902 17-DEC-1980 800 20
7499 ALLEN SALESMAN 7698 20-FEB-1981 1600 300 30
7521 WARD SALESMAN 7698 22-FEB-1981 1250 500 30
7566 JONES MANAGER 7839 02-APR-1981 2975 20
7654 MARTIN SALESMAN 7698 28-SEP-1981 1250 1400 30
7698 BLAKE MANAGER 7839 01-MAY-1981 2850 30
7782 CLARK MANAGER 7839 09-JUN-1981 2450 10
7788 SCOTT ANALYST 7566 19-APR-1987 3000 20
7839 KING PRESIDENT 17-NOV-1981 5000 10
9 rows selected.
SQL> l10
SP2-0226: Invalid line number
SQL>Message was edited by:
Kamal Kishore -
Hi
Is there some way to get line number error when there is some exception ?
I use oracle 9.2.02
thank you in advancesybrand_b wrote:
When you trap the exception you need to use dbms_utility.format_error_stack.
Thid will not provide correct line numbers. This issue has been resolved in 10g or 11g, and 9iR2 is going completely out of support in July.FORMAT_ERROR_STACK will not provide any line numbers:
SQL> select * from v$version
2 /
BANNER
Oracle Database 11g Enterprise Edition Release 11.1.0.6.0 - Production
PL/SQL Release 11.1.0.6.0 - Production
CORE 11.1.0.6.0 Production
TNS for 32-bit Windows: Version 11.1.0.6.0 - Production
NLSRTL Version 11.1.0.6.0 - Production
SQL> set serveroutput on format word_wrapped
SQL> begin
2 raise no_data_found;
3 exception
4 when no_data_found
5 then
6 dbms_output.put_line('ERROR_STACK: ' || DBMS_UTILITY.FORMAT_ERROR_STACK);
7 dbms_output.put_line('ERROR_BACKTRACE: ' || DBMS_UTILITY.FORMAT_ERROR_BACKTRACE);
8 end;
9 /
ERROR_STACK: ORA-01403: no data found
ERROR_BACKTRACE: ORA-06512: at line 2
PL/SQL procedure successfully completed.
SQL> SY. -
Please hep to generate same line number to print in file
Hi
I am generating file by taking data from few tables. I need to generate file data from below structure data :
i.e In table A for order O having product p1,p2,p3,p4, lines will be wrriten to file in following manner
Line Number
O -p1 - 1
O -p2 - 2
O -p3 - 3
O -p4 - 4
Now another line is from table which will have only two product entries for the order O in below manner
i.e In table B for order O having product p2,p4. so for this lines should be match with above line number of order like this :
Line Number
O - p2 -2
O - p4 -4
First all data from table A will be writeen. Then only from TABLE B data should be wrriten to file.
Can anybody please help how to match line number for both the tables?
Thanks in advancePerhaps a clearer output would be if we had different descriptions on each of the tables A an B to output with each of the rows..
SQL> ed
Wrote file afiedt.buf
1 with A as (select 1 as order_id, 'p1' as product_id, 'A - order 1 product 1' as descr from dual union all
2 select 1, 'p2', 'A - order 1 product 2' from dual union all
3 select 1, 'p3', 'A - order 1 product 3' from dual union all
4 select 1, 'p4', 'A - order 1 product 4' from dual union all
5 select 2, 'p1', 'A - order 2 product 1' from dual union all
6 select 2, 'p2', 'A - order 2 product 2' from dual union all
7 select 2, 'p3', 'A - order 2 product 3' from dual)
8 ,B as (select 1 as order_id, 'p2' as product_id, 'B - order 1 product 2' as descr from dual union all
9 select 1, 'p4', 'B - order 1 product 4' from dual union all
10 select 2, 'p3', 'B - order 2 product 3' from dual)
11 -- end of test data
12 select order_id
13 ,product_id
14 ,row_number() over (partition by order_id order by product_id) as line_number
15 ,descr
16 from A
17 union all
18 select order_id, product_id, line_number, descr
19 from (
20 select b.order_id
21 ,b.product_id
22 ,row_number() over (partition by a.order_id order by a.product_id) as line_number
23 ,b.descr
24 from A left outer join B on (a.order_id = b.order_id and a.product_id = b.product_id)
25 )
26* where order_id is not null
SQL> /
ORDER_ID PR LINE_NUMBER DESCR
1 p1 1 A - order 1 product 1
1 p2 2 A - order 1 product 2
1 p3 3 A - order 1 product 3
1 p4 4 A - order 1 product 4
2 p1 1 A - order 2 product 1
2 p2 2 A - order 2 product 2
2 p3 3 A - order 2 product 3
1 p2 2 B - order 1 product 2
1 p4 4 B - order 1 product 4
2 p3 3 B - order 2 product 3
10 rows selected.
SQL> -
Oracle I Expense Line Number Issue
Hi Experts,
I have put custom validations on Credit Card and Cash Transaction page in I Expense. For fetching the line number, i am taking the distribution_line_number column of ap_expense_report_lines_all table. But this is creating one problem. If user enters 2 lines on Credit Card transaction page and 3 on Cash Transaction page, then if an error is on first line of Cash Transaction page then error is populated as Error at Line 3.
Please knoe if anybody of you have faced the similar issue in the past and is there any code provided by Oracle to find the correct line numberHi,
Thanks a lot for your immediate response.
But I have few more doubts. The srw.get_page_num will return the current page number only. Is there any srw function to get the total no. of pages?
Or can you please explain how to get values in the boilder plate. We tried this but boilder plates could not be made invisible. And also if we tried to get the values inside a PL/SQL formula, it is not accessible.
Awaiting your reply...
Thanks in advance. -
Delivery schedule line number in make to order
Hi all,
i am doing make to order scenario with 20 strategy group. In sales order we r defining the different delivery schedule lines.when i run the MRP and getting the plan orders for all the FG material and semifinished material, the sale order number and sale order item number is getting updated in production order . Beside these two , delivery schedule line number is not populated and delivery date is not picking correctly in production order.
please give your valuable suggestion .
i would be highly thankful to u
regards
piyushHi
When you do the MRP Run at MD02, maintain the Delivery Schedules as 3 (schedule lines), so when ever you do the MRP Run, it will run along with the delievry date.
reward if it helps
Regards
Prasanna R
Maybe you are looking for
-
Images scrambled after iPhoto update
This week, I moved photos from an old Mac to a new Mac. The photos that had been so neatly organized on the old computer came in all scrambled on the new Mac...two years worth of photos in total disorder. Does the new iPhoto have the settings and con
-
Hi Friends, 3 goods receipts which are having excisable items, while doing IV , are not capturing excise values. for 1st goods receipt, IV is not done. For 2nd goods receipt, IV has been parked, for 3rd one IV has been posted without excise values. T
-
Dictionary help inpout/output
Hi all, I have attached a search help in a context attribute but I need to pass some extra values in the search help before it is called. (the system's language). How can I set up the input and output of a dictionary based search help on abap web dyn
-
At what seems to be random intervals Apache stops responding to requests. When I check in top, I see a slew of httpd processes that report "stuck" - never seen a process report as stuck before.... Sampling a stuck process gives this: Analysis of samp
-
Where is my captured image/ file saved?
Captured images appear in the Sprout Gallery. These are saved to the Captured Images folder in the Pictures library: This PC/Pictures/Captured Images. I work for HP, supporting the HP Experts who volunteer their time and technical knowledge to help o