oracle 如何在这个 PL/SQL 代码块中使用 INSERT INTO?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18117180/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 01:51:00  来源:igfitidea点击:

How do I use an INSERT INTO with this PL/SQL code block?

oraclefor-loopplsqlsql-insertsql-like

提问by duber

I'm fairly new to the procedural language side of PL/SQL, so forgive me if this is basic.

我对 PL/SQL 的过程语言方面还很陌生,所以如果这是基本的,请原谅我。

I'm trying to put values in a table I've previously created outside of this code block. This code is currently getting an error on the sixth line. Any idea why?

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

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;

采纳答案by duber

This worked.

这奏效了。

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

I cut the column names. Hope that helps.

我剪掉了列名。希望有帮助。

回答by haki

You don't need pl\sql here

你不需要 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 || '%'