【问题标题】:Search Inside Table Type of Records搜索内表类型的记录
【发布时间】:2014-07-05 08:47:49
【问题描述】:

我有以下类型

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 变量

【问题讨论】:

  • CREATE OR REPLACE TYPE "CLONE_PRODUCT_CHAR_TABLE" IS TABLE OF CLONE_PRODUCT_RECORD; 无法编译。我想你的意思是as table of clone_product_char_record

标签: sql oracle types plsql oracle11g


【解决方案1】:
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;
/

【讨论】:

    猜你喜欢
    • 2017-09-09
    • 2021-09-12
    • 2017-12-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-13
    • 2011-04-29
    • 1970-01-01
    相关资源
    最近更新 更多