Oracle 10g - 将列转换为字符串
Oracle 10g - convert columns to string
我有一个包含 x 列的 table,我需要删除其中的 4 个,但在我需要将这些列转换为 json 格式的 varchar 之前。
例子
现在怎么样
car
-----------------------------
id name color year HP
-- ------ ------ ---- ---
1 porche green 2014 350
删除 3 列并创建详细信息列后我需要的结果
car
--------------------------------------------------
id name detail
-- ------ -------------------------------------
1 porche {color: 'green', year: 2014, HP: 350}
--------------------------------------------------
我如何在更新脚本中实现这个?
谢谢
如何使用连接创建临时 table 然后重命名:
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;
我有一个包含 x 列的 table,我需要删除其中的 4 个,但在我需要将这些列转换为 json 格式的 varchar 之前。
例子
现在怎么样
car
-----------------------------
id name color year HP
-- ------ ------ ---- ---
1 porche green 2014 350
删除 3 列并创建详细信息列后我需要的结果
car
--------------------------------------------------
id name detail
-- ------ -------------------------------------
1 porche {color: 'green', year: 2014, HP: 350}
--------------------------------------------------
我如何在更新脚本中实现这个?
谢谢
如何使用连接创建临时 table 然后重命名:
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;