类型表空值检查

问题描述 投票:0回答:4

我在plsql块中具有以下关注类型

 TYPE table_type IS TABLE OF VARCHAR2(200);
 v_tab_1  table_type;

值初始化为

if (PROD_AMNT > INV_AMNT) then            

 v_tab_1 := table_type(PROD_AMNT, 'CURR');
......

有时上述条件将不成立,并且v_tab_1中将存在空值

v_tab_1中是否存在检查值的最佳方法?

我曾尝试过

 if not(v_tab_1.EXISTS(v_tab_1.first)) then

但是以上导致NO_DATA_FOUND异常

如何处理?

oracle plsql oracle10g
4个回答
1
投票

将单个错误值强制为表类型?然后检查该值。

if (PROD_AMNT > INV_AMNT) then            

 v_tab_1 := table_type(PROD_AMNT, 'CURR');

else

 v_tab_1 := table_type(0, 'ERR');

end if;

2
投票

检查变量是否为null或是否初始化了容器但为空。例如:

declare
  type list_t is table of varchar2(10);
  v_list list_t;
begin
  --
  -- 1) v_list is a null variable
  --

  v_list := null;

  if false then
    v_list := list_t('foo', 'bar');
  end if;

  if v_list is not null then
    dbms_output.put_line('v_list = ' || v_list(1) || ';' || v_list(2));
  else
    dbms_output.put_line('v_list is a null variable');
  end if;

  --
  -- 2) v_list is an empty but initialized collection
  --

  v_list := list_t();

  if false then
    v_list := list_t('foo', 'bar');
  end if;

  if v_list.exists(v_list.first) then
    dbms_output.put_line('v_list = ' || v_list(1) || ';' || v_list(2));
  else
    dbms_output.put_line('v_list is an empty but initialized collection');
  end if;

end;
/

1
投票

您可以使用以下方式:

- IF CreatedCursor%NOTFOUND THEN..

Or

- IF YourField IS NOT NULL THEN..

or 

- if NVL( YourField , 'NA' ) = 'NA'...

0
投票
Declare
    Type TBL_VARCHAR Is Table Of varchar2(10);
    tblFirst tbl_varchar; 
    tblSecond tbl_varchar; 
Begin
    -- Check if tblFirst is a null variable 
    Begin 
        If tblFirst.Count >= 0 Then
           tblSecond := tblFirst;
        End If;
    Exception       
        When Others Then 
            tblSecond := new tbl_varchar();
    End;

    -- Then I use tblSecond
    DBMS_OUTPUT.PUT_LINE(tblSecond.Count);
End;
© www.soinside.com 2019 - 2024. All rights reserved.