我定义了一个type类型表如下:      TYPE def_value_rec_type IS RECORD(
        parameter_code         tbl_1.parameter_code%TYPE,
        parameter_value        tbl_1.parameter_value%TYPE
        );复制代码以parameter_code的类型为主索引(字符型)    TYPE def_value_tbl_type1 IS TABLE OF def_value_rec_type INDEX BY tbl_1.parameter_code%TYPE;复制代码
如里往类型表中循环写入了10条数据,下面中的a只是举例,有可能是未知的字符。    for i in 1..10 loop
    x_paramter_tbl('a'||to_char(i)).parameter_code := rec_lgc.parameter_code;
    x_paramter_tbl('a'||to_char(i)).parameter_value := rec_lgc.parameter_value;
    end loop;复制代码那么应该如何才能取到类型表中的值呢?
因为索引是字符型的,所以不能用类似于x_paramter_tbl(i).parameter_code的方式取值。
type 循环

解决方案 »

  1.   

    自已搞定了,找到了答案。
    参考地址:http://www.cnblogs.com/gaolonglong/archive/2011/05/31/2064273.html
    记录下,方便查找,也方便有同样问题的朋友。以下是大概的代码:
    FOR i in 1..l_paramter_tbl.COUNT LOOP
        IF i = 1 THEN
            l_current_para_code := l_paramter_tbl.first;
            l_current_para_value := l_paramter_tbl(l_current_para_code).parameter_value; 
         ELSE
            IF l_paramter_tbl.NEXT(l_current_para_code) IS NOT NULL THEN
              l_current_para_code := l_paramter_tbl.NEXT(l_current_para_code);
              l_current_para_value := l_paramter_tbl(l_current_para_code).parameter_value; 
            ELSE
              EXIT;
            END IF;
          END IF;
          
          DBMS_OUTPUT.PUT_LINE(l_paramter_tbl(l_current_para_code).parameter_code ||  '=' || l_paramter_tbl(l_current_para_code).parameter_value);
    end loop;