I'm usualy use PostgreSQL, but I'm currently doing it in Oracle.
I need to chage the data type of a column in a query(select), in PostgreSQL I usualy do it in this way:
select 1::varchar from table
Hoe can I do this in Oracle?
Best Regards,
convert to varchar
select to_char(Field) from table
truncate varchar
select substr(field, 1, 1) from table
As @Michael Pakhantsov points out, to_char
works for converting to string. Likewise, to_date
and to_timestamp
are the standard when converting strings to dates and timestamps respectively. However, if you find that you need to perform a more exotic conversion (varchar2 to raw, for instance), then cast
is your friend:
Number to string:
select cast(field as varchar2(30)) from table;
String to Raw:
select cast(field as raw(16)) from table;
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