Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/83.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/oracle/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用PL/SQL从SQL视图动态插入表_Sql_Oracle_Plsql_Insert_Cursor - Fatal编程技术网

如何使用PL/SQL从SQL视图动态插入表

如何使用PL/SQL从SQL视图动态插入表,sql,oracle,plsql,insert,cursor,Sql,Oracle,Plsql,Insert,Cursor,如何使用PL/SQL从SQL视图动态插入表: 当sql视图被更改时,我想使用PLSQL游标从sql视图动态插入到表中 vi_客户是一个sqlview(主数据) 顾客1是一张桌子 IDENTITY_CUSTOMERS是一个标识列 当前客户视图当前客户视图%rowtype 代码: CREATE OR REPLACE PROCEDURE p_customer_1 IS CURSOR cur_customer_view IS SELECT * FROM vi_customer

如何使用PL/SQL从SQL视图动态插入表:

  • 当sql视图被更改时,我想使用PLSQL游标从sql视图动态插入到表中

  • vi_客户是一个sqlview(主数据)

  • 顾客1是一张桌子

  • IDENTITY_CUSTOMERS是一个标识列

  • 当前客户视图当前客户视图%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.
错误:

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.

编写此逻辑的正确方法是使用
insert。选择
,而不是光标和循环:

INSERT INTO customers_1 ( . . . )
    SELECT . . .
    FROM vi_customer 
    WHERE IDENTITY_CUSTOMERS IN (SELECT c.IDENTITY_CUSTOMERS
                                 FROM vı_customer c
                                 MINUS
                                 SELECT c.IDENTITY_CUSTOMERS
                                 FROM vı_customer c INNER JOIN 
                                      customers_1 c1
                                      ON c1.IDENTITY_CUSTOMERS = c.IDENTITY_CUSTOMERS
                                );

编写此逻辑的正确方法是使用
insert。选择
,而不是光标和循环:

INSERT INTO customers_1 ( . . . )
    SELECT . . .
    FROM vi_customer 
    WHERE IDENTITY_CUSTOMERS IN (SELECT c.IDENTITY_CUSTOMERS
                                 FROM vı_customer c
                                 MINUS
                                 SELECT c.IDENTITY_CUSTOMERS
                                 FROM vı_customer c INNER JOIN 
                                      customers_1 c1
                                      ON c1.IDENTITY_CUSTOMERS = c.IDENTITY_CUSTOMERS
                                );
决心

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)

select 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 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);
决心

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)

select 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 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);

如何使用循环和光标进行写入?目前逻辑并不重要。@KeremGUL。相对而言,很少需要游标。如果可以使用基于集合的操作,则不应使用它们。学习何时使用游标和何时不使用游标与学习如何使用游标一样重要。插入选择通常是最好的…取决于插入集的大小…您可能希望一次插入x个数量(例如10000)…因为你不想让交易变得太大…但问题中的一条记录绝对是不鼓励的Dok Thank you@Gordon Linoff如何使用循环和光标编写?目前逻辑并不重要。@KeremGUL。相对而言,很少需要游标。如果可以使用基于集合的操作,则不应使用它们。学习何时使用游标和何时不使用游标与学习如何使用游标一样重要。插入选择通常是最好的…取决于插入集的大小…您可能希望一次插入x个数量(例如10000)…因为您不希望交易量过大…但问题中每次有一条记录绝对是不鼓励的Dok Thank you@Gordon Linoff让我注意到问题中不包括有错误的行。问题中没有提及
db_kg_0
。请注意,问题中不包括带错误的行。问题中没有提及
db\u kg\u 0