【问题标题】:PLSQL IF/ELSE function to check XML valuePLSQL IF/ELSE 函数检查 XML 值
【发布时间】:2016-07-20 11:40:16
【问题描述】:

我正在尝试创建一个函数,该函数将获取一个条目 (ID),然后检查特定 XML 值的相关 XMLTYPE 字段并根据结果采取行动,但是我在将所有部分放在一起时遇到了一些困难。我有以下选择语句,可用于选择我正在寻找的 XML 值:

select x.xmldata.extract('//Fc_curstage/text()').getStringVal()
from test_data  x
where id = 149;

我目前的功能是:

create or replace
function get_xmlstatus
    (p_stage in NUMBER)
    return VARCHAR2 is
    v_stage varchar2(20);

    begin
    return varchar2
      IF v_cur_stg = 'INITIAL' THEN
      -- Create new record in stage
    v_stage := 'INITIAL 1';

    ELSIF v_cur_stg = 'RETURNED' THEN
      -- Remove any associated records from the stage
    v_stage := 'Returned 2';
    ELSE
      -- this should raise exception
    v_stage := 'Blank Expected 3';
    END IF;

我不确定我需要在哪里声明:

v_cur_stg:=x.xmldata.extract('//Fc_curstage/text()').getStringVal();

或者我需要在哪里包含 select 语句,以便函数知道如何处理传递给函数的 ID。

【问题讨论】:

    标签: sql plsql oracle11g


    【解决方案1】:

    试试这个:

    create or replace function get_xmlstatus (p_stage in NUMBER)
      return VARCHAR2 is
    
      v_cur_stage varchar2(20);
      v_stage varchar2(20);
     begin
    
       select x.xmldata.extract('//Fc_curstage/text()').getStringVal()
       into v_cur_stg
        from test_data  x
       where id = p_stage; --149;   
    
    
       IF v_cur_stg = 'INITIAL' THEN
          -- Create new record in stage
        v_stage := 'INITIAL 1';
    
        ELSIF v_cur_stg = 'RETURNED' THEN
          -- Remove any associated records from the stage
        v_stage := 'Returned 2';
        ELSE
          -- this should raise exception
        v_stage := 'Blank Expected 3';
        END IF;
    
        Return v_stage;
     End;   
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-08-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-08-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多