簡體   English   中英

PLS-00222:此范圍內不存在名為“LV_RATING_AGENCY_TAB”的函數

[英]PLS-00222: no function with name 'LV_RATING_AGENCY_TAB' exists in this scope

我還在學校學習 PL/SQL,所以請善待。 我正在嘗試創建一個循環范圍,該循環讀取集合內容並通過使用集合的復合對象類型的成員檢查 ITEM_RATING 和 ITEM_RATING_AGENCY 列值來更新項目表中的 RATING_AGENCY_ID 列。

這是我的代碼:

DECLARE
    CURSOR c IS
        SELECT a.rating_agency_id AS id
             , a.rating AS rating
             , a.rating_agency AS agency
        FROM   rating_agency_table a;

    -- Create a collection of rating_agency
    lv_rating_agency_tab rating_agency;
BEGIN
    FOR i IN c LOOP
        lv_rating_agency_tab := rating_agency( rating_agency_id => i.id
                                             , rating => i.rating
                                             , rating_agency => i.agency );
    END LOOP;

    FOR i IN 1..lv_rating_agency_tab(i).COUNT LOOP
        INSERT INTO item
        ( rating_agency_id
        , item_rating
        , item_rating_agency )
        VALUES
        ( lv_rating_agency_tab.rating_agency_id
        , lv_rating_agency_tab.rating
        , lv_rating_agency_tab.rating_agency );
    END LOOP;

我不知道我做錯了什么,但我收到以下錯誤:

FOR i IN 1..lv_rating_agency_tab(i).COUNT LOOP
            *
ERROR at line 18:
ORA-06550: line 18, column 13:
PLS-00222: no function with name 'LV_RATING_AGENCY_TAB' exists in this scope
ORA-06550: line 18, column 1:
PL/SQL: Statement ignored

我正在更正你的代碼..讓你試試..因為我不知道你的表和類型結構,所以你可以試試下面的代碼..如果有任何困難,請告訴我。

代碼 :

DECLARE
    CURSOR c IS
        SELECT a.rating_agency_id AS id
             , a.rating AS rating
             , a.rating_agency AS agency
        FROM   rating_agency_table a;

    -- Create a collection of rating_agency
    lv_rating_agency_tab rating_agency;
BEGIN
    FOR i IN c LOOP
        lv_rating_agency_tab := rating_agency( rating_agency_id => i.id
                                             , rating => i.rating
                                             , rating_agency => i.agency );
    END LOOP;

    FOR i IN 1..lv_rating_agency_tab.COUNT 
    LOOP
        INSERT INTO item
        ( rating_agency_id
        , item_rating
        , item_rating_agency )
        VALUES
        ( lv_rating_agency_tab(i).rating_agency_id
        , lv_rating_agency_tab(i).rating
        , lv_rating_agency_tab(i).rating_agency );
    END LOOP;

    end;

你可以這樣做:

表和類型:

CREATE TYPE rating_agency AS OBJECT
(
   rating_agency_id NUMBER,
   rating NUMBER,
   rating_agency VARCHAR2 (100)
);
/
create table rating_agency_table
(
   rating_agency_id NUMBER,
   rating NUMBER,
   rating_agency VARCHAR2 (100)
);
/
create  table item 
(
rating_agency_id NUMBER, 
item_rating NUMBER, 
item_rating_agency  VARCHAR2 (100)
)

堵塞:

DECLARE
   CURSOR c
   IS
      SELECT rating_agency (a.rating_agency_id, a.rating, a.rating_agency)
        FROM rating_agency_table a;

   -- Create a collection of rating_agency
   TYPE typ_rating_agency IS TABLE OF rating_agency
      INDEX BY PLS_INTEGER;

   lv_rating_agency_tab   typ_rating_agency;
BEGIN
   OPEN c;

   FETCH c BULK COLLECT INTO lv_rating_agency_tab;

   CLOSE c;

   FOR i IN 1 .. lv_rating_agency_tab.COUNT
   LOOP
      INSERT INTO item (rating_agency_id, item_rating, item_rating_agency)
              VALUES (
                        lv_rating_agency_tab (i).rating_agency_id,
                        lv_rating_agency_tab (i).rating,
                        lv_rating_agency_tab (i).rating_agency);
   END LOOP;
   COMMIT;
END;

輸出:

SQL> SELECT * FROM ITEM;

RATING_AGENCY_ID ITEM_RATING ITEM_RATING_AGENCY
---------------- ----------- ---------------------------------------------------------------------------------------------
             111           1 FFFF
             222           2 XXX

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM