Vinicius Cunha
Vinicius Cunha

Reputation: 63

Oracle 10g - convert columns to string

I have a table with x columns and i need drop 4 of them, but before i need transform these columns into varchar in json format.

Example

how is now

car
-----------------------------
id    name   color  year  HP
--   ------  ------ ----  ---
1    porche  green  2014  350

the result i need after drop 3 columns and create detail column

car
--------------------------------------------------
id    name   detail
--   ------  -------------------------------------
1    porche  {color: 'green', year: 2014, HP: 350}
--------------------------------------------------

How can i achieve this in update script?

Thanks

Upvotes: 0

Views: 125

Answers (1)

Gurwinder Singh
Gurwinder Singh

Reputation: 39457

How about creating a temporary table using concatenations and then renaming it:

create table your_table_new as
select 
    id, name, '{color: ''' || color || ''', year: ' || year || ', HP: ' || HP || '}' as detail
from your_table;


drop table your_table;
rename your_table_new to your_table;

Upvotes: 2

Related Questions