Mega Code Archive

 
Categories / Oracle PLSQL Tutorial / PL SQL Data Types
 

Use TO_NUMBER to assign value to NATURAL type variable

SQL> SET ECHO ON SQL> SET SERVEROUTPUT ON SQL> DECLARE   2    age   DATE;   3    current_year NATURAL;   4  BEGIN   5    age := sysdate;   6    current_year := TO_NUMBER(TO_CHAR(age,'yy'));   7    DBMS_OUTPUT.PUT_LINE('current_year:');   8    DBMS_OUTPUT.PUT_LINE(current_year);   9  END;  10  / current_year: 7 PL/SQL procedure successfully completed. SQL>