Is there a function in PL/SQL to show a variable's exact type, like the DUMP function in SQL?
I've tried the following
DECLARE
l_variable INTEGER := 1;
BEGIN
DBMS_OUTPUT.PUT_LINE (DUMP (l_variable));
END;
But it gives the following error:
PLS-00204: function or pseudo-column 'DUMP' may be used inside a SQL statement only
If the variable doesn't exist you'll get a NO_DATA_FOUND , and if there are two variables with the same name in the object you'll get ORA-01422: exact fetch returns more than requested number of rows .
Also, if you have Toad for Oracle, you can highlight the statement and press CTRL + F9 and you'll get a nice view of column and their datatypes.
In PL/SQL, a variable is named storage location that stores a value of a particular data type. The value of the variable changes through the program. Before using a variable, you must declare it in the declaration section of a block.
The %TYPE attribute lets use the datatype of a field, record, nested table, database column, or variable in your own declarations, rather than hardcoding the type names. You can use the %TYPE attribute as a datatype specifier when declaring constants, variables, fields, and parameters.
declare
a number(10,3);
type_info varchar2(400);
begin
a := 55.5;
select dump(a) into type_info from dual;
DBMS_OUTPUT.PUT_LINE(type_info);
end;
as you should notice, DUMP is an overloaded function. it has 3 overloads.
So you can simulate the same thing within your code.
function myDump (x Varchar2) return varchar2 is begin return('string') ; end ;
function myDump (x number) return varchar2 is begin return('integer') ; end ;
function myDump (x date) return varchar2 is begin return('date') ; end ;
the above code may not work properly but should give you the idea how to deal the problem.
I hope that this will fulfil your requirements.
Note; you can put these functions in a Package and use them accordingly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With