2nd Example - Data Type Conversion on PL/SQL


In the second example will be demonstrated changes in the value of one data type into another data type (data type conversion). 5 pieces variables which are var1 date, var2 varchar2, varchar2 var3, var4 number, var5 date. Var1 contains the current date (sysdate). Var2 will convert var1 and store the converted date that had become varchar2, var3 will convert the date into varchar (different format). Var4 will change Var3 results into numbers. Var5 will convert varchar to date in var2.


DECLARE
 Var1 DATE;
 Var2 VARCHAR2(16);
 Var3 VARCHAR2(16);
 Var4 NUMBER;
 Var5 DATE;
BEGIN
 Var1 := SYSDATE;
 Var2 := TO_CHAR(Var1, 'YYYY/MM');
 Var3 := TO_CHAR(Var1, 'YYYY');
 Var4 := TO_NUMBER(Var3);
 Var5 := TO_DATE(Var2, 'YYYY-MM');
 DBMS_OUTPUT.PUT_LINE(Var5);
END;
/

No comments

Powered by Blogger.