# Line Numbers for PL/SQL code

**URL:** <https://forums.toadworld.com/t/line-numbers-for-pl-sql-code/39345>\
**Category:** Toad for Oracle & DevOps Toolkit\
**Created:** [April 17, 2017, 4:39pm UTC](https://forums.toadworld.com/t/line-numbers-for-pl-sql-code/39345 "2017-04-17T16:39:23Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![tom.wickerath](https://avatars.discourse-cdn.com/v4/letter/t/bb73d2/32.png) [@tom.wickerath](https://forums.toadworld.com/u/tom.wickerath)\
**Post date:** [April 17, 2017, 4:39pm UTC](https://forums.toadworld.com/t/line-numbers-for-pl-sql-code/39345/1 "2017-04-17T16:39:23Z")

</div>

Hello -

Using TOAD for Oracle, version 12.10.0.30. When I encounter a PL/SQL error, which sadly is very often as I'm a newbie [:)] when it comes to PL/SQL, the line number in the Oracle error message is not correct if my code contains comments and/or blank lines. Is there any way to get the true and correct line number to display? For example, the attached image shows a slightly modified version of code provided by Tom Kyte for searching all columns in all tables. For anyone interested, I am running a modified version of code available at this URL:  
[asktom.oracle.com/.../f](https://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:37336026927381#42426083757635)

I am only allowed to run this code in anonymous mode, as the DBA will not create a saved procedure. I have added extensive commenting that is shown on the first (32) lines. As you can see, the error number indicates a line (line 42) that could not possibly have attracted the error in question, since this is still part of the Declare section:

 ![TOADPL_SQLLineNo.jpeg](https://global.discourse-cdn.com/quest/original/2X/f/f2f6669d0de491323cd207db6bd30d998b4563b1.jpeg)

**Second Question**

This one is specific to this search procedure. I have copied the procedure below, sans a few comments internal to the company I work for, that I cannot share. My question relates to the third comment. I have found that if two columns in the same table include the search term (same data), only the first column found will be displayed in the output. I know it is not good database design to have data repeated in two columns, but it is what it is....I have no control of the existing design.

Thank You,

Tom

* * *

/\* Adaptation of Tom Kyte procedure to search all tables in an Oracle database for a particular  
data value. This adaptation allows the procedure to run in anonymous mode, which means  
that you do not need to create the procedure first.

Reference:  
[asktom.oracle.com/.../f](https://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:37336026927381#42426083757635)

Note:  
Had to use the ALL\_TAB\_COLUMNS table, instead of the USER\_TAB\_COLUMNS table.  
Included a criteria for OWNER that is not found in the original procedure.

CAUTIONS:  
1.) MUST use the "Execute as script" button. MUST select the correct schema, in TOAD's  
"Current Schema" drop-down, to run as that user. If changing the schema, note that there are  
two places where the schema is specified in the code.

2.) 4 line comment removed

3.) This procedure seems to stop searching a table after it finds a hit. If the searched string is  
included in a different column in the same table, it appears as if the procedure does not find  
the data.

\*/

set serveroutput on size unlimited

declare  
i\_count number:=0;  
l\_cols long;  
l\_where long;  
l\_cursor sys\_refcursor;  
l\_cname varchar2(4000);  
p\_string varchar2(4000):='C93A';

begin  
dbms\_application\_info.set\_client\_info( '%' || p\_string || '%' );  
dbms\_output.put\_line('Data Searched: ' || p\_string);  
dbms\_output.put\_line(' ');

for x in ( select table\_name from all\_tables where owner = 'APDBMS\_SOR'  
order by table\_name ) -- \<-- Added by Tom, so that results will print alphabetically, by table\_name

-- for x in ( select table\_name from user\_tables )  
loop  
l\_cols := 'case when 1=0 then ''x'' ';  
l\_where := ' where ( 1=0 ';  
for y in  
(  
select '"' || column\_name || '"' column\_name  
from all\_tab\_columns  
-- from user\_tab\_columns  
where table\_name = upper(x.table\_name)  
and owner = 'APDBMS\_SOR'  
and (data\_type in ( 'CHAR', 'NVARCHAR2', 'VARCHAR2' ))

--and (data\_type in ( 'CHAR', 'DATE', 'FLOAT', 'NCHAR', 'NUMBER', 'NVARCHAR2', 'VARCHAR2' )  
--or data\_type like 'INTERVAL%' or data\_type like 'TIMESTAMP%' )  
-- order by column\_name -- \<-- Added by Tom, so that results will print alphabetically, by table\_name, but it turns out the procedure finds only the first column in a table.  
)

loop  
l\_cols := l\_cols || ' when ' || y.column\_name ||  
' like sys\_context(''userenv'',''client\_info'') then ' ||  
' ''' || y.column\_name || '''';  
l\_where := l\_where || ' or ' || y.column\_name || ' like sys\_context(''userenv'',''client\_info'') ';  
end loop;

open l\_cursor for 'select ' || l\_cols || 'else null end cname from ' ||  
x.table\_name || l\_where || ') and rownum=1';  
fetch l\_cursor into l\_cname;

if ( l\_cursor%found ) then  
i\_count:=i\_count + 1; -- Why can't I increment a counter variable without attracting error: PLS-00306: wrong number or types of arguments in call to '+'  
-- Answer: i\_count was declared as long. When I changed it to number, the code runs, however, it appears to be null below  
dbms\_output.put\_line(x.table\_name || chr(9) || chr(9) || l\_cname );  
--dbms\_output.put\_line('-- ' || x.table\_name || chr(9) || chr(9) || l\_cname );  
dbms\_output.put\_line('select \* from ' || x.table\_name || ' where ' || l\_cname || ' like ''%' || p\_string || '%'';');  
dbms\_output.put\_line(' ');  
end if;

close l\_cursor;

end loop;  
dbms\_output.put\_line(' '); -- Added to provide a single line in-between our results and the summary that starts with " PL/SQL procedure successfully completed."  
dbms\_output.put\_line(i\_count || ' tables found.'); -- \<-- Result is " tables found." without any number indicated??  
-- Solution: Initialized variable to zero in declaration, e.g. Changed: "i\_count number;" to: "i\_count number:=0;"  
dbms\_output.put\_line(' ');  
end;  
/

---

<div class="post-metadata">

**Author:** ![GTDG](https://sea1.discourse-cdn.com/quest/user_avatar/forums.toadworld.com/gtdg/32/140_2.png) [@GTDG](https://forums.toadworld.com/u/GTDG)\
**Post date:** [April 17, 2017, 5:51pm UTC](https://forums.toadworld.com/t/line-numbers-for-pl-sql-code/39345/2 "2017-04-17T17:51:05Z")

</div>

For the first question, that line number is what comes back from Oracle and what they're telling you is that the error is occurring on the 42nd line of code that they see. You'll see the same error if you were to run it via SQL\*Plus. Once you execute the script, go to the Messages tab on the Editor and you'll see a tab with Errors. Clicking on these errors will take you to where the line actually error'd out.

I'll have to let someone with ninja level SQL skills answer question #2.

> On Apr 17, 2017, at 7:40 PM, tom.wickerath [bounce-tomwickerath@toadworld.com](mailto:bounce-tomwickerath@toadworld.com) wrote:

> **[Line Numbers for PL/SQL code](http://www.toadworld.com/products/toad-for-oracle/f/10/t/32448)**

> Thread created by tom.wickerath  
> Hello -

> Using TOAD for Oracle, version 12.10.0.30. When I encounter a PL/SQL error, which sadly is very often as I'm a newbie [:)] when it comes to PL/SQL, the line number in the Oracle error message is not correct if my code contains comments and/or blank lines. Is there any way to get the true and correct line number to display? For example, the attached image shows a slightly modified version of code provided by Tom Kyte for searching all columns in all tables. For anyone interested, I am running a modified version of code available at this URL:
> 
> ```
> [asktom.oracle.com/.../f](https://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:37336026927381#42426083757635)
> 
> ```

> I am only allowed to run this code in anonymous mode, as the DBA will not create a saved procedure. I have added extensive commenting that is shown on the first (32) lines. As you can see, the error number indicates a line (line 42) that could not possibly have attracted the error in question, since this is still part of the Declare section:

> 

> 

> **Second Question**

> This one is specific to this search procedure. I have copied the procedure below, sans a few comments internal to the company I work for, that I cannot share. My question relates to the third comment. I have found that two columns in the same table include the search term, only the first column found will be displayed in the output. I know it is not good database design to have data repeated in two columns, but it is what it is....I have no control of the existing design.

> Thank You,

> Tom

> * * *

> /\* Adaptation of Tom Kyte procedure to search all tables in an Oracle database for a particular
> 
> data value. This adaptation allows the procedure to run in anonymous mode, which means
> 
> that you do not need to create the procedure first.
> 
> Reference:
> 
> [asktom.oracle.com/.../f](https://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:37336026927381#42426083757635)
> 
> Note:
> 
> Had to use the ALL\_TAB\_COLUMNS table, instead of the USER\_TAB\_COLUMNS table.
> 
> Included a criteria for OWNER that is not found in the original procedure.

> CAUTIONS:
> 
> 1.) MUST use the "Execute as script" button. MUST select the correct schema, in TOAD's
> 
> "Current Schema" drop-down, to run as that user. If changing the schema, note that there are
> 
> two places where the schema is specified in the code.

> 2.) 4 line comment removed

> 3.) This procedure seems to stop searching a table after it finds a hit. If the searched string is
> 
> included in a different column in the same table, it appears as if the procedure does not find
> 
> the data.

> \*/

> set serveroutput on size unlimited

> declare
> 
> i\_count number:=0;
> 
> l\_cols long;
> 
> l\_where long;
> 
> l\_cursor sys\_refcursor;
> 
> l\_cname varchar2(4000);
> 
> p\_string varchar2(4000):='C93A';
> 
> begin
> 
> dbms\_application\_info.set\_client\_info( '%' || p\_string || '%' );
> 
> dbms\_output.put\_line('Data Searched: ' || p\_string);
> 
> dbms\_output.put\_line(' ');

> for x in ( select table\_name from all\_tables where owner = 'APDBMS\_SOR'
> 
> order by table\_name ) -- \<-- Added by Tom, so that results will print alphabetically, by table\_name
> 
> -- for x in ( select table\_name from user\_tables )
> 
> loop
> 
> l\_cols := 'case when 1=0 then ''x'' ';
> 
> l\_where := ' where ( 1=0 ';
> 
> for y in
> 
> (
> 
> select '"' || column\_name || '"' column\_name
> 
> from all\_tab\_columns
> 
> -- from user\_tab\_columns
> 
> where table\_name = upper(x.table\_name)
> 
> and owner = 'APDBMS\_SOR'
> 
> and (data\_type in ( 'CHAR', 'NVARCHAR2', 'VARCHAR2' ))
> 
> --and (data\_type in ( 'CHAR', 'DATE', 'FLOAT', 'NCHAR', 'NUMBER', 'NVARCHAR2', 'VARCHAR2' )
> 
> --or data\_type like 'INTERVAL%' or data\_type like 'TIMESTAMP%' )
> 
> -- order by column\_name -- \<-- Added by Tom, so that results will print alphabetically, by table\_name, but it turns out the procedure finds only the first column in a table.
> 
> )
> 
> loop
> 
> l\_cols := l\_cols || ' when ' || y.column\_name ||
> 
> ' like sys\_context(''userenv'',''client\_info'') then ' ||
> 
> ' ''' || y.column\_name || '''';
> 
> l\_where := l\_where || ' or ' || y.column\_name || ' like sys\_context(''userenv'',''client\_info'') ';
> 
> end loop;
> 
> open l\_cursor for 'select ' || l\_cols || 'else null end cname from ' ||
> 
> x.table\_name || l\_where || ') and rownum=1';
> 
> fetch l\_cursor into l\_cname;
> 
> if ( l\_cursor%found ) then
> 
> i\_count:=i\_count + 1; -- Why can't I increment a counter variable without attracting error: PLS-00306: wrong number or types of arguments in call to '+'
> 
> -- Answer: i\_count was declared as long. When I changed it to number, the code runs, however, it appears to be null below
> 
> dbms\_output.put\_line(x.table\_name || chr(9) || chr(9) || l\_cname );
> 
> --dbms\_output.put\_line('-- ' || x.table\_name || chr(9) || chr(9) || l\_cname );
> 
> dbms\_output.put\_line('select \* from ' || x.table\_name || ' where ' || l\_cname || ' like ''%' || p\_string || '%'';');
> 
> dbms\_output.put\_line(' ');
> 
> end if;
> 
> close l\_cursor;
> 
> end loop;
> 
> dbms\_output.put\_line(' '); -- Added to provide a single line in-between our results and the summary that starts with " PL/SQL procedure successfully completed."
> 
> dbms\_output.put\_line(i\_count || ' tables found.'); -- \<-- Result is " tables found." without any number indicated??
> 
> -- Solution: Initialized variable to zero in declaration, e.g. Changed: "i\_count number;" to: "i\_count number:=0;"
> 
> dbms\_output.put\_line(' ');
> 
> end;
> 
> /

> To reply, please reply-all to this email.
> 
> [Stop receiving emails](http://www.toadworld.com/products/toad-for-oracle/f/10/t/32448?subscribe=false) on this subject.
> 
> Or [Unsubscribe from Toad for Oracle Forum](http://www.toadworld.com/products/toad-for-oracle/f/10?subscribe=false) notifications altogether.
> 
> Toad for Oracle - Discussion Forum

> [Flag](http://www.toadworld.com/products/toad-for-oracle/f/10/t/32448?AbuseContentId=fc8453e6-3a5e-4c88-87e5-7be581c46196&AbuseContentTypeId=46448885-d0e6-4133-bbfb-f0cd7b0fd6f7&AbuseFlag=true) this post as spam/abuse.

---

<div class="post-metadata">

**Author:** ![NormTeamT](https://sea1.discourse-cdn.com/quest/user_avatar/forums.toadworld.com/normteamt/32/53_2.png) [@NormTeamT](https://forums.toadworld.com/u/NormTeamT)\
**Post date:** [April 18, 2017, 1:01am UTC](https://forums.toadworld.com/t/line-numbers-for-pl-sql-code/39345/3 "2017-04-18T01:01:15Z")

</div>

Morning Tom,

this is why you only get one row listed:

open l\_cursor for 'select ’ || l\_cols || 'else null end cname from ’ ||

x.table\_name || l\_where || ‘) and rownum=1’;

The ‘and rownum = 1’ is saying, only give me the first row.

If you do not initialise a declared variable with a value at declaration, or at the start of the code after the begin, then it has the value NULL. You cannot add etc to a NULL. This is why you never got a count.

You don’t need to upper case the table name. You can use the table name returned from all/user\_tables as is, when looking for columns, as it is already correct. Using upper() will stop oracle from using an index, if there is one, on table\_name, in all/user\_tab\_columns.

HTH

Cheers,

Norm. [TeamT]

–

Sent from my Android device with K-9 Mail. Please excuse my brevity.

---

<div class="post-metadata">

**Author:** ![Dennis\_Paulus](https://sea1.discourse-cdn.com/quest/user_avatar/forums.toadworld.com/dennis_paulus/32/138_2.png) [@Dennis\_Paulus](https://forums.toadworld.com/u/Dennis_Paulus)\
**Post date:** [April 18, 2017, 5:52am UTC](https://forums.toadworld.com/t/line-numbers-for-pl-sql-code/39345/4 "2017-04-18T05:52:06Z")

</div>

That script is a little messy imho. Here’s one that may be a little easier to understand (at least it is to me 🙂 . Feel free to change it, or whatever to suit your needs/wants. Just add the search criteria and the schema you want to search. Hope it helps…

declare

l\_column\_name varchar2(128);  
l\_count integer := 0;  
l\_search\_string varchar2(100) := ‘{search\_criteria}’;  
l\_schema varchar2(100) := ‘{Schema\_Name}’;

cursor c\_get\_tables is  
select table\_name c\_table\_name  
from all\_tables  
where owner = l\_schema;

begin

dbms\_output.put\_line('Searching for tables in ‘||l\_schema||’ with columns named: '||l\_search\_string);

for cur\_rec in c\_get\_tables loop  
l\_column\_name := null;

begin  
select column\_name  
into l\_column\_name  
from all\_tab\_columns  
where table\_name = cur\_rec.c\_table\_name  
and data\_type in (‘CHAR’, ‘NVARCHAR2’, ‘VARCHAR2’)  
and column\_name = upper(l\_search\_string);  
exception when no\_data\_found then  
null;  
end;

if l\_column\_name is not null then  
l\_count := l\_count + 1;  
dbms\_output.put\_line(cur\_rec.c\_table\_name||’ - '||l\_column\_name);  
end if;

end loop;

dbms\_output.put\_line('Total Tables found: '||l\_count);

exception when others then  
dbms\_output.put\_line(SQLERRM);  
end;

---

<div class="post-metadata">

**Author:** ![tom.wickerath](https://avatars.discourse-cdn.com/v4/letter/t/bb73d2/32.png) [@tom.wickerath](https://forums.toadworld.com/u/tom.wickerath)\
**Post date:** [April 18, 2017, 12:26pm UTC](https://forums.toadworld.com/t/line-numbers-for-pl-sql-code/39345/5 "2017-04-18T12:26:02Z")

</div>

Hi Gregory,

Yes, I understand that this line number is what comes back from Oracle, and would be seen in SQL Plus. It is just a bit of a PITA to have to add the number of comment lines to the indicated line number in the error message, to try to find the correct location. This particular procedure is fairly short, but we have spaghetti code [a Steven Feuerstein term, from his video titled "Write Tiny Chunks of (Reusable) Code" [https://youtu.be/bCVFn2tvDqE](https://youtu.be/bCVFn2tvDqE)], that goes on for 20 printed pages. It is not so easy to find the actual lines that attracted an error, in those cases.

> Once you execute the script, go to the Messages tab on the Editor and you'll see a tab with Errors. Clicking on these errors will take you to where the line actually error'd out.

I think I found where you meant, but it does not take me anywhere by double-clicking or right-clicking. What am I doing wrong?

It looks like this:

Messages tab  
Errors

[Error] ORA-00942: table or view does not exist ORA-06512: at line 42 (36: 0): \>\> declare i\_count number:=0; .................

I cannot seem to figure out how to attach an image to this reply (it took me a while to figure out how to attach the first image last night).

Thank You,  
Tom

---

<div class="post-metadata">

**Author:** ![tom.wickerath](https://avatars.discourse-cdn.com/v4/letter/t/bb73d2/32.png) [@tom.wickerath](https://forums.toadworld.com/u/tom.wickerath)\
**Post date:** [April 18, 2017, 12:36pm UTC](https://forums.toadworld.com/t/line-numbers-for-pl-sql-code/39345/6 "2017-04-18T12:36:30Z")

</div>

Hi Dennis,

Thank you for your contribution, but I cannot get it to work?

I searched my test sandbox schema (TGW7078) for the string ‘C93A’. Using the modified procedure I posted, I find 22 tables:

22 tables found.

PL/SQL procedure successfully completed.  
Time End: 4/18/2017 12:31:39 PM  
Elapsed Time for Script Execution: 19 secs

However, after substituting the schema and search term into your procedure, e.g.:

declare  
l\_column\_name varchar2(128);  
l\_count integer := 0;  
l\_search\_string varchar2(100) := ‘C93A’;  
l\_schema varchar2(100) := ‘TGW7078’;  
etc.

I get this return result:

Time Start: 4/18/2017 12:35:30 PM  
Searching for tables in TGW7078 with columns named: C93A  
Total Tables found: 0  
PL/SQL procedure successfully completed.  
Time End: 4/18/2017 12:35:31 PM  
Elapsed Time for Script Execution: 807 msecs

I am not skilled enough at PL/SQL, at this point, to do effective troubleshooting. Any ideas?

Thanks,

Tom

---

<div class="post-metadata">

**Author:** ![tom.wickerath](https://avatars.discourse-cdn.com/v4/letter/t/bb73d2/32.png) [@tom.wickerath](https://forums.toadworld.com/u/tom.wickerath)\
**Post date:** [April 18, 2017, 12:40pm UTC](https://forums.toadworld.com/t/line-numbers-for-pl-sql-code/39345/7 "2017-04-18T12:40:00Z")

</div>

Oh, I just noticed something from your return result: “Searching for tables in TGW7078 with **columns** named: C93A”.

I am looking for data in columns, not column names. I just tried it with a known column name (ap\_entry\_id), but it still returns no results:

Time Start: 4/18/2017 12:39:04 PM  
Searching for tables in TGW7078 with columns named: ap\_entry\_id  
Total Tables found: 0  
PL/SQL procedure successfully completed.  
Time End: 4/18/2017 12:39:05 PM  
Elapsed Time for Script Execution: 1 sec

---

<div class="post-metadata">

**Author:** ![GTDG](https://sea1.discourse-cdn.com/quest/user_avatar/forums.toadworld.com/gtdg/32/140_2.png) [@GTDG](https://forums.toadworld.com/u/GTDG)\
**Post date:** [April 18, 2017, 12:41pm UTC](https://forums.toadworld.com/t/line-numbers-for-pl-sql-code/39345/8 "2017-04-18T12:41:41Z")

</div>

Just clicking on the line will (should) take you to that line in the editor.

> On Apr 18, 2017, at 3:37 PM, tom.wickerath [bounce-tomwickerath@toadworld.com](mailto:bounce-tomwickerath@toadworld.com) wrote:

> **[RE: Line Numbers for PL/SQL code](http://www.toadworld.com/products/toad-for-oracle/f/10/p/32448/65442#65442)**

> Reply by tom.wickerath  
> Hi Dennis,

> Thank you for your contribution, but I cannot get it to work?

> I searched my test sandbox schema (TGW7078) for the string 'C93A'. Using the modified procedure I posted, I find 22 tables:

> 22 tables found.
> 
> PL/SQL procedure successfully completed.
> 
> Time End: 4/18/2017 12:31:39 PM
> 
> Elapsed Time for Script Execution: 19 secs

> However, after substituting the schema and search term into your procedure, e.g.:

> declare
> 
> l\_column\_name varchar2(128);
> 
> l\_count integer := 0;
> 
> l\_search\_string varchar2(100) := 'C93A';
> 
> l\_schema varchar2(100) := 'TGW7078';
> 
> etc.

> I get this return result:

> Time Start: 4/18/2017 12:35:30 PM
> 
> Searching for tables in TGW7078 with columns named: C93A
> 
> Total Tables found: 0
> 
> PL/SQL procedure successfully completed.
> 
> Time End: 4/18/2017 12:35:31 PM
> 
> Elapsed Time for Script Execution: 807 msecs

> I am not skilled enough at PL/SQL, at this point, to do effective troubleshooting. Any ideas?

> 

> Thanks,

> Tom

> To reply, please reply-all to this email.
> 
> [Stop receiving emails](http://www.toadworld.com/products/toad-for-oracle/f/10/t/32448?subscribe=false) on this subject.
> 
> Or [Unsubscribe from Toad for Oracle Forum](http://www.toadworld.com/products/toad-for-oracle/f/10?subscribe=false) notifications altogether.
> 
> Toad for Oracle - Discussion Forum

> [Flag](http://www.toadworld.com/products/toad-for-oracle/f/10/p/32448/65442?AbuseContentId=cc70944a-70a8-4da2-8112-836a4c1888dc&AbuseContentTypeId=f586769b-0822-468a-b7f3-a94d480ed9b0&AbuseFlag=true) this post as spam/abuse.

---

<div class="post-metadata">

**Author:** ![tom.wickerath](https://avatars.discourse-cdn.com/v4/letter/t/bb73d2/32.png) [@tom.wickerath](https://forums.toadworld.com/u/tom.wickerath)\
**Post date:** [April 18, 2017, 12:48pm UTC](https://forums.toadworld.com/t/line-numbers-for-pl-sql-code/39345/9 "2017-04-18T12:48:38Z")

</div>

Okay, it looks like your search is designed to consider column names, with data types in (‘CHAR’, ‘NVARCHAR2’, ‘VARCHAR2’). I just happened to test it with a numeric column above (ap\_entry\_id).

I just changed my search to use a varchar2 column, airplanenbr. It kind of works, but it only found three tables before encountering an ORA-01422 error:

Time Start: 4/18/2017 12:44:56 PM  
Searching for tables in TGW7078 with columns named: airplanenbr  
VC\_EQUIPMENTINSTANCESHAPE - AIRPLANENBR  
VC\_CONNECTORS - AIRPLANENBR  
VC\_CONNECTORINSTANCESHAPE - AIRPLANENBR  
ORA-01422: exact fetch returns more than requested number of rows  
PL/SQL procedure successfully completed.  
Time End: 4/18/2017 12:44:57 PM  
Elapsed Time for Script Execution: 1 sec

In any case, my need is for searching for where data occurs in this database of approx. 280 tables, with each table having many many columns.

---

<div class="post-metadata">

**Author:** ![tom.wickerath](https://avatars.discourse-cdn.com/v4/letter/t/bb73d2/32.png) [@tom.wickerath](https://forums.toadworld.com/u/tom.wickerath)\
**Post date:** [April 18, 2017, 12:50pm UTC](https://forums.toadworld.com/t/line-numbers-for-pl-sql-code/39345/10 "2017-04-18T12:50:43Z")

</div>

> Just clicking on the line will (should) take you to that line in the editor.

Is there an option in TOAD that we need to enable, to get this to work?

---

<div class="post-metadata">

**Author:** ![GTDG](https://sea1.discourse-cdn.com/quest/user_avatar/forums.toadworld.com/gtdg/32/140_2.png) [@GTDG](https://forums.toadworld.com/u/GTDG)\
**Post date:** [April 18, 2017, 12:54pm UTC](https://forums.toadworld.com/t/line-numbers-for-pl-sql-code/39345/11 "2017-04-18T12:54:07Z")

</div>

![7534.DBStuff.jpeg](https://global.discourse-cdn.com/quest/original/2X/7/7e0aba3799b5a2c50ebed470c7288b327957f9e9.jpeg)

---

<div class="post-metadata">

**Author:** ![tom.wickerath](https://avatars.discourse-cdn.com/v4/letter/t/bb73d2/32.png) [@tom.wickerath](https://forums.toadworld.com/u/tom.wickerath)\
**Post date:** [April 18, 2017, 1:02pm UTC](https://forums.toadworld.com/t/line-numbers-for-pl-sql-code/39345/12 "2017-04-18T13:02:04Z")

</div>

Love the image. It’s a keeper!

What is the trick to attaching an image to a reply in this forum?

---

<div class="post-metadata">

**Author:** ![GTDG](https://sea1.discourse-cdn.com/quest/user_avatar/forums.toadworld.com/gtdg/32/140_2.png) [@GTDG](https://forums.toadworld.com/u/GTDG)\
**Post date:** [April 18, 2017, 1:06pm UTC](https://forums.toadworld.com/t/line-numbers-for-pl-sql-code/39345/13 "2017-04-18T13:06:05Z")

</div>

From the web page, you can drag an image onto the edit window or for attachments (zips, ...), above the edit window, you see Compose Options Preview. Click Options and you can attach files.

> On Apr 18, 2017, at 4:02 PM, tom.wickerath [bounce-tomwickerath@toadworld.com](mailto:bounce-tomwickerath@toadworld.com) wrote:

> **[RE: Line Numbers for PL/SQL code](http://www.toadworld.com/products/toad-for-oracle/f/10/p/32448/65448#65448)**

> Reply by tom.wickerath  
> What is the trick to attaching an image to a reply in this forum?

> To reply, please reply-all to this email.
> 
> [Stop receiving emails](http://www.toadworld.com/products/toad-for-oracle/f/10/t/32448?subscribe=false) on this subject.
> 
> Or [Unsubscribe from Toad for Oracle Forum](http://www.toadworld.com/products/toad-for-oracle/f/10?subscribe=false) notifications altogether.
> 
> Toad for Oracle - Discussion Forum

> [Flag](http://www.toadworld.com/products/toad-for-oracle/f/10/p/32448/65448?AbuseContentId=727def4f-e573-42a8-a65d-858a3236524e&AbuseContentTypeId=f586769b-0822-468a-b7f3-a94d480ed9b0&AbuseFlag=true) this post as spam/abuse.

---

<div class="post-metadata">

**Author:** ![tom.wickerath](https://avatars.discourse-cdn.com/v4/letter/t/bb73d2/32.png) [@tom.wickerath](https://forums.toadworld.com/u/tom.wickerath)\
**Post date:** [April 18, 2017, 1:17pm UTC](https://forums.toadworld.com/t/line-numbers-for-pl-sql-code/39345/14 "2017-04-18T13:17:13Z")

</div>

Hi Norm,

> The 'and rownum = 1' is saying, only give me the first row.

But I am looking for additional columns in the table, not rows. I just tried commenting out the "and rownum=1';" part, to see if the code would tell me more than one column in the same table that has the same data. It does not. It still only found the first column.

open l\_cursor for 'select ' || l\_cols || 'else null end cname from ' ||

x.table\_name || l\_where || ')'; -- and rownum=1';

-- x.table\_name || l\_where || ') and rownum=1';

fetch l\_cursor into l\_cname;

---

<div class="post-metadata">

**Author:** ![NormTeamT](https://sea1.discourse-cdn.com/quest/user_avatar/forums.toadworld.com/normteamt/32/53_2.png) [@NormTeamT](https://forums.toadworld.com/u/NormTeamT)\
**Post date:** [April 18, 2017, 2:34pm UTC](https://forums.toadworld.com/t/line-numbers-for-pl-sql-code/39345/15 "2017-04-18T14:34:21Z")

</div>

Duh! Silly me. I must learn to read! Apologies.

I think the open cursor, fetch, if found, close cursor is why.

I’ll explain.

You open the cursor and fetch a row. If a tow was fetched, you print out the details, however, you then close the cursor. So you only print the first results. What you need to do is loop around fetching rows from the cursor until %not found, at which point you would exit the loop and then close the cursor. Something like…

Open l\_cursor …

Loop

Fetch l\_cursor into …

Exit when l\_cursor%notfound;

Dbms\_output the details here.

End loop;

Close l\_cursor;

There’s an example at [docs.oracle.com/…/sqloperations.htm](https://docs.oracle.com/cd/B19306_01/appdev.102/b14261/sqloperations.htm#BABCFDJE) that might help.

---

<div class="post-metadata">

**Author:** ![tom.wickerath](https://avatars.discourse-cdn.com/v4/letter/t/bb73d2/32.png) [@tom.wickerath](https://forums.toadworld.com/u/tom.wickerath)\
**Post date:** [April 18, 2017, 2:43pm UTC](https://forums.toadworld.com/t/line-numbers-for-pl-sql-code/39345/16 "2017-04-18T14:43:43Z")

</div>

Hi Gregory,

> From the web page, you can drag an image onto the edit window or for attachments (zips, ...), above the edit window, you see Compose Options Preview. Click Options and you can attach files.

Okay, it looks like that works. Here is the image I tried to include earlier. When I double-click on the selected line shown above, or right-click it, nothing happens. Is there an option that needs to be enabled to make this work? I am using TOAD for Oracle, version 12.10.0.30.

Thank You,

Tom

---

<div class="post-metadata">

**Author:** ![tom.wickerath](https://avatars.discourse-cdn.com/v4/letter/t/bb73d2/32.png) [@tom.wickerath](https://forums.toadworld.com/u/tom.wickerath)\
**Post date:** [April 18, 2017, 3:36pm UTC](https://forums.toadworld.com/t/line-numbers-for-pl-sql-code/39345/17 "2017-04-18T15:36:38Z")

</div>

Hi Norm,

I forgot to reply to this part of your answer earlier:

> You don't need to upper case the table name. You can use the table name returned from all/user\_tables as is, when looking for columns, as it is already correct.

Really? If I run this query I get 102 rows returned:

select \* from user\_tab\_columns where table\_name = 'AWSM\_TLK\_AIRPLANE';

However, if I run this query, I get zero rows returned:

select \* from user\_tab\_columns where table\_name = 'awsm\_tlk\_airplane';

> Using upper() will stop oracle from using an index, if there is one, on table\_name, in all/user\_tab\_columns.

user\_tab\_columns is a view that uses a different view, user\_tab\_cols, as its source of data. However, upon using describe user\_tab\_cols, I see a fairly complicated query that includes several dependencies:

-- Dependencies:  
-- TAB$ (Table)  
-- OBJ$ (Table)  
-- "\_BASE\_USER" (View)  
-- COLTYPE$ (Table)  
-- ATTRCOL$ (Table)  
-- HIST\_HEAD$ (Table)  
-- COL$ (Table)  
-- "\_CURRENT\_EDITION\_OBJ" (View)

The only reference I see to "TABLE\_NAME" in this view is as a comment.

So, I do not know yet whether or not this system view has an index on the TABLE\_NAME column.

Tom

---

<div class="post-metadata">

**Author:** ![tom.wickerath](https://avatars.discourse-cdn.com/v4/letter/t/bb73d2/32.png) [@tom.wickerath](https://forums.toadworld.com/u/tom.wickerath)\
**Post date:** [April 18, 2017, 4:23pm UTC](https://forums.toadworld.com/t/line-numbers-for-pl-sql-code/39345/18 "2017-04-18T16:23:05Z")

</div>

Hi Norm,

I tried adding the Loop / End loop and Exit when l\_cursor%notfound; statements, but I’m still getting the same results–the code does not find a second column in the same table, with the same search term:

open l\_cursor for 'select ’ || l\_cols || 'else null end cname from ’ ||  
x.table\_name || l\_where || ‘) and rownum=1’;  
Loop  
fetch l\_cursor into l\_cname;  
Exit when l\_cursor%notfound;  
if ( l\_cursor%found ) then  
i\_count:=i\_count + 1;

```
       dbms_output.put_line(x.table_name || chr(9) || chr(9) || l_cname );
       dbms_output.put_line('select * from ' || x.table_name || ' where ' || l_cname || ' like ''%' || p_string || '%'';');
       dbms_output.put_line(' ');    
  end if;

```

End loop;  
close l\_cursor;  
end loop;

I also tried moving the Loop statement to happen before the open l\_cursor statement.

Loop  
open l\_cursor for 'select ’ || l\_cols || 'else null end cname from ’ ||  
x.table\_name || l\_where || ‘) and rownum=1’;  
fetch l\_cursor into l\_cname;  
:  
:

The procedure runs for several minutes, then craps out with an overflow:

Error at line 36  
ORA-20000: ORU-10027: buffer overflow, limit of 1000000 bytes  
ORA-06512: at “SYS.DBMS\_OUTPUT”, line 32  
ORA-06512: at “SYS.DBMS\_OUTPUT”, line 97  
ORA-06512: at “SYS.DBMS\_OUTPUT”, line 112  
ORA-06512: at line 52

I’d really like to get this procedure modified, so that it does not stop searching for additional columns in a table, once a match has been found.

Thank You,

Tom

---

<div class="post-metadata">

**Author:** ![GTDG](https://sea1.discourse-cdn.com/quest/user_avatar/forums.toadworld.com/gtdg/32/140_2.png) [@GTDG](https://forums.toadworld.com/u/GTDG)\
**Post date:** [April 18, 2017, 5:37pm UTC](https://forums.toadworld.com/t/line-numbers-for-pl-sql-code/39345/19 "2017-04-18T17:37:00Z")

</div>

It should just be a single click. No double or right involved.

On Apr 18, 2017, at 5:44 PM, tom.wickerath [bounce-tomwickerath@toadworld.com](mailto:bounce-tomwickerath@toadworld.com) wrote:

> **[RE: Line Numbers for PL/SQL code](http://www.toadworld.com/products/toad-for-oracle/f/10/p/32448/65454#65454)**

> Reply by tom.wickerath

> Hi Gregory,

> > From the web page, you can drag an image onto the edit window or for attachments (zips, ...), above the edit window, you see Compose Options Preview. Click Options and you can attach files.

> Okay, it looks like that works. Here is the image I tried to include earlier. When I double-click on the selected line shown above, or right-click it, nothing happens. Is there an option that needs to be enabled to make this work? I am using TOAD for Oracle, version 12.10.0.30.

> Thank You,

> Tom

> To reply, please reply-all to this email.
> 
> [Stop receiving emails](http://www.toadworld.com/products/toad-for-oracle/f/10/t/32448?subscribe=false) on this subject.
> 
> Or [  
> Unsubscribe from Toad for Oracle Forum](http://www.toadworld.com/products/toad-for-oracle/f/10?subscribe=false) notifications altogether.
> 
> Toad for Oracle - Discussion Forum

> [Flag](http://www.toadworld.com/products/toad-for-oracle/f/10/p/32448/65454?AbuseContentId=05ad32bf-523a-4769-8e50-b7ec46c8d5ef&AbuseContentTypeId=f586769b-0822-468a-b7f3-a94d480ed9b0&AbuseFlag=true)  
> this post as spam/abuse.

---

<div class="post-metadata">

**Author:** ![tom.wickerath](https://avatars.discourse-cdn.com/v4/letter/t/bb73d2/32.png) [@tom.wickerath](https://forums.toadworld.com/u/tom.wickerath)\
**Post date:** [April 18, 2017, 5:51pm UTC](https://forums.toadworld.com/t/line-numbers-for-pl-sql-code/39345/20 "2017-04-18T17:51:39Z")

</div>

Hi Gregory,

> It should just be a single click. No double or right involved.

The only thing I see with a single click is a tool-tip like window, which shows the error message along with the first several lines of code. It definitely is not jumping to the offending line of code for me. This is why I ask if there is an option I need to enable.

I can arrange a WebEx meeting with you, so that you can see my screen, if you think that would be helpful. This is a nagging problem for me. It does not make it easy to use TOAD....

Thank You,

Tom

[Next page](https://forums.toadworld.com/t/line-numbers-for-pl-sql-code/39345.md?page=2)
