INSERT statement is slower in PL/SQL, SQL

I can't understand why an insert in PL/SQL is much slower than in SQL (against 5 minutes 2 seconds).

INSERT statement and explain plans are below.


The BIG difference is that I use an immediate execution with bind variable because I'm passing in the dynamic table/column names. Maybe that confuses the optimizer? Another point is that if I remove the 2 'GOLD' terms these two queries run the same speed.


Oracle 10g

Jason

The insert statement is:

[code]

INSERT / * + APPEND * / INTO linker_sec_betach_ip

SELECT

SEC_CLIENTVISIT_GUID

SEC_INST

SEC_ADMIT_DT

SEC_DISCHARGE_DT

SEC_ENCOUNTER

SEC_TYPE

SEC_STATUS

SEC_CARE_LEVEL

BETACH_CD_ENCOUNTER_ID

BETACH_INST

BETACH_ADMIT_DT

BETACH_DISCH_DT

BETACH_PCU_FIRST

DATE_SCORE

LAST_UPDATE_DT AS SYSDATE

CEN

SELECT

BT. CLIENTVISIT_GUID AS SEC_CLIENTVISIT_GUID

bt. INST AS SEC_INST

bt. ADMIT_DT AS SEC_ADMIT_DT

bt. DISCHARGE_DT AS SEC_DISCHARGE_DT

bt. MEETING AS SEC_ENCOUNTER

bt. SEC_TYPE ACE TYPE

bt. STATE SEC_STATUS

bt. CARE_LEVEL AS SEC_CARE_LEVEL

JT. CD_ENCOUNTER_ID AS BETACH_CD_ENCOUNTER_ID

JT. INST AS BETACH_INST

JT. ADMIT_DT AS BETACH_ADMIT_DT

JT. DISCH_DT AS BETACH_DISCH_DT

JT. PCU_FIRST AS BETACH_PCU_FIRST

ABS (bt. ADMIT_DT - JT. ADMIT_DT) AS DATE_SCORE

MIN (ABS (bt. ADMIT_DT - JT. ADMIT_DT)) OVER (PARTITION BY bt. CLIENTVISIT_GUID) AS LINK_PRIMARY_KEY_SCORE

MIN (ABS (bt. ADMIT_DT - JT. ADMIT_DT)) OVER (PARTITION BY JT. CD_ENCOUNTER_ID) AS BASE_PRIMARY_KEY_SCORE

OF sec_encounters_delme bt

jt betach_visits

WHERE)

(bt. RSP = JT. PHN)

OR (bt. PTN_CHART = JT. RHRN) - IF I REMOVE THESE TWO THEN THEY BOTH RUN THE SAME SPEED

OR (bt. MEET = JT. ENCOUNTER_NO) -IF I REMOVE THESE TWO and THEN THEY BOTH PERFORM THE SAME SPEED

)

AND bt. ADMIT_DT < trunc (sysdate)

AND bt. ADMIT_DT > = JT. ADMIT_DT - 1.5

AND bt. ADMIT_DT < = JT. ADMIT_DT + 1.5

AND bt. ADMIT_DT > = trunc(sysdate-7)

AND bt. ADMIT_DT < trunc(sysdate-7) + 7

AND JT. ADMIT_DT > = trunc(sysdate-7) - 1.5

AND JT. ADMIT_DT < = trunc(sysdate-7) + 7 + 1.5

AND 1 = 1

);

[/ code]

THIS PLAN IS < 2 seconds for 5000 lines

Hash value of plan: 1434516581

-----------------------------------------------------------------------------------------------------------

| ID | Operation | Name                  | Lines | Bytes | Cost (% CPU). Time |

-----------------------------------------------------------------------------------------------------------

|   0 | INSERT STATEMENT.                       |     3.   378.    42 (3) | 00:00:01 |

|   1.  LOAD SELECT ACE | LINKER_SEC_BETACH_IP |       |       |            |          |

|   2.   VIEW                            |                       |     3.   378.    42 (3) | 00:00:01 |

|   3.    CONCATENATION.                       |       |       |            |          |

|*  4 |     FILTER                        |                       |       |       |            |          |

|*  5 |      TABLE ACCESS BY INDEX ROWID | SEC_ENCOUNTERS_DELME |     1.    74.     3 (0) | 00:00:01 |

|   6.       NESTED LOOPS |                       |     1.   137.    13 (0) | 00:00:01 |

|   8 S        TABLE ACCESS BY INDEX ROWID | BETACH_VISITS |     1.    63.    10 (0) | 00:00:01 |

|*  8 |         INDEX RANGE SCAN | IDX_BETACH_VISITS_006 |     1.       |     9 (0) | 00:00:01 |

|*  9 |        INDEX RANGE SCAN | NDX_SEC_ENC_05 |     1.       |     2 (0) | 00:00:01 |

| * 10 |     FILTER                        |                       |       |       |            |          |

| * 11 |      TABLE ACCESS BY INDEX ROWID | SEC_ENCOUNTERS_DELME |     1.    74.     4 (0) | 00:00:01 |

|  12.       NESTED LOOPS |                       |     1.   137.    14 (0) | 00:00:01 |

|  13.        TABLE ACCESS BY INDEX ROWID | BETACH_VISITS |     1.    63.    10 (0) | 00:00:01 |

| * 14 |         INDEX RANGE SCAN | IDX_BETACH_VISITS_006 |     1.       |     9 (0) | 00:00:01 |

| * 15 |        INDEX RANGE SCAN | NDX_SEC_ENC_06 |     3.       |     2 (0) | 00:00:01 |

| * 16.     FILTER                        |                       |       |       |            |          |

| * 17.      TABLE ACCESS BY INDEX ROWID | SEC_ENCOUNTERS_DELME |     1.    74.     4 (0) | 00:00:01 |

|  18.       NESTED LOOPS |                       |     1.   137.    14 (0) | 00:00:01 |

| * 19.        TABLE ACCESS BY INDEX ROWID | BETACH_VISITS |     1.    63.    10 (0) | 00:00:01 |

| * 20.         INDEX RANGE SCAN | IDX_BETACH_VISITS_006 |     1.       |     9 (0) | 00:00:01 |

| * 21.        INDEX RANGE SCAN | NDX_SEC_ENC_03 |     3.       |     2 (0) | 00:00:01 |

-----------------------------------------------------------------------------------------------------------

Information of predicates (identified by the operation identity card):

---------------------------------------------------

4 filter (TRUNC (SYSDATE@!-7) - 1.5 < = TRUNC (SYSDATE@!-7) + 7 + 1.5 AND)

TRUNC (sysdate@!-7) < TRUNC (SYSDATE@!-7) + 7 AND TRUNC(SYSDATE@!) > TRUNC (SYSDATE@!-7))

5 - filter("BT".") ADMIT_DT' > = TRUNC (SYSDATE@!-7) AND "BT". "" ADMIT_DT "< TRUNC(SYSDATE@!) AND

'BT '. "" ADMIT_DT "< TRUNC (SYSDATE@!-7) + 7 AND"BT ". "" ADMIT_DT "> = INTERNAL_FUNCTION ("JT". "ADMIT_DT")-1.5 "

(AND "BT". "" ADMIT_DT "< = INTERNAL_FUNCTION ("JT". "ADMIT_DT") + (1.5) "

8 - access("JT".") ADMIT_DT' > = TRUNC (SYSDATE@!-7) - 1.5 AND

"JT". ("' ADMIT_DT" < = TRUNC (SYSDATE@!-7) + 7 + 1.5)

filter (INTERNAL_FUNCTION ("JT". "ADMIT_DT")-1.5 < TRUNC(SYSDATE@!) " AND

INTERNAL_FUNCTION ("JT". "ADMIT_DT") + 1.5 > = TRUNC (SYSDATE@!-7) AND "

INTERNAL_FUNCTION ("JT". "ADMIT_DT")-1.5 < TRUNC (SYSDATE@!-7)(+7) "

9 - access("BT".") MEET JT '=' '. ("' ENCOUNTER_NO")

10 filter (TRUNC (SYSDATE@!-7) - 1.5 < = TRUNC (SYSDATE@!-7) + 7 + 1.5 AND)

TRUNC (sysdate@!-7) < TRUNC (SYSDATE@!-7) + 7 AND TRUNC(SYSDATE@!) > TRUNC (SYSDATE@!-7))

11 - filter("BT".") ADMIT_DT' > = TRUNC (SYSDATE@!-7) AND "BT". "" ADMIT_DT "< TRUNC(SYSDATE@!) AND

'BT '. "" ADMIT_DT "< TRUNC (SYSDATE@!-7) + 7 AND"BT ". "" ADMIT_DT "> = INTERNAL_FUNCTION ("JT". "ADMIT_DT")-1.5 "

(AND "BT". "" ADMIT_DT "< = INTERNAL_FUNCTION ("JT". "ADMIT_DT") + 1.5 AND "

LNNVL ("BT". "JT"="MEETING" "." " ENCOUNTER_NO'))

14 - access("JT".") ADMIT_DT' > = TRUNC (SYSDATE@!-7) - 1.5 AND

"JT". ("' ADMIT_DT" < = TRUNC (SYSDATE@!-7) + 7 + 1.5)

filter (INTERNAL_FUNCTION ("JT". "ADMIT_DT")-1.5 < TRUNC(SYSDATE@!) " AND

INTERNAL_FUNCTION ("JT". "ADMIT_DT") + 1.5 > = TRUNC (SYSDATE@!-7) AND "

INTERNAL_FUNCTION ("JT". "ADMIT_DT")-1.5 < TRUNC (SYSDATE@!-7)(+7) "

15 - access("BT".") PTN_CHART «= TO_NUMBER ("JT".» RHRN'))

16 filter (TRUNC (SYSDATE@!-7) - 1.5 < = TRUNC (SYSDATE@!-7) + 7 + 1.5 AND)

TRUNC (sysdate@!-7) < TRUNC (SYSDATE@!-7) + 7 AND TRUNC(SYSDATE@!) > TRUNC (SYSDATE@!-7))

17 - filter("BT".") ADMIT_DT' > = TRUNC (SYSDATE@!-7) AND "BT". "" ADMIT_DT "< TRUNC(SYSDATE@!) AND

'BT '. "" ADMIT_DT "< TRUNC (SYSDATE@!-7) + 7 AND"BT ". "" ADMIT_DT "> = INTERNAL_FUNCTION ("JT". "ADMIT_DT")-1.5 "

(AND "BT". "" ADMIT_DT "< = INTERNAL_FUNCTION ("JT". "ADMIT_DT") + 1.5 AND "

LNNVL ("BT". "PTN_CHART '= TO_NUMBER ("JT".' RHRN')) AND LNNVL ("BT". "JT"="MEETING" "." " ENCOUNTER_NO'))

19 - filter("JT".") PHNS' IS NOT NULL)

20 - access("JT".") ADMIT_DT' > = TRUNC (SYSDATE@!-7) - 1.5 AND

"JT". ("' ADMIT_DT" < = TRUNC (SYSDATE@!-7) + 7 + 1.5)

filter (INTERNAL_FUNCTION ("JT". "ADMIT_DT")-1.5 < TRUNC(SYSDATE@!) " AND

INTERNAL_FUNCTION ("JT". "ADMIT_DT") + 1.5 > = TRUNC (SYSDATE@!-7) AND "

INTERNAL_FUNCTION ("JT". "ADMIT_DT")-1.5 < TRUNC (SYSDATE@!-7)(+7) "

21 - access("BT".") PHN '=' JT '. ("' PHN ')


When I placed this SQL in PL/SQL (AND place it in an immediate execution) it slows down.

THIS PLAN GOES ~ 5minutes to 5000 lines

Hash value of plan: 60405780

----------------------------------------------------------------------------------------------------------

| ID | Operation | Name                  | Lines | Bytes | Cost (% CPU). Time |

----------------------------------------------------------------------------------------------------------

|   0 | INSERT STATEMENT.                       |     1.   126.     2 (0) | 00:00:01 |

|   1.  LOAD SELECT ACE | LINKER_SEC_BETACH_IP |       |       |            |          |

|   2.   VIEW                           |                       |     1.   126.     2 (0) | 00:00:01 |

|*  3 |    FILTER                        |                       |       |       |            |          |

|*  4 |     TABLE ACCESS BY INDEX ROWID | SEC_ENCOUNTERS_DELME |     1.    74.     1 (0) | 00:00:01 |

|   5.      NESTED LOOPS |                       |     1.   137.     2 (0) | 00:00:01 |

|   4 >       TABLE ACCESS BY INDEX ROWID | BETACH_VISITS |     1.    63.     1 (0) | 00:00:01 |

|*  7 |        INDEX RANGE SCAN | IDX_BETACH_VISITS_006 |     1.       |     1 (0) | 00:00:01 |

|*  8 |       INDEX RANGE SCAN | NDX_SEC_ENC_07 |     2.       |     1 (0) | 00:00:01 |

----------------------------------------------------------------------------------------------------------

Information of predicates (identified by the operation identity card):

---------------------------------------------------

3 filter (TO_NUMBER(:4) - 1.5 < = TO_NUMBER(:5) + 7 + AND 1.5: 2 < TO_NUMBER(:3) + 7 AND)

To_date(:1) > TO_DATE (:2))

4 - filter("BT".") PHN '=' JT '. "' PHN ' AND 'JT '. "' PHN ' IS NOT NULL OR

'BT '. «PTN_CHART «= TO_NUMBER ("JT".» ("' RHRN") OR "BT". «"JT MEETING «=»» ("' ENCOUNTER_NO")

7 - access("JT".") ADMIT_DT' > = TO_NUMBER(:4) - 1.5 AND "JT". ("' ADMIT_DT" < = TO_NUMBER(:5) + 7 + 1.5)

filter (INTERNAL_FUNCTION ("JT". "ADMIT_DT")-1.5 < TO_NUMBER(:3) + 7 AND "

INTERNAL_FUNCTION ("JT". "ADMIT_DT")-1.5 <: 1 AND INTERNAL_FUNCTION ("JT" ".") " (ADMIT_DT') + 1.5 > =: 2)

8 - access("BT".") ADMIT_DT' > = INTERNAL_FUNCTION ("JT". "ADMIT_DT") - 1.5 AND "BT". ("' ADMIT_DT" <: 1).

filter ("BT". "ADMIT_DT" < TO_NUMBER(:3) + 7 AND "BT" "." " ADMIT_DT' > =: 2 AND

'BT '. "" ADMIT_DT "< = INTERNAL_FUNCTION ("JT". "ADMIT_DT") + (1.5) "

I have it!

I added / * + USE_CONCAT * / forces subquery and not it the PL/SQL plan of union the subqueries.

Hoek thanks for the link to the use of the tracing utility.

Jason

Tags: Database

Similar Questions

  • slow performance pl/sql for insert and update (pls suggestion) required

    DECLARE

    TYPE IS of LOC_USI_SEQ1 TABLE customer_TABLE.customereid%type;

    row_cnt number (19): = 0;

    CURSOR C1 IS

    SELECT customereid

    OF customer_TABLE

    WHERE customereid = 6316;

    LOC_USI_SEQ LOC_USI_SEQ1;

    BEGIN

    OPEN c1;

    C1 FETCH BULK COLLECT INTO LOC_USI_SEQ;

    Close c1;

    row_cnt: = LOC_USI_SEQ. Count;

    If row_cnt = 0 THEN

    INSERT INTO CUSTOMER_TABLE (CUSTOMEREID) VALUES (LOC_USI_SEQ);

    ON THE OTHER

    If row_cnt = 1 then

    Update customer_TABLE set id = 1 where CUSTOMEREID = LOC_USI_SEQ;

    INSERT INTO CUSTOMER_TABLE (CUSTOMEREID) VALUES (LOC_USI_SEQ);

    on the other

    If row_cnt = 2 then

    Update customer_TABLE set id = 2 where CUSTOMEREID = LOC_USI_SEQ;

    INSERT INTO CUSTOMER_TABLE (CUSTOMEREID) VALUES (LOC_USI_SEQ);

    end if;

    end if;

    end if;

    COMMIT;

    end;

    the query above works only for 1 customer id 6316. It runs in 1 sec.
    But if I run for the customer id 10 lakh of input parameter,
    (Whenever he runs for unique subscriber id) 10 times lachize it is running.
    update by inserting the customer_table table. it becomes slow. What is the real reason behind all this?


    Pls help gurus


    S

    Of course, it's slow.

    This is the perfect example of HOW not in PL/SQL code.

    Cursor fetch in PL/SQL loops are wrong 99% of the time. When you want to process the data in the database? Use SQL statements. Use SQL statements. And use SQL statements.

    No PL/SQL.

    Use INSERT... SELECT, MERGE, UPDATE (SELECT) and other SQL constructions.

    When you want to change it manually (where you manage the treatment), run this SQL via DBMS_PARALLEL_EXECUTE.

  • Looking for a better style or a way to write the INSERT statement, possible with brand of continuation

    Honestly, I really looked everywhere for this.

    The problem is that, while tinkering in SQL Developer and knowing that in the spreadsheet I can just execute individual instructions by placing the cursor on the SQL statement I want to run I tried to do an INSERT query that would allow me to run an INSERT statement for... Well many inserts.

    I thought I could use a brand of continuation but nothing I've tried has worked.

    INSERT INTO

    HF_easy_drinks

    VALUES

    ("Blackthorn", "tonic water", 1.5, 1.0, "pineapple juice", "mix with ice").

    ("Blue Moon", "soda", 1.5 "Blueberry Juice",. 75, "mix with ice, strain")

    ;


    I ended up doing just individual INSERT statements, which was not as convenient.

    INSERT INTO HF_easy_drinks

    VALUES ('Blackthorn', 'tonic water', 1.5, 1.0, "pineapple juice", "mix with ice");

    INSERT INTO HF_easy_drinks

    VALUES ('Blue Moon', 'soda', 1.5, 'Blueberry Juice',. 75, "mix with ice");

    Hello

    Perhaps you might prefer "an" insert like this:

    INSERT INTO hf_easy_drinks (x, y, z,...)
    SELECT "Blackthorn", "tonic water", 1.5, 1.0, "pineapple juice", "mix with ice" OF THE double
    UNION ALL SELECT 'Blue Moon', 'soda', 1.5, 'Blueberry Juice',. 75, "mix with ice, strain ' FROM dual
    SELECT UNION ALL... OF the double
    SELECT UNION ALL... OF the double
    ;

    Best regards

    Bruno Vroman.

  • Is possible to write the INSERT statement that fills two columns: 'word' and 'sense' of the file text with multiple lines - in each line is followed word that is the meaning?

    Is possible to write the INSERT statement that fills two columns: 'word' and 'sense' of the file text with multiple lines - in each line is followed word that is the meaning?

    Hello

    2796614 wrote:

    Is possible to write the INSERT statement that fills two columns: 'word' and 'sense' of the file text with multiple lines - in each line is followed word that is the meaning?

    Of course, it is possible.  According to what the text file looks like to, you can create an external table that treats the text file as if it were a table.  Otherwise, you can always read the file in PL/SQL, using the utl_file package and INSERT of PL/SQL commands.

    You have problems whatever you wantt?  If so, your zip code and explain what the problem is.

    Whenever you have any questions, please post a small example of data (CREATE TABLE and only relevant columns, INSERT statements) for all of the tables involved and the exact results you want from these data, so that people who want to help you can recreate the problem and test their ideas.  In this case, also post a small sample of the text involved file.

    If you ask about a DML operation, such as INSERT, then INSERT statements, you post should show what looks like the tables before the DML, and the results will be the content of the table changed after the DML.

    Explain, using specific examples, how you get these results from these data.

    Always say what version of Oracle you are using (for example, 11.2.0.2.0).

    See the FAQ forum: Re: 2. How can I ask a question on the forums?

  • Need help with the insert statement

    Hello

    I have a question on how to write a SQL statement.

    This is the table of "base":
    CREATE TABLE TEMP_TBL
    (
    id_nr NUMBER,
    DATE_DOK DATE,
    DATE_DUE DATE,
    DATE_DOK_PAY DATE,
    DEB NUMBER,
    KRD NUMBER
    );
    
    insert into temp_tbl (ID_NR,DATE_DOK,DATE_DUE,DATE_DOK_PAY,DEB,KRD)values('1',TO_DATE('11.01.2011','DD.MM.YYYY'),TO_DATE('25.02.2011','DD.MM.YYYY'),NULL,'423,24','0');
    insert into temp_tbl(ID_NR,DATE_DOK,DATE_DUE,DATE_DOK_PAY,DEB,KRD)values('2',TO_DATE('16.12.2011','DD.MM.YYYY'),TO_DATE('13.06.2011','DD.MM.YYYY'),NULL,'91270,15','0');
    insert into temp_tbl(ID_NR,DATE_DOK,DATE_DUE,DATE_DOK_PAY,DEB,KRD)values('3',TO_DATE('27.09.2011','DD.MM.YYYY'),TO_DATE('27.09.2011','DD.MM.YYYY'),NULL,'0','2000');
    and it comes to resoult in the target table. SQL statement must take care of the insert in a base of the target table table (example below is already provided with test data).
    create table table_sod
    (
    
          id_nr number
         ,date_from date
         ,date_to date
         ,deb_krd number
    
    );
    
    One thing to note here :  values in column deb_krd under insert 1 and 4 must be summarized in insert 4.
    
    insert into table_sod (id_nr,date_from,date_to,deb_krd) values('1',null,to_date('25.02.2011','dd.mm.yyyy'),'423,24');
    insert into table_sod(id_nr,date_from,date_to,deb_krd) values('2',to_date('26.02.2011','dd.mm.yyyy'),to_date('13.06.2011','dd.mm.yyyy'),'423,24');
    insert into table_sod(id_nr,date_from,date_to,deb_krd)values('3',null,to_date('13.06.2011','dd.mm.yyyy'),'91270,15');
    insert into table_sod(id_nr,date_from,date_to,deb_krd)values('4',to_date('14.06.2011','dd.mm.yyyy')to_date('27.09.2011','dd.mm.yyyy'),'91693,39');
    insert into table_sod(id_nr,date_from,date_to,deb_krd)values('5',null,to_date('27.09.2011','dd.mm.yyyy'),'2000');
    If someone could give me a helping hand how write correct insert statement I would be really gratefull.

    Thank you for your time!

    I came here with my own assumptions with this

    SQL> select rownum id_nr
      2       , date_from
      3       , date_to
      4       , case when date_from is null then deb
      5              else sum(case when date_from is not null then deb else 0end) over(order by id_nr, no)
      6         end deb_krd
      7    from (
      8            select id_nr
      9                 , case when lg_dt is null or ld_dt = date_due then  null else lg_dt+1 end date_from
     10                 , ld_dt date_to
     11                 , case when deb = 0 then krd else deb end deb
     12                 , no
     13              from (
     14                      select t1.*
     15                           , lead(t1.date_due) over(order by t1.id_nr, t2.no) ld_dt
     16                           , lag(t1.date_due) over(order by t1.id_nr, t2.no) lg_dt
     17                           , t2.no
     18                        from temp_tbl t1
     19                       cross
     20                       join (select 1 no from dual union all select 2 no from dual) t2
     21                       order by id_nr, no
     22                   )
     23             where ld_dt is not null
     24         )
     25  /
    
         ID_NR DATE_FROM DATE_TO      DEB_KRD
    ---------- --------- --------- ----------
             1           25-FEB-11      42324
             2 26-FEB-11 13-JUN-11      42324
             3           13-JUN-11    9127015
             4 14-JUN-11 27-SEP-11    9169339
             5           27-SEP-11       2000
     
    
  • exception in two places to insert statement

    Hi all

    I want to insert an exception to two places in pl sql. I get the error. Is it possible to apply the exception to two places in the insert statement.

    Thank you

    Uday


    Begin
    Declare
    Number of V_Code;
    V_Errm Varchar2 (64);
    Number of V_Code1;
    V_Errm1 Varchar2 (64);



    INSERT INTO recovery
    Select Employee_Id, salary * 1.1 employees
    Where Commission_Pct >. 2;
    EXCEPTION
    While others then
    V_Code: = Sqlcode;
    V_Errm: = Substr (Sqlerrm, 1, 64);
    Dbms_Output.put_line ("Error Code" |) V_Code | ': ' || V_Errm);

    Insert Into Scap_Fact_Loading_Errors Values (V_Code, V_Errm, Systimestamp);


    INSERT INTO recovery
    Select Employee_Id, salary * 1.1 employees
    Where Commission_Pct >. 1;
    EXCEPTION
    While other then V_Code1: = Sqlcode;
    V_Errm1: = Substr (Sqlerrm, 1, 64);
    Dbms_Output.put_line ("Error Code" |) V_Code1 | ': ' || V_Errm1);
    INSERT INTO Scap_Fact_Loading_Errors VALUES (v_code1, v_errm1, SYSTIMESTAMP);

    END;

    Published by: 929521 on January 7, 2013 10:15

    for example.

    Declare
      V_Code Number;
      V_Errm Varchar2(64);
      V_Code1 Number;
      V_Errm1 Varchar2(64);
    
    begin
    
      -- 1st begin .. end block
      begin
        INSERT INTO Raise
        Select Employee_Id, Salary*1.1 From Employees
         Where Commission_Pct > .2;
      EXCEPTION
        When Others Then
          V_Code := Sqlcode;
          V_Errm := Substr(Sqlerrm, 1, 64);
          Dbms_Output.Put_Line ('Error code ' || V_Code || ': ' || V_Errm);
          Insert Into Scap_Fact_Loading_Errors Values (V_Code, V_Errm, Systimestamp);
      end;
    
      -- 2nd begin .. end block
      begin
        INSERT INTO Raise
        Select Employee_Id, Salary*1.1 From Employees
         Where Commission_Pct > .1;
      EXCEPTION
        When Others Then V_Code1 := Sqlcode;
          V_Errm1 := Substr(Sqlerrm, 1, 64);
          Dbms_Output.Put_Line ('Error code ' || V_Code1 || ': ' || V_Errm1);
          INSERT INTO Scap_Fact_Loading_Errors VALUES (v_code1, v_errm1, SYSTIMESTAMP);
      end;
    
    end;
    
  • Help with the insert statement

    Hello

    I was wondering if someone could help write me a sql statement.

    Here is my table:
    CREATE TABLE "TEMP_INVOICE" 
       ("INVOICE" VARCHAR2(100 BYTE),
         "DATE_OF_DOCUMENT" DATE, 
         "DATE_OF_PAY_DAY" DATE, 
         "D" NUMBER, 
         "K" NUMBER
       );
    Here are the instructions for correct insertion. This time, I posted 2 examples with 2 numbers different otherwise.
    insert into temp_invoice (invoice,DATE_OF_DOCUMENT,DATE_OF_PAY_DAY,d,k)  values (1000,to_date('01.02.2012','dd.mm.yyyy'),to_date('01.03.2012','dd.mm.yyyy'),5000,0);
     
    insert into temp_invoice (invoice,DATE_OF_DOCUMENT,DATE_OF_PAY_DAY,d,k)  values (1000,to_date('01.04.2012','dd.mm.yyyy'),'','',1000);
     
    insert into temp_invoice (invoice,DATE_OF_DOCUMENT,DATE_OF_PAY_DAY,d,k)  values (1000,to_date('01.05.2012','dd.mm.yyyy'),'','',3000);
     
    insert into temp_invoice (invoice,DATE_OF_DOCUMENT,DATE_OF_PAY_DAY,d,k)  values (1000,to_date('01.06.2012','dd.mm.yyyy'),'','',1000);
    
    insert into temp_invoice (invoice,DATE_OF_DOCUMENT,DATE_OF_PAY_DAY,d,k)  values (2000,to_date('01.07.2012','dd.mm.yyyy'),to_date('01.09.2012','dd.mm.yyyy'),8000,0);
     
    insert into temp_invoice (invoice,DATE_OF_DOCUMENT,DATE_OF_PAY_DAY,d,k)  values (2000,to_date('01.10.2012','dd.mm.yyyy'),'','',5000);
     
    insert into temp_invoice (invoice,DATE_OF_DOCUMENT,DATE_OF_PAY_DAY,d,k)  values (2000,to_date('01.11.2012','dd.mm.yyyy'),'','',2000);
     
    insert into temp_invoice (invoice,DATE_OF_DOCUMENT,DATE_OF_PAY_DAY,d,k)  values (2000,to_date('01.12.2012','dd.mm.yyyy'),'','',1000);
    I want to do is make an insert allows you to table another call is MADE:
    CREATE TABLE "INVOICE" 
       ("INVOICE" VARCHAR2(100 BYTE),
        "DATE_OF_DOCUMENT" DATE, 
         "DATE_OF_PAY_DAY" DATE,
         "DATE_OF_PAYMENT_REC" DATE,
         "VALUE" NUMBER,
         "VALUE_DEDUCT" NUMBER,
        "DATE_FROM" DATE,     
         "DATE_TO" DATE
         );
    Statements in the INVOICE table should be like this:


    ........ The Bill... date_of_document... date_of_pay_day... date_of_payment_rec... value... value_deduct... Date_from... Date_to
    1......     1000...............1.1.2012.................1.3.2012................NULL............................ 5000... NULL... 1.3.2012...1.4.2012
    2......     1000...............1.4.2012.................NULL..................... 1.4.2012...1000... 4000... 2.4.2012... 1.5.2012
    3......     1000...............1.5.2012.................NULL..................... 1.5.2012...3000... 1000... 2.5.2012... 1.6.2012
    4......     1000...............1.6.2012.................NULL..................... 1.6.2012...1000


    Can someone help me with the sql statement that would insert data from table to table Bill temp_invoice as in the example?

    Thank you!

    PS

    I would try to explain.
    (1) the first statement that is to be inserted is original imply that at which is different DATE_OF_PAY_DAY to NULL.
    To this inserted negative of the original imply, we must add date_from that is exatly the same date_of_pay_day and date_to which is exactly the same as the date of the first payment. Payment which came first!
    (2) we have now in the second insert statement. It will be the first payment of lease with date_of_document and date_pf_payment_rec, which is the same as date_fo_document. Value field will be populated with the amount of payment received and value_deduct field will be the value of the original imply - value of the first payment. Date is date_of_document + 1 and date_to is the date of the next payment.
    (3) Insert us the next installment. Date_od_payment_rec is the same as date_of_document... value is the amount of the second payment and value_deduct's previous value_deduct which was of 4000 - value of this second payment. date_from date_of_payment_rec + 1 and date_to is the date of the next payment

    So we continue this same pattern until we reached the final payment when we finish insert with the statement:
    Date of the document (date of the last payment received) and even for date_of_payment_rec and field value with the amount of the payment receieved. The rest (value_deduct, date_from, date_to) is null.

    I really hope you understand what I'm trying to do here.

    If you have any other questions please.

    Published by: user13071990 on November 22, 2012 04:16

    Published by: user13071990 on November 22, 2012 04:16

    Hello

    user13071990 wrote:
    ... Here are the instructions for correct insertion. This time, I posted 2 examples with 2 numbers different otherwise.

    Ok!
    Be sure to post the results you want new data.

    You probably need to add "PARTITION BY the Bill" to all analytical clauses in my solution:

    INSERT INTO invoice
    ( invoice, date_of_document, date_of_pay_day, date_of_payment_rec
    , value,   value_deduct,     date_from,           date_to
    )
    SELECT       invoice
    ,       date_of_document
    ,       date_of_pay_day
    ,       CASE
               WHEN  k > 0
               THEN  date_of_document
           END          AS date_of_payment_rec
    ,       NVL (d, k)     AS value
    ,       NVL2 ( date_of_pay_day
                , NULL
                , SUM (d) OVER ( PARTITION BY  invoice
                                          ORDER BY      date_of_document
                         )
                - SUM (k) OVER ( PARTITION BY  invoice
                                          ORDER BY      date_of_document
                         )
                )     AS value_deduct
    ,       NVL ( date_of_pay_day
               , date_of_document + 1
               )          AS date_from
    ,       LEAD (date_of_document) OVER ( PARTITION BY  invoice
                                            ORDER BY      date_of_document
                               )
                          AS date_to
    FROM       temp_invoice
    ;
    

    Because I'm not an English speaker nativ, that I just posted what it should look like after the insert is successful.

    OK, so you can't explain as you want, but you still need to explain.

    ... @Frank Kulash: you are very close, but still not quite what I'm looking for.

    Point out where my solution is the production of incorrect results, and explain (as you can) how to get good results in these places.

  • Ignore the duplicates on Insert statement

    I'm trying to create a script to import a CSV file into a MySQL database.   The script works very well.   However, it occurred to me that there could be duplicates to a certain point in time.

    How do I get this to only insert records that are not already in the database?    Please keep in mind that an excel sheet may have tens or hundreds of thousands of records when inserting.

    Any ideas?   Here is my code so far:

    <?php
    if(isset($_POST["Import"]))
    {
    $host="localhost";
    $db_user="***";
    $db_password="***";
    $db='test';
    $conn=mysql_connect($host,$db_user,$db_password) or die (mysql_error());
    mysql_select_db($db) or die (mysql_error());
    
    
    echo $filename=$_FILES["file"]["tmp_name"];
    //echo $ext=substr($filename,strrpos($filename,"."),(strlen($filename)-strrpos($filename,".")));
    
    
    
    
     if($_FILES["file"]["size"] > 0)
     {
    
    
      $file = fopen($filename, "r");
             while (($emapData = fgetcsv($file, 10000, ",")) !== FALSE)
             {
                
                $sql = "INSERT into leads2(fname, lname, dog) values('$emapData[0]','$emapData[1]','$emapData[2]')";
                mysql_query($sql);
             }
             fclose($file);
             echo "SUCCESS!";
     }
     else
     echo "FAILED!";
    
    
    }
    ?>
    

    Two ways I can think of. First is to check if the primary key exists before executing the insert statement. This is going to be an expensive operation with 100K of records! A better solution would be to use a load operation into a temporary table and then use an INSERT INTO... SELECT FROM... Statement from the temporary table to the table live. You can use a where clause, group by clause clause or the DISTINCT keyword in select it remove all dupes.

    at http://www.mysqlfaqs.net/MySQL-FAQs/Data-back-up/Import-Data/How-to-use-LOAD-DATA-INFILE-s

  • Help! Using CFQUERYPARAM in INSERT statements causes NullPointerException?

    Hi all

    I've never used cfqueryparam with the INSERT statement in cfquery before, but now whenever I have it try, I have a NullPointerException.

    My code:

    < name cfquery = "insertDocEntry."
    result = "docEntry."
    DataSource = "#application. PrimaryDataSource #">"
    INSERT INTO tbl_conference_document
    (SessionID, DocTypeID, symbol, language, Title)
    VALUES)
    < cfqueryparam value = "" #Form.SessionID # "cfsqltype ="cf_sql_numeric">,"
    < cfqueryparam value = "" #Form.DocTypeID # "cfsqltype ="cf_sql_numeric">,"
    < cfqueryparam value = "" #Form.Symbol # "cfsqltype ="cf_sql_varchar">,"
    < cfqueryparam value = "" #Form.Language # "cfsqltype ="cf_sql_varchar">,"
    < cfqueryparam value = "" #Form.Title # "cfsqltype ="cf_sql_varchar">"
    )
    < / cfquery >

    I cfdump the form field and all values are defined, but I always get this error:

    The web site, you access has met an unexpected error.
    Please contact the site administrator.

    The following information is for the creation of Web sites for debugging purposes.
    Error occurred while processing request
    The system has attempted to use an undefined value, which usually indicates an error programming, either in your code or system code.

    NULL pointers are another name for undefined values.

    The error occurred in D:\ColdFusion9\wwwroot\Infobase\Document\execConferenceDocUpload.cfm: line 28

    26 :       <cfqueryparam value="#Form.Symbol#" cfsqltype="cf_sql_varchar">,
    27 :       <cfqueryparam value="#Form.Language#" cfsqltype="cf_sql_varchar">,
    28 :       <cfqueryparam value="#Form.Title#" cfsqltype="cf_sql_varchar">
    29 :     )
    30 :    </cfquery>

    Resources:

    BrowserMozilla/5.0 (Windows; U; Windows NT 5.1; en-US; RV:1.9.2.8) Gecko/20100722 Firefox/3.6.8
    Remote address127.0.0.1
    Referrerhttp://localhost:8501/Infobase/document/uploadConferenceDoc.cfm
    Date/time3 Aug 10 11:48
    Stack trace
    at cfexecConferenceDocUpload2ecfm1876641633.runPage (D:\ColdFusion9\wwwroot\Infobase\Document \execConferenceDocUpload.cfm:28) to cfApplication2ecfc1086350920$ funcONREQUEST.runFunction (D:\ColdFusion9\wwwroot\Infobase\Ap plication.cfc:230)

    java.lang.NullPointerException
         at coldfusion.sql.QueryTable.populate(QueryTable.java:325)
         at coldfusion.sql.QueryTable.populate(QueryTable.java:261)
         at coldfusion.sql.Executive.getRowSet(Executive.java:466)
         at coldfusion.sql.Executive.executeQuery(Executive.java:1248)
         at coldfusion.sql.Executive.executeQuery(Executive.java:1008)
         at coldfusion.sql.Executive.executeQuery(Executive.java:939)
         at coldfusion.sql.SqlImpl.execute(SqlImpl.java:341)
         at coldfusion.tagext.sql.QueryTag.executeQuery(QueryTag.java:843)
         at coldfusion.tagext.sql.QueryTag.doEndTag(QueryTag.java:533)
         at cfexecConferenceDocUpload2ecfm1876641633.runPage(D:\ColdFusion9\wwwroot\Infobase\Document\execConferenceDocUpload.cfm:28)
         at coldfusion.runtime.CfJspPage.invoke(CfJspPage.java:231)
         at coldfusion.tagext.lang.IncludeTag.doStartTag(IncludeTag.java:416)
         at coldfusion.runtime.CfJspPage._emptyTcfTag(CfJspPage.java:2722)
         at cfApplication2ecfc1086350920$funcONREQUEST.runFunction(D:\ColdFusion9\wwwroot\Infobase\Application.cfc:230)
         at coldfusion.runtime.UDFMethod.invoke(UDFMethod.java:472)
         at coldfusion.runtime.UDFMethod$ReturnTypeFilter.invoke(UDFMethod.java:405)
         at coldfusion.runtime.UDFMethod$ArgumentCollectionFilter.invoke(UDFMethod.java:368)
         at coldfusion.filter.FunctionAccessFilter.invoke(FunctionAccessFilter.java:55)
         at coldfusion.runtime.UDFMethod.runFilterChain(UDFMethod.java:321)
         at coldfusion.runtime.UDFMethod.invoke(UDFMethod.java:220)
         at coldfusion.runtime.TemplateProxy.invoke(TemplateProxy.java:490)
         at coldfusion.runtime.TemplateProxy.invoke(TemplateProxy.java:336)
         at coldfusion.runtime.AppEventInvoker.invoke(AppEventInvoker.java:88)
         at coldfusion.runtime.AppEventInvoker.onRequest(AppEventInvoker.java:280)
         at coldfusion.filter.ApplicationFilter.invoke(ApplicationFilter.java:338)
         at coldfusion.filter.RequestMonitorFilter.invoke(RequestMonitorFilter.java:48)
         at coldfusion.filter.MonitoringFilter.invoke(MonitoringFilter.java:40)
         at coldfusion.filter.PathFilter.invoke(PathFilter.java:87)
         at coldfusion.filter.LicenseFilter.invoke(LicenseFilter.java:27)
         at coldfusion.filter.ExceptionFilter.invoke(ExceptionFilter.java:70)
         at coldfusion.filter.ClientScopePersistenceFilter.invoke(ClientScopePersistenceFilter.java:28)
         at coldfusion.filter.BrowserFilter.invoke(BrowserFilter.java:38)
         at coldfusion.filter.NoCacheFilter.invoke(NoCacheFilter.java:46)
         at coldfusion.filter.GlobalsFilter.invoke(GlobalsFilter.java:38)
         at coldfusion.filter.DatasourceFilter.invoke(DatasourceFilter.java:22)
         at coldfusion.filter.CachingFilter.invoke(CachingFilter.java:53)
         at coldfusion.filter.RequestThrottleFilter.invoke(RequestThrottleFilter.java:126)
         at coldfusion.CfmServlet.service(CfmServlet.java:200)
         at coldfusion.bootstrap.BootstrapServlet.service(BootstrapServlet.java:89)
         at jrun.servlet.FilterChain.doFilter(FilterChain.java:86)
         at coldfusion.monitor.event.MonitoringServletFilter.doFilter(MonitoringServletFilter.java:42)
         at coldfusion.bootstrap.BootstrapFilter.doFilter(BootstrapFilter.java:46)
         at jrun.servlet.FilterChain.doFilter(FilterChain.java:94)
         at jrun.servlet.FilterChain.service(FilterChain.java:101)
         at jrun.servlet.ServletInvoker.invoke(ServletInvoker.java:106)
         at jrun.servlet.JRunInvokerChain.invokeNext(JRunInvokerChain.java:42)
         at jrun.servlet.JRunRequestDispatcher.invoke(JRunRequestDispatcher.java:286)
         at jrun.servlet.ServletEngineService.dispatch(ServletEngineService.java:543)
         at jrun.servlet.http.WebService.invokeRunnable(WebService.java:172)
         at jrunx.scheduler.ThreadPool$DownstreamMetrics.invokeRunnable(ThreadPool.java:320)
         at jrunx.scheduler.ThreadPool$ThreadThrottle.invokeRunnable(ThreadPool.java:428)
         at jrunx.scheduler.ThreadPool$UpstreamMetrics.invokeRunnable(ThreadPool.java:266)
         at jrunx.scheduler.WorkerThread.run(WorkerThread.java:66)

    This error does NOT occur when I don't use cfqueryparam, but my problem is, I need to insert a downloaded file in the database as a BLOB (code not shown above because it is a problem even without BLOB), so far the only way I know how is it to use CFQUERYPARAM.

    Am I the only one seeing this here? So far I only tried to use my CF9 local server (developer edition), the server of CF9 on my colleague has the same problem.

    Here we have a very tight schedule and I really wasn't expecting this kind of problems, so any help and advice is much appreciated!

    Thanks in advance!

    ZHU, Jia

    Yes, I don't think there was a data type mismatch. I was just trying to get more clues on the circumstances in which the error occurs. In other words, it happens every time cfqueryparam is used... or simply when certain types of data are used. Because surely it should not happen.  Maybe a level driver problem, what I do usually is set up a few test cases fast, ideally very simple.  Then use this to determine if there are exceptions to the main issue.  Thus, for example, things like the exception occurs even with a simple insert a column with a varchar column base

    INSERT INTO TestTable (VarcharCol) VALUES ( )

    Also, have you experienced the same results with the jtds driver?

  • LogMiner does not list INSERT statements

    Hello

    does anyone know why logminer does not INSERT statements? I have this problem on a 10.2.0.4 database. On a 11.2.0.1 database are, no problem.

    Unit test:
    SQL> select * from v$version;
    
    BANNER
    ----------------------------------------------------------------
    Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - Prod
    PL/SQL Release 10.2.0.4.0 - Production
    CORE    10.2.0.4.0      Production
    TNS for 32-bit Windows: Version 10.2.0.4.0 - Production
    NLSRTL Version 10.2.0.4.0 - Production
    
    SQL> select supplemental_log_data_min from v$database;
    
    SUPPLEME
    --------
    NO
    
    SQL> select sequence# from v$log where status = 'CURRENT';
    
     SEQUENCE#
    ----------
           180
    
    SQL> create table scott.test_load (id number);
    
    Table created.
    
    SQL> insert into scott.test_load select rownum r from user_objects where rownum <= 10;
    
    10 rows created.
    
    SQL> commit;
    
    Commit complete.
    
    SQL> select sequence# from v$log where status = 'CURRENT';
    
     SEQUENCE#
    ----------
           180
    
    SQL> alter system archive log current;
    
    System altered.
    
    SQL> select sequence# from v$log where status = 'CURRENT';
    
     SEQUENCE#
    ----------
           181
    
    SQL> select name from v$archived_log where sequence#=180;
    
    NAME
    --------------------------------------------------------------------------------------------------------
    C:\ORACLE10G\PRODUCT\10.2.0\FLASH_RECOVERY_AREA\TEST10G\ARCHIVELOG\2010_09_08\O1_MF_1_180_68H49WQS_.ARC
    
    SQL> exec sys.dbms_logmnr.add_logfile('C:\ORACLE10G\PRODUCT\10.2.0\FLASH_RECOVERY_AREA\TEST10G\ARCHIVELOG\2010_09_08\O1_MF_1_180_68H49WQS_.ARC');
    
    PL/SQL procedure successfully completed.
    
    SQL> exec sys.dbms_logmnr.start_logmnr(options=>sys.dbms_logmnr.dict_from_online_catalog);
    
    PL/SQL procedure successfully completed.
    
    SQL> select seg_owner, seg_name, to_char(timestamp,'mm/dd/yy hh24:mi:ss') timestamp, sql_redo
      2      from v$logmnr_contents
      3      where table_name = 'TEST_LOAD';
    
    SEG_OWNER  SEG_NAME             TIMESTAMP         SQL_REDO
    ---------- -------------------- ----------------- ---------------------------------------------
    SCOTT      TEST_LOAD            09/08/10 15:35:29 create table scott.test_load (id number);
    
    SQL>
    While the DDL part is present. If the minimum additional logging is enabled, INSERT statements are visible also in 10.2.0.4 (in 11.2.0.1, they are also visible if additional logging is disabled). Anyone know the reason of such behaviour in 10.2.0.4?

    I ask because I have a 10.2.0.4 database production that has not allowed an additional minimum logging. It seems there were a few 'ad hoc' changes in some tables, and because we have not enabled the audit, I tried to see if something can be found in the recovery logs archived. I searched on them and I have not found anything. Anyway, as the unit test above shows, I can't be sure if there was in fact no change to the data or only logminer recount not the...


    Thank you very much in advance and greetings.
    Swear

    Hello

    By default, the Oracle 10.2.0.4 database - does not provide any additional registration, which means that default LogMiner is not usable. Because of which you might not see the results.

    -Pavan Kumar N

  • need help to create the insert statement

    I have customer_priv of table which has 4 columns (login, privilize_id, adate, added_by)

    the stmt insert like "insert into customer_priv values('JDOE',951.sysdate,admin);

    I have 100 users and for each user, I need to add to the 15 privilize_id

    I have the list of connections and roles, what is the best way to create a massive insert for all those users statement and

    any help is very appreciated

    Thank you

    user11984714 wrote:
    Thanks Frank

    I get the below now.what Miss. Also is it possible to reel in a file insert rather directly the data.am I missing values?

    Sorry, I don't understand what you want.
    You say you want to write something in a HOLD file instead of insert? Of course, you can do it. Change the INSERT statement in a SELECT statement and add commands to the COIL.

    SQL > @c:\insert_many.sql
    33 old: SELECT ' & 1' priv_id, 'admin', sysdate)
    33 News: SELECT sysdate, "BNELSON", "admin", priv_id)

    Of all_priv_id
    *
    ERROR on line 34:
    ORA-00923: THE KEYWORD not found where expected
    Thank you

    Published by: user11984714 on August 9, 2010 18:40

    Sorry, there was a typing error in my previous post.
    Remove the ')' the end of the

    SELECT     '&1', privilze_id, SYSDATE, 'admin')
    

    I hope that you have more problems, but if you do, post your code, even if you think that you just copied it from this site.

  • Generate the insert statement using columns in view all_tab_cols

    I am trying to generate a dynamic insert statement using the columns of a table in the all_tab_cols view. If I do a select, I get the result as lines. How to convert the row of the columns so that I get something like this:
     INSERT INTO TABLE_NAME (COL1, COL2, COL3,COL4.....) 
    .

    Any help will be appreciated!

    This can give you a tip.

    SQL> ed
    Wrote file afiedt.buf
    
      1  with tab_col
      2  as
      3  (
      4  select i.table_name,
      5         column_name,
      6         row_number() over(partition by i.table_name order by table_name) rno
      7    from user_tab_cols i
      8  )
      9  select 'INSERT INTO '||table_name||' ('||ltrim(sys_connect_by_path(column_name, ','), ',')||')
     10    from tab_col
     11   where connect_by_isleaf = 1
     12   start with rno = 1
     13  connect by rno = prior rno+1
     14     and table_name = prior table_name
     15* and rownum<4
    SQL> /
    
    SQL_STATEMENT
    --------------------------------------------------------------------------------
    INSERT INTO A (MAKER,TYPE)
    INSERT INTO ADAM_TEST (ACCT,CODE)
    INSERT INTO AREA_TBL (AREA_ID,ORG_ID,CLUSTER_ID)
    INSERT INTO B (MAKER)
    INSERT INTO BONUS (ENAME)
    INSERT INTO CLUSTER_TBL (CLUSTER_ID)
    INSERT INTO COMPANY (MANUFACTURER)
    INSERT INTO COUNTRIES (COUNTRY_ID)
    
  • NDS Insert statement glitch

    DB version XE 10 g

    Hello

    I have little problem with my insert statement.

    In my code, the examples are numerous, but please focus on the part V2 and V3.

    As you can see V2 and V3 will not work

    I get the following errors

    V2
    Error report:
    ORA-00984: column not allowed here
    ORA-06512: at line 28
    00984 00000 - "unauthorized column here.

    V3
    Error report:
    ORA-00917: lack of comma
    ORA-06512: at line 33
    00917 00000 - "missing comma.

    I have no idea why I get these errors...
    DROP TABLE FILMYARNOLD;
    
    CREATE TABLE FILMYARNOLD
    (
        FIL_ID VARCHAR2 (329),
        FIL_NAME VARCHAR2 (592),
        FIL_YEAR VARCHAR2 (294),
        FIL_ACTOR VARCHAR2 (392),
        FIL_TEXTT VARCHAR2 (2596)
    );
    
    
    
    SET SERVEROUTPUT ON
    DECLARE
      TYPE FIL_TABLE IS TABLE OF VARCHAR2 (256);
      vfilmiczki FIL_TABLE := fil_table();
      statement VARCHAR2 (2048);
    BEGIN
    vfilmiczki.EXTEND;
    vfilmiczki(1) := '77804';
    vfilmiczki.EXTEND;
    vfilmiczki(2) := 'Predator';
    vfilmiczki.EXTEND;
    vfilmiczki(3) := '1984';
    vfilmiczki.EXTEND;
    vfilmiczki(4) := 'Arnold';
    vfilmiczki.EXTEND;
    vfilmiczki(5) := 'get to the choppa';
    /*statement := 'INSERT INTO FILMYARNOLD (FIL_ID, FIL_NAME, FIL_YEAR, FIL_ACTOR, FIL_TEXTT) VALUES ( ';
    statement := statement|| '''chlip'',''lol'',''lol'',''chlip''';--
    statement := statement||',''hmm'')';*/
    -------------------------------
    -------V1------------working-----------------
    --statement := 'INSERT INTO FILMYARNOLD (FIL_ID) VALUES ( ';
    --statement := statement||vfilmiczki(1)||' )';
    --EXECUTE IMMEDIATE statement;
    -----------------------------------
    --------V2-------------------- not working -----------------------------------------
    --statement := 'INSERT INTO FILMYARNOLD (FIL_ID, FIL_NAME) VALUES ( ';
    --statement := statement||vfilmiczki(1)||','||vfilmiczki(2)||' )';
    --EXECUTE IMMEDIATE statement;
    --------------------------------------------
    ----V3------------ not working ------------
    statement := 'INSERT INTO FILMYARNOLD (FIL_ID, FIL_NAME, FIL_YEAR, FIL_ACTOR, FIL_TEXTT) VALUES ( ';
    statement := statement||vfilmiczki(1)||','||vfilmiczki(2)||','||vfilmiczki(3)||','||vfilmiczki(4)||','||vfilmiczki(5)||' )';
    EXECUTE IMMEDIATE statement;
    ------------------------------------------------------
    /* statement := 'INSERT INTO FILMYARNOLD VALUES (:jeden, :dwa, :trzy, :cztery, :piec)';
    EXECUTE IMMEDIATE statement
      USING vfilmiczki(1)
      ,     vfilmiczki(2)
      ,     vfilmiczki(3)
      ,     vfilmiczki(4)
      ,     vfilmiczki(5); */
      /*
      statement := 'INSERT INTO FILMYARNOLD VALUES ('; --(:jeden, :dwa, :trzy, :cztery, :piec)';
        FOR i IN 1..vfilmiczki.COUNT
        LOOP
            IF i = vfilmiczki.LAST THEN
                statement := statement||vfilmiczki(i)||' )';
            ELSE
            statement := statement||vfilmiczki(i)||', ';
          END IF;
            --DBMS_OUTPUT.PUT_LINE (vfilmiczki(i));
        END LOOP;
        EXECUTE IMMEDIATE statement;
        */
        --INSERT INTO FILMYARNOLD 
        --VALUES (vfilmiczki(vfilmiczki.FIRST),vfilmiczki(2),vfilmiczki(3),
                --vfilmiczki(4), vfilmiczki(5)); 
        --DBMS_OUTPUT.PUT_LINE ('*****************');
        --DBMS_OUTPUT.PUT_LINE (vfilmiczki((vfilmiczki.LAST)));
    END;
    /
    IM waiting for your responses

    Greetings

    Hello

    change V2 to:

    STATEMENT := 'INSERT INTO FILMYARNOLD (FIL_ID, FIL_NAME) VALUES ( ';
    STATEMENT := STATEMENT||VFILMICZKI(1)||','''||VFILMICZKI(2)||''' )';
    EXECUTE IMMEDIATE statement;
    

    and V3 for:

    ----V3------------ not working ------------
    STATEMENT := 'INSERT INTO FILMYARNOLD (FIL_ID, FIL_NAME, FIL_YEAR, FIL_ACTOR, FIL_TEXTT) VALUES ( ';
    STATEMENT := STATEMENT||VFILMICZKI(1)||','''||VFILMICZKI(2)||''','||VFILMICZKI(3)
                 ||','''||VFILMICZKI(4)||''','''||VFILMICZKI(5)||''' )';
    EXECUTE IMMEDIATE statement;EXECUTE IMMEDIATE statement;
    

    A general remark: INSERT can be used directly in PL/SQL, you don't need to bother with dynamic SQL statements.
    and the PASS-THROUGH is probably more effective than dynamic SQL.

    Try this:

    SET SERVEROUTPUT ON
    DECLARE
      TYPE FIL_TABLE IS TABLE OF VARCHAR2 (256);
      vfilmiczki FIL_TABLE := fil_table();
      statement VARCHAR2 (2048);
    BEGIN
    vfilmiczki.EXTEND;
    vfilmiczki(1) := '77804';
    vfilmiczki.EXTEND;
    vfilmiczki(2) := 'Predator';
    vfilmiczki.EXTEND;
    vfilmiczki(3) := '1984';
    vfilmiczki.EXTEND;
    vfilmiczki(4) := 'Arnold';
    vfilmiczki.EXTEND;
    vfilmiczki(5) := 'get to the choppa';
    
    -------V1------------working-----------------
    INSERT INTO  FILMYARNOLD (FIL_ID) VALUES ( VFILMICZKI(1) );
    
    --------V2-------------------- not working -----------------------------------------
    INSERT INTO FILMYARNOLD (FIL_ID, FIL_NAME) VALUES ( VFILMICZKI(1),VFILMICZKI(2));
    
    ----V3------------ not working ------------
    INSERT INTO FILMYARNOLD (FIL_ID, FIL_NAME, FIL_YEAR, FIL_ACTOR, FIL_TEXTT)
    VALUES ( VFILMICZKI(1), VFILMICZKI(2), VFILMICZKI(3), VFILMICZKI(4), VFILMICZKI(5));
    
    END;
    / 
    
  • value of the check box in the insert statement

    I'm hand-coding an insert from the insert record sb construction will do for this application. The values of several form elements are inserted into the fields in the table. The problem that occur is a checkbox value in the form. If the box is checked, all is well and the value is 'True' inserted in the appropriate database field. However, if the checkbox is not checked I get syntax error message. The reason being that, while are passed on to the fields with null null, the checkbox is not transmitted at all. This is evident when changing the method of the form to 'Get' for testing purposes. There is no reference to this field check box in the query string.

    My assumption is that this would require an If statement changing the value of the 'False' check box when the box is blocked. How I would go to this topic. With my knowledge limited to the ASP, I wrote the following, but it doesn't seem to work:

    < input name = "emailprob_mor" type = "checkbox" id = "emailprob_mor" value = "< % If Not (IsNull (Request.Form ("emailprob_cus")) then Response.Write"True") Else Response.Write ("False") End If % >" >

    When you use the boxes, it is better to separate your Request.Form statement and your insert statement:

    cbVal = '0 '.
    If (Request.Form ("emailprob_mor") <> "") then cbVal = Request.Form ("emailprob_mor")

    Then in your SQL statement:

    "& cbVal &"..."

    For your real HTML:

    "" ) then response.write(" checked='checked' ") %>>

    It is true that if the user does not check the box, then it appears as if there is no when it is submitted, that is the reason why he must be given a default value when the record is inserted.

  • Simple Insert statement does not

    This problem is just driving me crazy. I don't know what I'm doing wrong here. The code works fine on my localhost, but gives the problem on the site online. It's a simple insert like this:

    insert into tblSubImages (productid, title, subdescription, image, location) values (#form.productid #, ' #form.title #',' #form.subdescription #',' #uploadedimage # ", #form.place #")

    The error I m to looks like this:

    Syntax error in INSERT INTO statement.

    The error occurred in D:\Hosting\davedhillon\superprinters\admin\addaditional.cfm: line 11

    9: < cfset uploadedImage = cffile.serverfile >
    10: < cfquery name = "insertadditional" datasource = "#super.dsn #" >
    11: insertion in values(#form.productid#,'#form.title#','#form.subdescription#','#uploadedimage#') tblSubImages (productid, title, subdescription, image)
    12: < / cfquery >
    13:



    --------------------------------------------------------------------------------

    SQL insert into values(1,'ewr','werw','FamilyRoomBedroom.jpg') tblSubImages (productid, title, subdescription, image)
    Davedhillon_accesscf_super DATA source
    VENDORERRORCODE 3092

    You can see that it is the simple insert statement that I worked with so many times. Why he started giving problems all of a sudden?

    Thank you

    'Image' can be a reserved word. What happens if you do this?

    insert into tblSubImages (productid, title, subdescription, [image])
    values (...)

Maybe you are looking for