Search code examples
oracle-databasewhere-clause

Oracle - denie columns in where clause


Is there a way to disable/restrict/alert-when-using some column in Oracle in a where clauses?

The reason that I'm asking this is because I have a very complex system (~30 services span cross millions of lines of code with thousends of sqls in it, in a sensitive production environment) working with an Oracle DB I need to migrate from using one column that is part of a key (and have a very not uniqu name) to another column.

Simple search is impossible.... The steps I'm having are:

  1. populate new column
  2. Add indexes on with the second column whenever there's an index with the first one.
  3. Migrate all uses in where caluses from old to new column
  4. Stop reading from the first column
  5. Stop writing to the first column
  6. Delete the column

I'm currently done step 3 and want to verify I've found all of the cases.


Solution

  • So, you're replacing one column with another. Which benefit do you expect once you're done? How will that improve overall experience with that application? I hope it is worth the effort.

    As of your question: query user_source (or expand it to all_source or even dba_source, but you'll need additional privileges to do that) and see where's that very not unique name used. Something like this:

    SQL> select * from user_source where lower(text) like '%empno%';
    
    NAME            TYPE          LINE TEXT
    --------------- ------------ ----- --------------------------------------------------------------------------------
    P_RAISE         PROCEDURE       22        WHERE empno = par_empno;
    P_RAISE         PROCEDURE       14     WHERE empno = par_empno;
    P_RAISE         PROCEDURE        1 PROCEDURE p_raise (par_empno IN emp.empno%TYPE)
    GET_LIST        FUNCTION         7          'select empno, ename, job, sal from emp where deptno = 10 order by '
    
    SQL>