【问题标题】:Oracle 10g - convert columns to stringOracle 10g - 将列转换为字符串
【发布时间】:2017-03-20 18:22:18
【问题描述】:

我有一个包含 x 列的表,我需要删除其中的 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}
--------------------------------------------------

如何在更新脚本中实现这一点?

谢谢

【问题讨论】:

    标签: oracle oracle10g


    【解决方案1】:

    如何使用连接创建一个临时表,然后重命名它:

    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;
    

    【讨论】:

      猜你喜欢
      • 2013-01-12
      • 2021-09-12
      • 1970-01-01
      • 1970-01-01
      • 2020-01-19
      • 1970-01-01
      • 2021-04-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多