Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Marking Out-of-Use Methods

DZone's Guide to

Marking Out-of-Use Methods

With Oracle 12c R2, it is now possible to mark a method as deprecated and then notify it when trying to use this method. Learn how to do it.

· Database Zone ·
Free Resource

RavenDB vs MongoDB: Which is Better? This White Paper compares the two leading NoSQL Document Databases on 9 features to find out which is the best solution for your next project.  

The use of "deprecated" methods, one of the warning mechanisms we are accustomed to from high-level programming languages, is now provided with PL/SQL with Oracle 12c R2. It is now possible to mark a method as deprecated and then notify it when trying to use this method.

Let's see how quickly we can handle this.

First of all, in order to be aware of these warnings that the compiler will generate, we open the following warning codes at the session level:

ALTER SESSION SET PLSQL_WARNINGS = 'ENABLE:(6019,6020,6021,6022)';

When we want to compile or call a method that we will mark as deprecated, we have opened the subroutine to give the required compiler warning. Now let's look at how to mark a method as deprecated:

CREATE OR REPLACE PROCEDURE kare_hesapla (x NUMBER)
IS
   PRAGMA deprecate (
    kare_hesapla, 'Bu metod eski. Yeni metod kare_hesapla_yeni.'
  );
   v   NUMBER;
BEGIN
   v := x * x;
END kare_hesapla;
/

As we can see from the sample we made, we reported to the system that the method is an old method with the statement PRAGMA deprecate. We compile our code with a warning system like the one below.

Image title

We marked our sample method as deprecated. Now let's call this method from within another method.

CREATE OR REPLACE PROCEDURE KARE_HESAPLA_2
IS
BEGIN
   KARE_HESAPLA (5);
END KARE_HESAPLA_2;

Image title

After compiling the code we see, the necessary warning messages were shown to us by the compiler. With this mechanism, we can easily alert software developers about the use of our old methods, and we can easily inform them about the use of new methods.

Get comfortable using NoSQL in a free, self-directed learning course provided by RavenDB. Learn to create fully-functional real-world programs on NoSQL Databases. Register today.

Topics:
database ,oracle ,tutorial ,deprecation

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}