【发布时间】:2018-09-18 02:07:39
【问题描述】:
如何使用 PL/SQL 从 SQL 视图动态插入到表中:
当 sql 视图已更改时,我想使用 PLSQL Cursor 从 sql 视图动态插入表!!!
vi_customer 是一个 sqlview(主数据)
customers_1 是一张表
IDENTITY_CUSTOMERS 是一个标识列。
v_cur_cust_view cur_customer_view%rowtype
代码:
CREATE OR REPLACE PROCEDURE p_customer_1
IS
CURSOR cur_customer_view
IS
SELECT *
FROM vi_customer
WHERE IDENTITY_CUSTOMERS IN
(SELECT vi_cus.IDENTITY_CUSTOMERS FROM vı_customer vi_cus
MINUS
SELECT vı_customer.IDENTITY_CUSTOMERS
FROM vı_customer
INNER JOIN customers_1
ON customers_1.IDENTITY_CUSTOMERS=vı_customer.IDENTITY_CUSTOMERS
);
v_cur_cust_view cur_customer_view%rowtype;
BEGIN
FOR v_cur_cust_view IN cur_customer_view
LOOP
INSERT
INTO customers_1
(
cust_last_name,
cust_emaıl,
phone_number1,
phone_number2,
order_ıd,
order_tımestamp,
order_total,
quantıty,
unıt_prıce,
category,
fılename,
ımage_last_update,
product_ımage,
product_name,
lıst_prıce,
mımetype,
admın_user,
created_on,
expıres_on,
password,
products,
user_ıd,
user_name,
st,
state_name,
customer_ıd,
cust_fırst_name,
IDENTITY_CUSTOMERS
)
VALUES
(
v_cur_cust_view.cust_last_name,
v_cur_cust_view.cust_emaıl,
v_cur_cust_view.phone_number1,
v_cur_cust_view.phone_number2,
v_cur_cust_view.order_ıd,
v_cur_cust_view.order_tımestamp,
v_cur_cust_view.order_total,
v_cur_cust_view.quantıty,
v_cur_cust_view.unıt_prıce,
v_cur_cust_view.category,
v_cur_cust_view.fılename,
v_cur_cust_view.ımage_last_update,
v_cur_cust_view.product_ımage,
v_cur_cust_view.product_name,
v_cur_cust_view.lıst_prıce,
v_cur_cust_view.mımetype,
v_cur_cust_view.admın_user,
v_cur_cust_view.created_on,
v_cur_cust_view.expıres_on,
v_cur_cust_view.password,
v_cur_cust_view.products,
v_cur_cust_view.user_ıd,
v_cur_cust_view.user_name,
v_cur_cust_view.st,
v_cur_cust_view.state_name,
v_cur_cust_view.customer_ıd,
v_cur_cust_view.cust_fırst_name,
v_cur_cust_view.IDENTITY_CUSTOMERS
);
END LOOP;
COMMIT;
END;
错误:
Connecting to the database db_kg_0.
ORA-00917: missing comma
ORA-06512: at "DB_KG_0.P_CUSTOMER_1", line 15
ORA-06512: at line 2
Process exited.
Disconnecting from the database db_kg_0.
【问题讨论】:
-
请注意,有错误的行不包含在问题中。问题中没有对
db_kg_0的引用。
标签: sql oracle plsql insert cursor