簡體   English   中英

如何使用select語句在表中使用插入

[英]How to use insert into a table using a select statement

下面是我的PL / SQL塊,在這里我想通過選擇另一個表來插入記錄,這對我填充的變量不利。

DECLARE
  CURSOR cust_insert is
    select distinct UBAN,SUBSCRIBER_NO from not_exists_inv_RC_CINF;

  i_cust_id    varchar2(100);
  i_sub_no     varchar2(100);

Begin

  dbms_output.enable(2000000);

  Open cust_insert; 
  Loop  
    Fetch cust_insert into i_cust_id,i_sub_no;
    Exit when cust_insert%NOTFOUND; 

    dbms_output.put_line('CUSTOMER IS :- '||i_cust_id
      ||' SUBSCRIBER IS :- '||i_sub_no);

    insert into not_exists_inv_RC_CINF_TRB
    select a.MST_TRX_ID,entity_id 
    from lspappc.trb9_mst_log_1v a, lspappc.trb1_actv b 
    where a.ACTV_CODE_ID=b.ACTV_CODE_ID
    and PART_DEP_ENT like 'CUSTOMER=i_cust_id'
    and general_data_c like '%i_sub_no%'
    and a.ACTV_CODE_ID=44;

    commit;
  END LOOP;

  Close cust_insert;   
End;
/

數據未插入表中,您能解釋為什么嗎?

您正在將PL / SQL變量視為字符串文字; 這個:

general_data_c like '%i_sub_no%'

應該:

general_data_c like '%' || i_sub_no || '%'

我不確定您要做什么:

PART_DEP_ENT like 'CUSTOMER=i_cust_id'

因為沒有通配符,而且構造看起來仍然很奇怪; 你可能想要:

PART_DEP_ENT = 'CUSTOMER=' || l_cust_id

...但是還不清楚。

但是,有了文字值,您從中選擇的表中就沒有匹配的記錄-記住,您要查找的是字符串'i_sub_no' ,而不是`i_sub_no'變量的值。

暫無
暫無

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

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