【问题标题】:Oracle database batch update pl_sqlOracle数据库批量更新pl_sql
【发布时间】:2015-10-07 20:16:14
【问题描述】:

我正在尝试使用 pl_sql 6.0 程序“翻译”一个月份表。

我想以非常简单的代码一次运行以下所有这些指令,例如“选择指令并按 F8”。

问题是:

没有“;”在每条指令之间,我得到: ORA-00933 命令未正确结束 和 ”;”在每条指令之间,我得到:ORA-00911 无效字符 我是 Oracle 数据库的新手,所以...我没有看到什么?提前致谢。

update TIME_TABLE t set t.m_description='JANEIRO' where t.m_description like '%JANUARY%'
update TIME_TABLE t set t.m_description='FEVEREIRO' where t.m_description like '%FEBRUARY%'
update TIME_TABLE t set t.m_description='MARÇO' where  t.m_description like '%MARCH%'
update TIME_TABLE t set t.m_description='ABRIL' where t.m_description like '%APRIL%'
... and so on

【问题讨论】:

    标签: oracle


    【解决方案1】:

    使用CASE 语句更新。

    update TIME_TABLE t 
    set t.m_description = (
        case when t.m_description like '%JANUARY%' then 'JANEIRO' 
            when t.m_description like '%FEBRUARY%' then 'FEVEREIRO'
            when t.m_description like '%MARCH%' then 'MARÇO'
            when t.m_description like '%APRIL%' then 'ABRIL'
        else t.m_description
        end
    )
    

    【讨论】:

      【解决方案2】:

      只需将这些指令放在 BEGIN ... END 中,如下所示:

      BEGIN
         update TIME_TABLE t set t.m_description='JANEIRO' where t.m_description like '%JANUARY%'
         update TIME_TABLE t set t.m_description='FEVEREIRO' where t.m_description like '%FEBRUARY%'
         update TIME_TABLE t set t.m_description='MARÇO' where  t.m_description like '%MARCH%'
         update TIME_TABLE t set t.m_description='ABRIL' where t.m_description like '%APRIL%'
         ... and so on
      END;
      /
      

      【讨论】:

        猜你喜欢
        • 2014-08-30
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-01-18
        相关资源
        最近更新 更多