搜索表的内部记录类型 [英] Search Inside Table Type of Records

查看:52
本文介绍了搜索表的内部记录类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下几种类型

CREATE OR REPLACE TYPE "CLONE_PRODUCT_CHAR_RECORD" IS OBJECT  (
  CharacteristicID              NUMBER,
  NewValue              VARCHAR2(200 Char),
  NewValueName      VARCHAR2(200 Char)
);


 CREATE OR REPLACE TYPE "CLONE_PRODUCT_CHAR_TABLE" IS 
  TABLE OF CLONE_PRODUCT_CHAR_RECORD;

以及以下步骤

DECLARE 

characteristic CLONE_PRODUCT_CHAR_TABLE:=CLONE_PRODUCT_CHAR_TABLE(

      CLONE_PRODUCT_CHAR_RECORD(2,'ZIKA','ZIKA'),
      CLONE_PRODUCT_CHAR_RECORD(3,'MIGO','MIGO'),
      CLONE_PRODUCT_CHAR_RECORD(4,'ZAG','ZAG')

);

char_record CLONE_PRODUCT_CHAR_RECORD;

BEGIN


END;

我需要从CharacteristicID = 3的特征记录中选择char_record变量

and i need to select from characteristic record with CharacteristicID = 3 into the char_record variable

推荐答案

declare 
characteristic CLONE_PRODUCT_CHAR_TABLE:=CLONE_PRODUCT_CHAR_TABLE(
      CLONE_PRODUCT_CHAR_RECORD(2,'ZIKA','ZIKA'),
      CLONE_PRODUCT_CHAR_RECORD(3,'MIGO','MIGO'),
      CLONE_PRODUCT_CHAR_RECORD(4,'ZAG','ZAG')
);
char_record CLONE_PRODUCT_CHAR_RECORD;
BEGIN
  for i in 1 .. characteristic.count loop
      if characteristic(i).characteristicID = 3 then
         char_record := characteristic(i);
         exit;
      end if;
  end loop;
  dbms_output.put_line(char_record.newValue);
  dbms_output.put_line(char_record.newValueName);
END;
/

或者,您可能想尝试

declare 
characteristic CLONE_PRODUCT_CHAR_TABLE:=CLONE_PRODUCT_CHAR_TABLE(
      CLONE_PRODUCT_CHAR_RECORD(2,'ZIKA','ZIKA'),
      CLONE_PRODUCT_CHAR_RECORD(3,'MIGO','MIGO'),
      CLONE_PRODUCT_CHAR_RECORD(4,'ZAG','ZAG')
);
char_record CLONE_PRODUCT_CHAR_RECORD;
BEGIN

  select CLONE_PRODUCT_CHAR_RECORD(characteristicID, newvalue, newvaluename)
    into char_record from
   table(characteristic)
   where
      characteristicID = 3;

  dbms_output.put_line(char_record.newValue);
  dbms_output.put_line(char_record.newValueName);
END;
/

这篇关于搜索表的内部记录类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆