如何在此PL / SQL代码块中使用INSERT INTO?

时间:2013-08-08 02:54:35

标签: oracle for-loop plsql sql-insert sql-like

我对PL / SQL的过程语言方面还不熟悉,如果这是基本的话,请原谅我。

我正在尝试将值放在我之前在此代码块之外创建的表中。此代码目前在第六行出错。知道为什么吗?

BEGIN
  FOR c IN (SELECT name FROM clients) LOOP
    FOR d IN (SELECT customer_id, alt_name FROM customers) LOOP 
      IF d.alt_name LIKE '%' || c.name || '%'
      THEN
            INSERT INTO previously_made_table(name, customer_id, alt_name, customer_code) VALUES(c.name, d.customer_id, d.alt_name, '101');
            COMMIT;
       END IF;
    END LOOP;
END LOOP;
END;

2 个答案:

答案 0 :(得分:4)

你这里不需要pl \ sql

insert into previously_made_table
  (name, customer_id, alt_name, customer_code) 
 select c.name, d.customer_id, d.alt_name, '101'
 from   clients c , customers d
 where  d.alt_name LIKE '%' || c.name || '%'

答案 1 :(得分:-1)

这很有用。

INSERT INTO previously_made_table VALUES(c.name, d.customer_id, d.alt_name, '101');

我剪切了列名。希望有所帮助。