Line Numbers for PL/SQL code

Tom,

What you're seeing is due to the AB being treated as a "single line" by Oracle. When we execute an AB, Oracle sees it as a single statement so when the error comes back, even though Oracle has listed out where the issue is, "where" the error occurs is on the first line of the AB. When you click on the error, you'll see the first line (Declare) highlighted. If you were to click somewhere else in the AB and click on the error again, it will take you back to the top. Unfortunately, ABs are a weird item and and because they're treated as single statements by Oracle, we have to do the same making it very difficult to debug.

AB.jpeg

Something that could speed up your debugging also comes from Oracle. If you look in the error message, they tell you where in the AB the error occurs. Use the keyboard shortcut and type in the line number to take you to that line in the code. Hopefully that helps.

If I get errors when running anonymous blocks, I will generally move them so they start on line 1 so I can better find the line number of the error. It is easier than taking the time to figure out that because my block starts on line 32 and the error is on line 49, I need to look at line 81 to see what is going on. :slight_smile: Now if Toad was to do that for me. . .

Of course, I also rarely use ABs. I have found that one-time code almost always needs to be reused, so I use packages (mostly) or stored procedures for almost everything I write.

On Fri, Apr 21, 2017 at 9:04 AM, Gregory Liss bounce-GTDG@toadworld.com wrote:

RE: Line Numbers for PL/SQL code

Reply by Gregory Liss
Tom,

What you're seeing is due to the AB being treated as a "single line" by Oracle. When we execute an AB, Oracle sees it as a single statement so when the error comes back, even though Oracle has listed out where the issue is, "where" the error occurs is on the first line of the AB. When you click on the error, you'll see the first line (Declare) highlighted. If you were to click somewhere else in the AB and click on the error again, it will take you back to the top. Unfortunately, ABs are a weird item and and because they're treated as single statements by Oracle, we have to do the same making it very difficult to debug.

Something that could speed up your debugging also comes from Oracle. If you look in the error message, they tell you where in the AB the error occurs. Use the keyboard shortcut and type in the line number to take you to that line in the code. Hopefully that helps.

To reply, please reply-all to this email.

Stop receiving emails on this subject.

Or Unsubscribe from Toad for Oracle Forum notifications altogether.

Toad for Oracle - Discussion Forum

Flag this post as spam/abuse.

--
Phyllis Helton

Data Magician

Security Gestapo
Digital Products & Strategies, Cru | Data Sciences & Analytics
Office :phone: 407-515-4452

phyllis.helton@cru.org

Hi Phylis,

This is the same reason that I have a package in a couple of databases, named PK_ONE_OFFS!!! [*-)]

Cheers.

HA! Our entire IT Department needs a severe talking to.

But that’s about as fun as a dog would have chasing parked cars!!

Our “usual” change control process just changed significantly, for the worse, this past January.

Oh well…

From: Norm [TeamT] [mailto:bounce-NormTeamT@toadworld.com]

Sent: Friday, April 21, 2017 4:57 AM

To: toadoracle@toadworld.com

Subject: RE: [Toad for Oracle - Discussion Forum] Line Numbers for PL/SQL code

RE: Line Numbers for PL/SQL code

Reply by Norm [TeamT]

Hi Tom,

your IT person needs a sever talking to, s/he is obstruction your ability to do work by the sound of things. However…

You have the ability to create a package in your sandbox I see. Once you have demonstrated that it is ok, and not virus/trojan ridden or likely to do harm to production etc, you can request that it be applied to production via the usual change control procedures. Good luck!

To reply, please reply-all to this email.

Stop receiving emails on this subject.

Or
Unsubscribe from Toad for Oracle Forum
notifications altogether.

Toad for Oracle - Discussion Forum

Flag
this post as spam/abuse.

In response to: Norm [TeamT] / 21 Apr 2017 at 12:01pm

The flogging will continue until…… [:D]

Have a nice weekend, and Thank You so much for all your help.

Tom

From: Norm [TeamT] [mailto:bounce-NormTeamT@toadworld.com]
Sent: Friday, April 21, 2017 5:03 AM
To: toadoracle@toadworld.com
Subject: RE: [Toad for Oracle - Discussion Forum] Line Numbers for PL/SQL code

RE: Line Numbers for PL/SQL code

Reply by Norm [TeamT]

Hi Tom,

You said:

Okay, but this is NOT the first point you made about the use of the UPPER() function. If you refer back to your earlier reply, Norm [TeamT] / 18 Apr 2017 at 8:01am, you wrote:

“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.”

In fact, you didn’t even use the word error or imply incorrect result. While I say “Thank You” for this correction to Mr. Kyte’s code, I think you could have said something like "gee, I missed an important point earlier…The use or not of UPPER() is not meant to save time, it’s meant to be correct because…

You’ll have to forgive me, English isn’t my first language, I’m Scottish!

However, your observation is correct, I didn’t mention that the use of UPPER() as supplied by Tom K, would result in incorrect results if and only if, your friendly local “low-life” has indeed created tables with lower or mixed case names. I forgot that after my mini-rant on the use of UPPER() causing any existing indexes on the NAME column from being used in the query.

I sit corrected. :wink:

Cheers.

To reply, please reply-all to this email.

Stop receiving emails on this subject.
Or Unsubscribe from Toad for Oracle Forum notifications altogether.
Toad for Oracle - Discussion Forum

Flag this post as spam/abuse.

Hi Phyllis,

It is easier than taking the time to figure out that because my block starts on line 32 and the error is on line 49, I need to look at line 81 to see what is going on. :slight_smile:

I agree. But, I have also found that often times even when I do add the values, as you show, the error could not have possibly occurred on the indicated line (81 in your example). That’s why it is soooooo confusing me, as a PL/SQL and Oracle newbie.

Now if Toad was to do that for me. . .

That is the crux of my request for version next of TOAD!

Cheers,

Tom

From: phyllis.helton_1150 [mailto:bounce-phyllishelton_1150@toadworld.com]

Sent: Friday, April 21, 2017 6:50 AM

To: toadoracle@toadworld.com

Subject: RE: [Toad for Oracle - Discussion Forum] Line Numbers for PL/SQL code

RE: Line Numbers for PL/SQL code

Reply by phyllis.helton_1150

If I get errors when running anonymous blocks, I will generally move them so they start on line 1 so I can better find the line number of the error. It is easier than taking the time to figure out that because my block starts on line 32 and the error is on line 49, I need to look at line 81 to see what is going on. :slight_smile: Now if Toad was to do that for me. . .

Of course, I also rarely use ABs. I have found that one-time code almost always needs to be reused, so I use packages (mostly) or stored procedures for almost everything I write.

To reply, please reply-all to this email.

Stop receiving emails on this subject.

Or
Unsubscribe from Toad for Oracle Forum
notifications altogether.

Toad for Oracle - Discussion Forum

Flag
this post as spam/abuse.

Hi Gregory,

In reply to: Gregory Liss / 21 Apr 2017 at 1:03pm

I’m not sure I follow you, but it is entirely possible that I’m just SOL, because this is an AB (Anonymous Block) of code.

I just intentionally generated an error with the AB procedure based on Tom Kyte’s code (sans the UPPER function, thanks Norm). As you can see, Oracle is telling me the error occurs on Line 44, which is part of the Declare section in my AB (it is certainly near the beginning of the AB, but I’m not sure I can call this the first line…):

My comments include 34 lines at the beginning, with some blank lines interspersed for readability. If I add (44 + 34) = 78, and look in that area, I see the following:

……which doesn’t seem to provide information that helps (at least to me).

Tom

PS. I am using the Reply All feature from Outlook, which seems to be a lot easier than editing content via the web page. However, I noticed the other day that two images I attached as .png files did not display in the web page. I then switched to .jpg, and the images displayed okay. Is there any restriction against the use of the *.png (Portable Networks Graphics) file format? This is the format that I usually use with TechSmith’s Snag-It software.

From: Gregory Liss [mailto:bounce-GTDG@toadworld.com]
Sent: Friday, April 21, 2017 6:04 AM
To: toadoracle@toadworld.com
Subject: RE: [Toad for Oracle - Discussion Forum] Line Numbers for PL/SQL code

RE: Line Numbers for PL/SQL code

Reply by Gregory Liss

Tom,

What you’re seeing is due to the AB [Anonymous Block] being treated as a “single line” by Oracle. When we execute an AB, Oracle sees it as a single statement so when the error comes back, even though Oracle has listed out where the issue is, “where” the error occurs is on the first line of the AB. When you click on the error, you’ll see the first line (Declare) highlighted. If you were to click somewhere else in the AB and click on the error again, it will take you back to the top. Unfortunately, ABs are a weird item and and because they’re treated as single statements by Oracle, we have to do the same making it very difficult to debug.

Something that could speed up your debugging also comes from Oracle. If you look in the error message, they tell you where in the AB the error occurs. Use the keyboard shortcut and type in the line number to take you to that line in the code. Hopefully that helps.

To reply, please reply-all to this email.

Stop receiving emails on this subject.
Or Unsubscribe from Toad for Oracle Forum notifications altogether.
Toad for Oracle - Discussion Forum

Flag this post as spam/abuse.

This “one-off” procedure has already been used several times in the past month!

I also wanted another Tom Kyte procedure added, to reset sequence values without dropping and re-creating the sequence. We are still on 11gR2, and sometimes it is just nice, although not necessary, to start the counter over when you are truncating a logging-type table (for example, a stand-alone table, with no relationships established to other tables).

I think I need to simply wait for the IT person who tells me to run the search code as an anonymous block to retire. Then, I will try again to get it implemented, if I do not retire first!

Tom

From: Norm [TeamT] [mailto:bounce-NormTeamT@toadworld.com]

Sent: Friday, April 21, 2017 4:57 AM

To: toadoracle@toadworld.com

Subject: RE: [Toad for Oracle - Discussion Forum] Line Numbers for PL/SQL code

RE: Line Numbers for PL/SQL code

Reply by Norm [TeamT]

Hi Tom,

your IT person needs a sever talking to, s/he is obstruction your ability to do work by the sound of things. However…

You have the ability to create a package in your sandbox I see. Once you have demonstrated that it is ok, and not virus/trojan ridden or likely to do harm to production etc, you can request that it be applied to production via the usual change control procedures. Good luck!

To reply, please reply-all to this email.

Stop receiving emails on this subject.

Or
Unsubscribe from Toad for Oracle Forum
notifications altogether.

Toad for Oracle - Discussion Forum

Flag
this post as spam/abuse.

Hi Norm,

In reply to: Norm [TeamT] wrote the following post at 21 Apr 2017 11:53 AM:

That was it…you nailed it! There was no query, just a partial listing of columns. I changed vSQL to Clob, [you even left a comment in there “Change the size if something barfs!”, which I had not noticed earlier].

For ‘H91A’, in my test sandbox environment, your code found (14) places. By comparison, the modified Tom Kyte Anonymous Block code, which I already had determined was not looking for additional columns in a table once a match was found, located (11) tables. Of the (14) results your code located, three tables had two columns each with the same data. As you can see, Norm, there are NormALIZATION issues that we deal with. Sorry, that stupid pun just came to mind! [H]

A few more questions, if I may…

  1. In debug mode for your NormSearch procedure, what determines the order that the columns were printed (and presumably interrogated in the database)? It was neither alphabetical nor by ordinal number.
  2. Is there an easy way to add a comment to the end of the query string that indicates the ordinal position for the column? For example:
    select * from “TGW7078”.“AW_WORK_STATEMENT_AIRPLANE” where “TPRN_COMMENTS” like ‘%H91A%’; – Column 49
    select * from “TGW7078”.“AW_WORK_STATEMENT_AIRPLANE” where “WORK_STATEMENT” like ‘%H91A%’; – Column 7

Now, if I can just convince the IT Powers-to-be, at this little airplane company, that a “one-offs” collection of procedures in production would be useful to us…

Tom

Hi Tom,

I don’t mind further questions, I was a beginner once too and people helped me - it’s payback time!

Q1. The order of printing to columns is determined by Oracle. The query against ALL_TAB_COLUMNS that pulls out the columns that are character based, gets the columns back in the order that they are stored in, which is not necessarily the same order that they were created in and is highly unlikely to be sorted as the query doesn’t specify a sort.

In relational databases, the internal workings are also done in a relational manner. So nothing is sorted unless specifically requested. Also, if you insert a few rows, then delete one, then insert a further row, it may or may not be stored in the space where the row was deleted from. If it was, then your SELECT (without an ORDER BY) will return them with the most recently added row in amongst the others that were inserted first.

The columns printed by the debugging are printed in that order, the order that Oracle gives me them.

Q2. Interesting, and I can see how it would be useful. The easy answer is no, there’s no easy way. I suspect it might be able to be done with an INSTR() but that doesn’t take wildcard parameters, so your search with “TPRN_COMMENTS” like ‘%H91A%’, for example, cannot be INSTRd as the leading wildcard means that the “found” position will always be at the start - the columns contains a random number of characters, then H91A, then some more characters. Where is the start? You could I suppose change the generated query to be INSTR(TPRN_COMENTS, ‘H91A’) which would give you a starting position.

Who knows, maybe Oracle internally uses INSTR() calls to facilitate LIKE queries? And simply takes the result as a yes or no in deciding whether or not the column does contain the search text.

And finally, normalisation. I feel your pain. I have yet to come across a database that has been properly normalised in all of 30 plus years in IT.

Have a good weekend.

Hi Norm,

Last week, I reported success with your Normsearch package in my test sandbox environment. I found more occurrences of a search term versus the modified Tom Kyte procedure run as an Anonymous Block.

Today, I tried creating the same package in our lower “DEV” environment. It compiles fine, yet when I try to run it in this environment, I get an Invalid Relational Operator error:

InvalidRelationalOperator.jpeg

I get this error with any search term, in this environment, for example ‘ZA005’ or ‘H91B’. I have tried running with the Debug option, but the code is bombing out before any output is printed.

I tried looking up this error on the TechOnTheNet.com site:

https://www.techonthenet.com/oracle/errors/ora00920.php

It includes “You tried to execute a SQL statement, but the WHERE clause contained an invalid relational operator.”

Any idea why the package compiles fine in both environments (my test sandbox and DEV), but only runs okay in my test sandbox? I note that I have two additional privileges in my test sandbox versus DEV. Could this be the cause of the error?

Sandbox Test Environment
DEV Environment with ORA00920 Error
PRIVILEGE
PRIVILEGE
CREATE CLUSTER
CREATE CLUSTER
CREATE DATABASE LINK
CREATE DATABASE LINK
CREATE INDEXTYPE
CREATE INDEXTYPE
CREATE JOB
CREATE MATERIALIZED VIEW
CREATE MATERIALIZED VIEW
CREATE OPERATOR
CREATE OPERATOR
CREATE PROCEDURE
CREATE PROCEDURE
CREATE SEQUENCE
CREATE SEQUENCE
CREATE SESSION
CREATE SESSION
CREATE SYNONYM
CREATE SYNONYM
CREATE TABLE
CREATE TABLE
CREATE TRIGGER
CREATE TRIGGER
CREATE VIEW
CREATE TYPE
DEBUG ANY PROCEDURE
CREATE VIEW
DEBUG CONNECT SESSION
DEBUG ANY PROCEDURE
DEBUG CONNECT SESSION
SQL Statement
select * from session_privs order by privilege;

The more I look at this, I’m thinking I need the session priv. CREATE TYPE. It looks like the code is trying to do that at run-time, which I think explains why the code compiles, but then has a run-time issue:

CREATE OR REPLACE PACKAGE APDBMS_SOR.normSearch as
– Pipelined functions need a table type to return results.
type tSqlStatement is table of varchar2(1024);

Thank You,

Tom

Try running it with debug set to y and see what query is being generated. That might give a clue.

Cheers,

Norm. [ TeamT ]

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

Hi Tom,

it seems that when I get an email from ToadWorld, some of it is missing. I hadn’t seen your questions etc after the line that mentions the WHERE clause. Strange!

Anyway, your CREATE TYPE allows you to execute the command CREATE TYPE while in your sandbox, this is not the same as defining a type in PL/SQL, so it is not going to be relevant.

The error mentions the WHERE clause, as you pointed out, so that’s WHERE we need to be looking. (Pun intended!) Once you run the code with debugging on, you will be able to see the table and columns it is processing, as well as the query it generated. I suspect that if you copy and paste the query into a Toad editor, logged in as the same user, than you may well see what’s wrong if you F9 it.

Use the “format code” button in the editor when you have selected the code just pasted, to format it into something nice.

Cheers,

Norm.

Hi Norm,

Try running it with debug set to y and see what query is being generated. That might give a clue.

I thought I had tried running it in debug mode before, without seeing anything, but I tried again this morning. It appears as if the code bombs out on a table in our DEV environment that I do not have in my test sandbox environment. Earlier, on 4/21, while discussing my modified Tom Kyte code run as an anonymous block, you made the comment:

“However, your observation is correct, I didn't mention that the use of UPPER() as supplied by Tom K, would result in incorrect results if and only if, your friendly local "low-life" has indeed created tables with lower or mixed case names.”

I think the new errors I am experiencing in our DEV environment might be a gift from our friendly local “low-life”!

To recap, the errors I observed in DEV, but not in my test sandbox, include the following:

ORA-00920: invalid relational operator

ORA-06512: at "APDBMS_SOR.NORMSEARCH", line 129

ORA-06512: at line 1

I copied the SQL statement that was generated, and formatted it. The first error I observed is located here:

Not only are there mixed case column names, but this particular column includes a damn space! Who does *&^%$# like that these days?

After fixing this error, I started getting new errors on every column that included mixed case. I can fix them one-by-one, by adding double quotes.

My question: Is your Normsearch procedure tolerant of the lack of proper naming conventions from friendly local low-lifes? My guess is that it may not have protections for what some idiots can do when naming columns and tables.

Thank You,

Tom

From: Norm [TeamT] [mailto:bounce-NormTeamT@toadworld.com]
Sent: Wednesday, April 26, 2017 1:36 AM
To: toadoracle@toadworld.com
Subject: RE: [Toad for Oracle - Discussion Forum] Line Numbers for PL/SQL code

RE: Line Numbers for PL/SQL code

Reply by Norm [TeamT]

Try running it with debug set to y and see what query is being generated. That might give a clue.

Cheers,
Norm. [ TeamT ]

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

To reply, please reply-all to this email.

Stop receiving emails on this subject.
Or Unsubscribe from Toad for Oracle Forum notifications altogether.
Toad for Oracle - Discussion Forum

Flag this post as spam/abuse.

Evening Tom,

Looks like your local low-life has gone “below and beyond” anything I’ve ever seen or come across before, spaces in a table name, sheesh! (Insert unprintable profanity here!)

Regarding the code, I thought I’d already double quoted all the column names, but I obviously had not. A quick fix:

Change these lines, just after the select from all_tab_columns, …

loop

vColumns := vColumns || ’ when ’ || y.column_name ||

q’< like sys_context(‘userenv’,‘client_info’) then >’ ||

To the following. I haven’t been able to test this, I’m away from my work, desk, pc and I’m actually in bed! So please test yourself…

loop

vColumns := vColumns || ’ when "’ || y.column_name ||

q’<" like sys_context(‘userenv’,‘client_info’) then ">’ ||

I’ve added a double quote just after ‘when’ and before the single quote, as well as adding one just after the text “q’’<” at the start of the second line plus another at the end of that line, nearly. That should wrap the column names correctly with no additional spaces.

HTH.

Sorry, ignore the double quote added at the end of the second line of the loop, it’s already there in the lines I didn’t copy and paste. There should not a a double quote before the text >’ ||.

Hi Norm,

I think I got your recommended changes added correctly. I ended up with this:

        loop



            vColumns := vColumns ||

’ when "’
|| y.column_name ||

         -- vColumns := vColumns || ' when ' || y.column_name ||

         -- q'< like sys_context('userenv','client_info') then >' ||

            q'<" like sys_context('userenv','client_info') then >'

||

            q'< '>'

|| y.column_name ||
q’<’>’;

            vWhereClause := vWhereClause ||

’ or ’
|| y.column_name ||

                            q'< like sys_context('userenv','client_info') >';

           

            if

(vDebug)
then

                ***dbms_output.put_line***('    COLUMN: '

|| y.column_name);

            end

if;

        end

loop;

However, the script failed in my test sandbox environment, which includes a new table that only a low-life would appreciate. Here is a quickie script to create this table and insert one row:

CREATE
TABLE
“Mixed Case Madness”

(

 PROGRAM                          VARCHAR2(50

BYTE),

 "PROgramTest"                    VARCHAR2(50

BYTE),

 "Comments WITH fugly spaces"

VARCHAR2(50
BYTE)

);

insert
into
“Mixed Case Madness”

(PROGRAM,
“PROgramTest”,
“Comments WITH fugly spaces”)

values
(‘Hickory’,
‘Dickery’,
‘Dock’);

commit;

select
*
from
“Mixed Case Madness”;

select
*
from
table(normSearch.textSearch(‘TGW7078’,
‘Dock’,
pDEBUG=>‘Y’));

– drop table “Mixed Case Madness” purge;

The output of running a search with the debug switch looks like that shown below.

It looks like the column names are properly quoted in the SELECT clause, but the table name and the columns are not properly quoted in the FROM or WHERE clauses:

After adding the indicated double quotes, this query runs correctly:

Tom

From: Norm [TeamT] [mailto:bounce-NormTeamT@toadworld.com]

Sent: Wednesday, April 26, 2017 2:06 PM

To: toadoracle@toadworld.com

Subject: RE: [Toad for Oracle - Discussion Forum] Line Numbers for PL/SQL code

RE: Line Numbers for PL/SQL code

Reply by Norm [TeamT]

Sorry, ignore the double quote added at the end of the second line of the loop, it’s already there in the lines I didn’t copy and paste. There should not a a double quote before the text >’ ||.

To reply, please reply-all to this email.

Stop receiving emails on this subject.

Or
Unsubscribe from Toad for Oracle Forum
notifications altogether.

Toad for Oracle - Discussion Forum

Flag
this post as spam/abuse.

I think I got it now, using the clues you provided earlier! Yahoo!!

I changed this line in the “Build the SQL” section:

         -- Build the SQL...

        vSQL :=

'select distinct ’
|| vColumns ||

                 ' else null end cname from '

|| vOwner ||
‘."’
||

                x.table_name ||

‘"’
|| vWhereClause ||
‘)’;

– vSQL := 'select distinct ’ || vColumns ||

– ’ else null end cname from ’ || vOwner || ‘.’ ||

– x.table_name || vWhereClause || ‘)’;

And this line, in the loop that builds the vWhereClause statement:

            vWhereClause := vWhereClause ||

’ or “’
|| y.column_name ||
'”’
||

                            q'< like sys_context('userenv','client_info') >';

– vWhereClause := vWhereClause || ’ or ’ || y.column_name ||

– q’< like sys_context(‘userenv’,‘client_info’) >’;

In limited initial testing, it seems to work. My new “Mixed Case Madness” table did not upset the apple cart.

Tom

From: Norm [TeamT] [mailto:bounce-NormTeamT@toadworld.com]

Sent: Wednesday, April 26, 2017 2:06 PM

To: toadoracle@toadworld.com

Subject: RE: [Toad for Oracle - Discussion Forum] Line Numbers for PL/SQL code

RE: Line Numbers for PL/SQL code

Reply by Norm [TeamT]

Sorry, ignore the double quote added at the end of the second line of the loop, it’s already there in the lines I didn’t copy and paste. There should not a a double quote before the text >’ ||.

To reply, please reply-all to this email.

Stop receiving emails on this subject.

Or
Unsubscribe from Toad for Oracle Forum
notifications altogether.

Toad for Oracle - Discussion Forum

Flag
this post as spam/abuse.

Morning Tom,

yes, that’s pretty much what I did too.

Looking at the code, mine and Tom Kyte’s, there’s a “feature”! If a single table has numerous columns with the same text contained, only the first will appear in the output!

For example, Oracle runs this query against my test tables:

SELECT DISTINCT

   CASE

      WHEN 1 = 0

      THEN

         'x'

      WHEN "COL_A" LIKE SYS_CONTEXT ('userenv', 'client_info')

      THEN

         'COL_A'

      WHEN "COL_B" LIKE SYS_CONTEXT ('userenv', 'client_info')

      THEN

         'COL_B'

      WHEN "COL_C" LIKE SYS_CONTEXT ('userenv', 'client_info')

      THEN

         'COL_C'

      ELSE

         NULL

   END

      cname

FROM “NORMAN”.“NORMAN”

WHERE ( 1 = 0

    OR "COL_A" LIKE SYS_CONTEXT ('userenv', 'client_info')

    OR "COL_B" LIKE SYS_CONTEXT ('userenv', 'client_info')

    OR "COL_C" LIKE SYS_CONTEXT ('userenv', 'client_info'));

So, if COL_A and COL_B have the searched for text within, the CASE statement will “short-circuit” after checking COL_A and finding a hit, so it returns only ‘COL_A’ as the result for this particular table. It will move on to the next table after finding a hit in one column of the current table. This can be seen in the results of running the packaged function and searching for text in bot COL_A and COL_B, all you get out of it is one row - select * from “NORMAN”.“NORMAN” where “COL_A” like ‘%Hello%’;

Hmmm.

Hi Norm,

In reply to your message at 27 Apr 2017 8:12 AM:

Looking at the code, mine and Tom Kyte’s, there’s a “feature”! If a single table has numerous columns with the same text contained, only the first will appear in the output!
:
:
So, if COL_A and COL_B have the searched for text within, the CASE statement will “short-circuit” after checking COL_A and finding a hit, so it returns only ‘COL_A’ as the result for this particular table. It will move on to the next table after finding a hit in one column of the current table. This can be seen in the results of running the packaged function and searching for text in bot COL_A and COL_B, all you get out of it is one row - select * from “NORMAN”.“NORMAN” where “COL_A” like ‘%Hello%’;

I have only found that feature with the Tom Kyte code. On the other had, your code did much better for me. Thus far, I have only found tables that include two columns with duplicate values, but your code has indeed shown two complete SQL statements, as expected. I would be willing to share the results of running your code versus the modified Tom Kyte code by private email, but I don’t feel comfortable posting those results to a more public forum. I have not tested for > 2 columns duplicated, but if a database is that badly normalized, then we probably have lots of problems!

I do have one more feature creep request for you, if you are up to the challenge. [:D]

How difficult might it be to add the ability to have a new table, populated with the names of tables that you do not want to waste time searching? For example, we have a number of tables in our production database that include names such as *_BAK, *_BACKUP, *_TMP, etc. I envision creating a query that involves the Oracle Minus operator, so that we subtract these tables from those found by searching the ALL_TABLES table.

Tom