Passing sequence nextval in insert statement

Hi,
Want to insert a record in table A using incremented sequence value to be get inserted in the ID column of table.
ID column is having a primary key constraint
created sequence test1_seq for that table
How to use this sequence number's NEXTVAL to be get inserted in ID column of table A, along with other data.
How to pass the values to the below procedure for inserting record ?
There are total six fields in the column
execute pk_test1.insert_test1('*How to pass next sequence value here ?*','rec2','rec3','rec4','rec5','rec6')
With Regards
Edited by: user640001 on Aug 10, 2010 12:25 AM

Check this: You can create a trigger to insert a sequence value in to a table for every insert that happens:
SQL> create table my_Test1(col1 number,col2 VARCHAR2(100));
Table created.
SQL> ed
Wrote file afiedt.buf
  1  create sequence test1_seq
  2  start with 1
  3  increment by 1
  4  maxvalue 999999999
  5  nocycle
  6  nocache
  7* noorder
SQL> /
SQL> ed
Wrote file afiedt.buf
  1  create or replace package pkg1_test as
  2  procedure insert_tab1(p_val1 VARCHAR2);
  3* end;
SQL> /
Package created.
SQL> ed
Wrote file afiedt.buf
  1  create or replace package body pkg1_test as
  2  procedure insert_tab1(p_val1 varchar2) is
  3  begin
  4  insert into my_test1(col2) values(p_val1);
  5  COMMIT;
  6  END;
  7* end;
SQL> /
Package body created.
SQL> create trigger my_trig1 before insert on my_test1
  2  for each row
  3  declare
  4  v_seqno NUMBER := 0;
  5  BEGIN
  6  SELECT test1_seq.nextval into v_seqno from dual;
  7  :new.col1 := v_seqno;
  8  end;
  9  /
Trigger created.
SQL> exec pkg1_test.insert_tab1(100);
PL/SQL procedure successfully completed.
SQL> select * from my_Test1;
      COL1 COL2
         1 ABCD
         2 100
SQL> select test1_seq.currval from dual;
   CURRVAL
         2
SQL> Edited by: AP on Aug 10, 2010 12:38 AM

Similar Messages

  • USE sequence.nextval in SQL statement

    Hi,
    I want to use SEQUENCE_name.NEXVAL in our query.
    But it gives error
    ora-02287: sequence number not allowed here
    Select distinct dd.agreementid,dd.cityid,dd.bankid,dd.bankbranchid,zz.bankbranchdesc,
    account_no,account_type,Sysdate,'A',Null,'1001',Sysdate,NULL,NULL,
    ELEC_PMNT_SEQ.Nextval seq_num
    From pdi.pdi_instr_d_tmp dd,
    pdi.pdi_bankbranch_m zz,
    pdi.pdi_bankaccount_tmp t
    Where t.agreementid = dd.agreementid
    And dd.cityid = zz.cityid
    And dd.bankid = zz.bankid
    And dd.bankbranchid= zz.bankbranchid
    And dd.mc_status = 'M' And dd.status = 'M' And instr_type <> 'P'
    Thanks & Regards
    K S Ratan

    You can use a subquery, but maybe have you need an order by clause ?
    SQL> ed
    Wrote file afiedt.buf
      1* select distinct username, MySeq.nextval from dba_users
    SQL> /
    select distinct username, MySeq.nextval from dba_users
    ERROR at line 1:
    ORA-02287: sequence number not allowed here
    SQL> ed
    Wrote file afiedt.buf
      1  select a.*, MySeq.nextval
      2* from (select distinct username from dba_users order by username) a
    SQL> /
    USERNAME                          NEXTVAL
    DBSNMP                                  1
    H89UCBAC                                2
    OUTLN                                   3
    PEOPLE                                  4
    PS                                      5
    SYS                                     6
    SYSTEM                                  7
    7 rows selected.
    SQL> /
    USERNAME                          NEXTVAL
    DBSNMP                                  8
    H89UCBAC                                9
    OUTLN                                  10
    PEOPLE                                 11
    PS                                     12
    SYS                                    13
    SYSTEM                                 14
    7 rows selected.Is this do you want ? Sequence will increment on each query execution, or did you want the number of output line to have the same result on each sql execution :
    SQL> ed
    Wrote file afiedt.buf
      1  select a.*, rownum
      2* from (select distinct username from dba_users order by username) a
    SQL> /
    USERNAME                           ROWNUM
    DBSNMP                                  1
    H89UCBAC                                2
    OUTLN                                   3
    PEOPLE                                  4
    PS                                      5
    SYS                                     6
    SYSTEM                                  7
    7 rows selected.
    SQL> /
    USERNAME                           ROWNUM
    DBSNMP                                  1
    H89UCBAC                                2
    OUTLN                                   3
    PEOPLE                                  4
    PS                                      5
    SYS                                     6
    SYSTEM                                  7
    7 rows selected.
    SQL> Nicolas.
    Sorry Laurent, you've already showed that works with subquery...
    Message was edited by:
    N. Gasparotto

  • Use NEXTVAL in an insert statement Part II

    db - 10g
    I am asking this question out of curiosity.
    I posted a question and recieved a successful answer at the following address on this forum;
    Use NEXTVAL in an insert statement
    The following insert statement uses a sequence to create an arbitrary number for each null record. The problem is, the sequence is firing regardless of the condition being true or false (but it is working in that it only inserts values when the condition is true). The result is the sequence appears to increment each time it loops through the cursor and so the first arbitrary number to be inserted is not 1001 but some other higher number.
    INSERT INTO psp_trees
    ( plot_id
    , tree_name
    , species_code)
    VALUES
    ( get_plot_id
    , c1.treenum          
    , c1.species
    ) RETURNING tree_id INTO get_tree_id;   I have gotten around the issue by removing the sequence from the insert statement and placing it outside the cursor loop as an update statement.
          UPDATE psp_trees
             SET tree_name = to_char(tree_arbitrary_name_seq.nextval)
           WHERE tree_name IS NULL;Is there anyway to get the sequence to only fire in the insert statement when the condition is true.
    This is the complete anonymous block for your reference;
    DECLARE p_access_num NUMBER;
    col_access_var VARCHAR2(30);
    type number_ptb IS table OF VARCHAR2(4000);
    p_access_nam number_ptb;
    get_plot_measurement_id NUMBER;
    update_plot_measurements VARCHAR2(4000);
    get_tree_id NUMBER;
    get_plot_id NUMBER;
    BEGIN
        p_access_num := 6;
        p_access_nam := number_ptb();
        p_access_nam.extend(7);
        p_access_nam(1) := 535;
        p_access_nam(2) := 548;
        p_access_nam(3) := 898;
        p_access_nam(4) := 544;
        p_access_nam(5) := 551;
        p_access_nam(6) := 724;
        FOR loop_int IN 1 .. p_access_num
        LOOP
          col_access_var := p_access_nam(loop_int);
          -- 1. Initiate insert process by getting PK from psp_plots.
          SELECT plot_id INTO get_plot_id FROM psp_plots WHERE plot_name = col_access_var;    
          -- 2. Insert records into psp_plot_measurements and keep relationship with psp_plots with variable get_plot_id.
          --    and get primary key value of psp_plot_measurements to insert into psp_tree_measurements during loop process.
          INSERT INTO psp_plot_measurements (plot_id) VALUES (get_plot_id) RETURNING plot_measurement_id INTO get_plot_measurement_id;   
          -- 3. Update record created at point 2.
          UPDATE psp_plot_measurements
             SET measurement_date    = (SELECT DISTINCT date_ FROM pspdata)
               , codominant_height   = (SELECT DISTINCT height_codom FROM pspdata)
               , assessor            = (SELECT DISTINCT assessor FROM pspdata)
           WHERE plot_measurement_id = col_access_var
          -- 4. Open cursor to insert rows one at a time and maintain relationships between related tables.
          FOR c1 IN (SELECT treenum
                          , dbhob
                          , treecomments
                          , species
                       FROM pspdata
                      WHERE plotnumber = col_access_var
                        AND date_ IS NOT NULL)     
              LOOP   
                -- 5. Insert record into psp_trees
                --    and get primary key value of psp_trees to insert into psp_tree_measurements.
                INSERT INTO psp_trees
                ( plot_id
                , tree_name
                , species_code)
                VALUES
                ( get_plot_id
                , c1.treenum
                --, NVL(c1.treenum , to_char(tree_arbitrary_name_seq.nextval))
                --, (CASE WHEN c1.treenum IS NULL THEN to_char(tree_arbitrary_name_seq.nextval) ELSE c1.treenum END)
                , c1.species
                ) RETURNING tree_id INTO get_tree_id;   
                -- 6. Insert records into psp_tree_measurements and keep relationship with psp_trees with variable get_tree_id.
                INSERT INTO psp_tree_measurements
                ( plot_measurement_id
                , tree_id
                , dbhob          
                , comments
                VALUES
                ( get_plot_measurement_id
                , get_tree_id
                , c1.dbhob
                , c1.comment
              END LOOP;         
      END LOOP; 
          -- 7. Update null columns with arbitrary number.
          UPDATE psp_trees
             SET tree_name = to_char(tree_arbitrary_name_seq.nextval)
           WHERE tree_name IS NULL;
    END;
    /Edited by: benton on Sep 6, 2011 1:53 PM

    Or use a function (I'll use dbms_xml.getxml):
    SQL> create sequence s_seq nocache
    Sequence created.
    SQL> select case when mod (level, 2) = 0
                then extractvalue(dbms_xmlgen.getxmltype('select s_seq.nextval from dual'), '//text()')
                else '0' end col1
              from dual connect by level < 20
    COL1                                                                           
    0                                                                              
    1                                                                              
    0                                                                              
    2                                                                              
    0                                                                              
    3                                                                              
    0                                                                              
    4                                                                              
    0                                                                              
    5                                                                              
    0                                                                              
    6                                                                              
    0                                                                              
    7                                                                              
    0                                                                              
    8                                                                              
    0                                                                              
    9                                                                              
    0                                                                              
    19 rows selected.
    SQL> select sequence_name, last_number from user_sequences where sequence_name = 'S_SEQ'
    SEQUENCE_NAME                  LAST_NUMBER
    S_SEQ                                   10
    1 row selected.

  • Insert Select sequence.nextval Problme

    Hi,
    I am trying to insert records in the table using query similar to
    insert into table1 (id, col1, col2)
    select
    sequence.nextval
    t1. col1, t1.col2
    from table t1;
    I am getting following error
    ORA-02287: sequence number not allowed here
    Will you please let me know how to resolve this?
    Regards
    ~Pravin

    Hmm...
    See here ->
    satyaki>
    satyaki>select * from v$version;
    BANNER
    Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Prod
    PL/SQL Release 10.2.0.1.0 - Production
    CORE    10.2.0.1.0      Production
    TNS for Linux: Version 10.2.0.1.0 - Production
    NLSRTL Version 10.2.0.1.0 - Production
    Elapsed: 00:00:00.01
    satyaki>
    satyaki>
    satyaki>
    satyaki>create table ff_gg
      2      (
      3        a_col   number(5),
      4        b_col   varchar2(30)
      5      );
    Table created.
    Elapsed: 00:00:00.01
    satyaki>
    satyaki>
    satyaki>create sequence dd_qq
      2     start with 1
      3     increment by 1;
    Sequence created.
    Elapsed: 00:00:00.00
    satyaki>
    satyaki>insert into ff_gg
      2     select rn, ename
      3     from (
      4            select dd_qq.nextval, ename
      5            from emp
      6          );
              select dd_qq.nextval, ename
    ERROR at line 4:
    ORA-02287: sequence number not allowed here
    Elapsed: 00:00:00.00
    satyaki>
    satyaki>ed
    Wrote file afiedt.buf
      1  insert into ff_gg
      2     select dd_qq.nextval rn, ename
      3     from (
      4            select ename
      5            from emp
      6*         )
    satyaki>/
    12 rows created.
    Elapsed: 00:00:00.00
    satyaki>
    satyaki>select * from ff_gg;
         A_COL B_COL
             1 WARD
             2 MARTIN
             3 SCOTT
             4 KING
             5 TURNER
             6 ADAMS
             7 JAMES
             8 FORD
             9 MILLER
            10 Smith
            11 Glen
         A_COL B_COL
            12 boock
    12 rows selected.
    Elapsed: 00:00:00.00
    satyaki>Got me?
    Regards.
    Satyaki De.

  • B1out - B1isql - Pass value of query to insert statement.

    Experts,
    Perhaps it is because it is late and I am very tired, but I feel as though I am overlooking some obvious solution to the following scenario.
    I have created a scenario that is making a SQL Call to a database, and I need to pass the values from that query to a table in a B1 DB.
    I am using an outbound channel of B1, and the B1isql type.
    here is my issue,
    I know that I can pass the value of atom0 JDBC:JOBID to my Field tag.
    However, the insert statement uses the tag attribute value="" to pass the values to the DB.
    <Table id="invoicesource" keylist="jobid" task="A" del="">
         <Field id="JOBID" value="" wrapchar="False"><xsl:value-of select="jdbc:JOBID"/></Field>
    </Table>
    I'd like to be able to pass the <value-of select= />, into the value="" attribute instead.
    Any insight would be greatly appreciated.
    warmest regards,
    Lucas Fischer

    I used standard SQL out instead, since it was for custom DB object, and not SAP B1 table, issue resolved.
    Edited by: Lucas Fischer on Jun 28, 2011 12:01 PM

  • Urgent help needed... PL/SQL Insert statement

    Hi...
    I need some urgent help on this project. I have a 2 column table with values that need to be inserted into another existing table which has a sequence.
    This is the 2 column table:
    FUND YEAR
    29587 05
    29587 07
    Existing table:
    Name Null? Type
    LIST_ID NOT NULL NUMBER(6) -- This is a sequence
    WEB_USER_ID NOT NULL VARCHAR2(10)
    RESOURCE_TYPE NOT NULL VARCHAR2(8)
    LIST_TYPE NOT NULL VARCHAR2(10)
    LIST_NAME NOT NULL VARCHAR2(50)
    LIST_CODE_1 NOT NULL VARCHAR2(6) -- FUND from table above
    LIST_CODE_2 NOT NULL VARCHAR2(6) -- YEAR from table above
    LIST_CODE_3 NOT NULL VARCHAR2(6)
    LAST_UPDATED_DT NOT NULL DATE
    LAST_UPDATED_BY NOT NULL VARCHAR2(10)
    LIST_CODE_4 NOT NULL VARCHAR2(20)
    The columns from table 1 (FUND, YEAR) correspond to columns (LIST_CODE_1, LIST_CODE_2) in table 2. The column LIST_ID is a sequence. I can put in sysdate for LAST_UPDATED_DT and my initials SN for LAST_UPDATED_BY. This is going to be for 2 unique WEB_USER_IDs which would be in the WHERE clause. I will be inserting 2200 rows for each id. A single insert statement would look like this -
    INSERT INTO EXISTING_TBL (list_id,web_user_id,resource_type,list_type,list_name,list_code_1,list_code_2,list_code_3,list_code_4,last_updated_dt,last_updated_by) VALUES ('470027','WEBUSER','GL','FUNDFYF',' FUND BALANCE SUM','12010','01',' ',' ',{ts '2010-5-19 10:16:9'},'SN')
    How would I do this to insert the 2200 values from my 2 column table to the existing table?
    All help is greatly appreciated!!
    SN

    Hello ,
    I think this will work
    INSERT INTO TABLE2
         LIST_ID,
         WEB_USER_ID,
         RESOURCE_TYPE,
         LIST_TYPE,
         LIST_NAME,
         LIST_CODE_1,
         LIST_CODE_2,
         LIST_CODE_3,
         LIST_CODE_4,
         LAST_UPDATED_DT,
         LAST_UPDATED_BY
    SELECT
         SEQ.NEXTVAL,
         FUND,
         YEAR,
         <VALUE FOR RESOURCE_TYPE>,
         <VALUE FOR LIST_TYPE>,
         <VALUE FOR LIST_NAME>,
         <VALUE FOR LIST_CODE_1>,
         <VALUE FOR LIST_CODE_2>,
         <VALUE FOR LIST_CODE_3>,
         <VALUE FOR LIST_CODE_4>,
         SYSDATE,
         'SN'
    FROM
         TABLE1
    REGARDS
    Rahul Sharma

  • Issue with sequence.currval in INSERT ALL...

    Hi Gurus,
    I am having an issue with using sequence.currval in INSERT ALL with WHEN clause.Please check following example
    Let say I have 4 tables
    1) SOURCE_PARENT
    PARENT_ID
    ========
    10
    20
    2) SOURCE_CHILD
    PARENT_ID CHILD_ID
    ========= ========
    10     1
    10     2
    20     1
    20     2
    Now i have another 2 tables same as above definition(DEST_PARENT, DEST_CHILD),which i want to populate with above source data with new parent_id's from a sequence.
    So I have used INSERT ALL as follows.
    =====================================================
    INSERT ALL
    WHEN (prev_parent_id = 0)THEN
    INTO dest_parent
    values(test_s.nextval)
    when 1 = 1 then
    INTO dest_child
    values(test_s.currval,child_id)
    select
    p.parent_id
    ,c.child_id
    ,LAG(c.parent_id, 1, 0) OVER (PARTITION BY c.parent_id ORDER BY c.child_id) prev_parent_id
    from
    source_parent p
    ,source_child c
    where
    p.parent_id = c.parent_id
    order by p.parent_id
    ========================================================
    Above INSERT ALL created following rows in DEST tables
    1) DEST_PARENT
    PARENT_ID
    =========
    75
    77
    2)DEST_CHILD
    PARENT_ID CHILD_ID
    ========= =======
    75     1
    76     2 --- this should be same as above record
    77     1
    78     2 --this should be same as above record
    As you can see test_s.nextval is executed 4 times even we do have WHEN Clause in INSERT ALL
    Can you please check what's wrong in this INSERT ALL statement?
    (or)
    Any otherway of doing these INSERTS in a single SQL statement?
    Any help would be appreciated!!
    Thanks
    srinivas.L

    Sorry, but this solution does not work. I had to remove the constraints on the two tables dest_parent and dest_child just to show you, how bad your solution is
    SQL> select * from source_parent;
    PARENT_ID
            10
            20
    2 rows selected.
    SQL> select * from source_child;
    PARENT_ID   CHILD_ID
            10          1
            10          2
            20          1
            20          2
            20          3
    5 rows selected.
    SQL> select * from dest_parent;
    no rows selected
    SQL> select * from dest_child;
    no rows selected
    SQL> insert all when
      2       (PREV_PARENT_ID = 0) then into DEST_PARENT
      3  values
      4       (TEST_S.nextval) when 1 = 1 then into DEST_CHILD
      5  values
      6       (case when PREV_PARENT_ID != 0 then TEST_S.currval - 1 else TEST_S.currval end,
      7        CHILD_ID)
      8       select P.PARENT_ID,
      9              C.CHILD_ID,
    10              LAG(C.PARENT_ID, 1, 0) OVER(partition by C.PARENT_ID order by C.CHILD_ID) PREV_PARENT_ID
    11       from SOURCE_PARENT P, SOURCE_CHILD C
    12       where P.PARENT_ID = C.PARENT_ID
    13       order by P.PARENT_ID
    14  /
    7 rows created.
    SQL> select * from dest_parent;
    PARENT_ID
            23
            26
    2 rows selected.
    SQL> select * from dest_child;
    PARENT_ID   CHILD_ID
            21          2   -- ??? !!!
            23          1
            23          2
            24          3   -- !!!
            26          1
    5 rows selected.
    SQL>

  • Sequence error in select statement

    Does anyone know why I get the following error when I run the code below. If so, how can it be fixed.
    Thanks in advance,
    John C
    ORA-02287 sequence number not allowed here
    INSERT INTO PROMO_STAGE.NAC_OFFER (CMPGN_KEY, OFFER_KEY, CREATIVE)
    SELECT DISTINCT A.CREATIVE,
    B.CMPGN_KEY,
    PROMO_STAGE.SEQ_NAC_OFFER_KEY.NEXTVAL@DSTAGE
    FROM PROMO_STAGE.CAMPAIGN@DSTAGE B,
    ROCEONOF.NACQ0211_2_FINAL@OGD A
    WHERE B.CMPGN_ID = 'NAC_'|| to_char(add_months(SYSDATE,-1),'YYYYMM');

    John
    It is the DISTINCT which is causing the trouble. How about:
    INSERT INTO PROMO_STAGE.NAC_OFFER (CMPGN_KEY, OFFER_KEY, CREATIVE)
    SELECT COL1, COL2, PROMO_STAGE.SEQ_NAC_OFFER_KEY.NEXTVAL@DSTAGE
    FROM
    (SELECT DISTINCT A.CREATIVE COL1, B.CMPGN_KEY COL2
    FROM PROMO_STAGE.CAMPAIGN@DSTAGE B,
    ROCEONOF.NACQ0211_2_FINAL@OGD A
    WHERE B.CMPGN_ID = 'NAC_'|| to_char(add_months(SYSDATE,-1),'YYYYMM'));
    Incidentally, judging by the column names, it appears that the columns in your insert statement are not listed in the same order as in the select statement, which of course they should be.

  • Use of sequence numbers while inserting into tables

    Hi,
    Consider i have a stored procedure where i insert records into 30 to 40 tables.
    for example i have a table A and a sequence SEQ_A for that table.
    Is there any difference in performance in the following two ways of
    insertion,
    1. select SEQ_A.NEXTVAL into variable_a FROM DUAL;
    INSERT INTO A VALUES(variable_a);
    2.INSERT INTO A VALUES (SEQ_A.NEXTVAL).
    I have 30 to 40 insert statements like that in method 1.
    if i replace it by method 2. will there be any improvement in performance?
    Thanks & Regards
    Sundar

    This could be interesting. I agree that triggers should be used for data integrity, though even better is to only allow write access to tables via stored procedures.
    Anyway while you are waiting for the test case that shows triggers are faster, which could take some time, it is quick and easy to come up with a test case that shows the opposite.
    SQL> create table t (id number, dummy varchar2(1));
    Table created.
    real: 40
    SQL> insert into t select s.nextval, 'a' from all_objects;
    29625 rows created.
    real: 5038
    SQL> rollback;
    Rollback complete.
    real: 40
    SQL> create trigger tt before insert on t
      2  for each row
      3  begin
      4     select s.nextval into :new.id from dual;
      5  end;
      6  /
    Trigger created.
    real: 291
    SQL> insert into t select null, 'a' from all_objects;
    29626 rows created.
    real: 13350
    SQL> rollback;
    Rollback complete.
    real: 1082
    SQL>Note with triggers even the rollback took longer.
    Martin

  • SQL*Loader-929: Error parsing insert statement for table

    Hi,
    I get the following error with SQL*Loader:
    Table MYTABLE loaded from every logical record.
    Insert option in effect for this table: INSERT
    Column Name Position Len Term Encl Datatype
    IDE FIRST * ; CHARACTER
    SQL string for column : "mysequence.NEXTVAL"
    CSI_NBR 1:10 10 ; CHARACTER
    POLICY_NBR 11:22 12 ; CHARACTER
    CURRENCY_COD 23:25 3 ; CHARACTER
    POLICY_STAT 26:27 2 ; CHARACTER
    PRODUCT_COD 28:35 8 ; CHARACTER
    END_DAT 44:53 10 ; CHARACTER
    FISCAL_COD 83:83 1 ; CHARACTER
    TOT_VAL 92:112 21 ; CHARACTER
    SQL*Loader-929: Error parsing insert statement for table MYTABLE.
    ORA-01031: insufficient privileges
    I am positive that I can SELECT the sequence and INSERT into the table with the user invoking sql*loader.
    Where does that "ORA-01031" come from?
    Regards
    ...

    Options:
    1) you are wrong about privileges OR
    2) you have the privilege only when you connect via SQL*Plus (or whichever other tool you used to test the insert).
    Is it possible that during your test you enabled the role which granted you the INSERT privilege - and that SQL*Loader doesn't do this?
    Can you see the table in this list?
    select *
    from user_tab_privs_recd
    where table_name='MY_TABLE'
    and owner='table owner whoever';
    select *
    from user_role_privs;Any roles where DEFAULT_ROLE is not YES?
    HTH
    Regards Nigel

  • Need help understanding what i am doing wrong in my insert statement

    insert into employees (employeeid, firstname, lastname, title) Values ('1001', 'jack', null, 'shepard', 'salesperson');
    insert into employees (employeeid, firstname, lastname, title) Values ('1002', 'jack', null, 'shepard', 'salesperson');
    insert into employees (employeeid, firstname, lastname, title) Values ('1003', 'jack', null, 'shepard', 'salesperson');
    insert into employees (employeeid, firstname, lastname, title) Values ('1004', 'jack', null, 'shepard', 'salesperson');
    insert into employees (employeeid, firstname, lastname, title) Values ('1005', 'jack', null, 'shepard', 'salesperson');
    insert into employees (employeeid, firstname, lastname, title) Values ('1006', 'jack', null, 'shepard', 'salesperson');
    i am getting this error message
    Msg 110, Level 15, State 1, Line 3
    There are fewer columns in the INSERT statement than values specified in the VALUES clause. The number of values in the VALUES clause must match the number of columns specified in the INSERT statement.
    also 
    insert into products (Name, price) values  ('shirts', 12.99);
    insert into products (Name, price) values  ('shirts', 14.99);
    insert into products (Name, price) values  ('shirts', 11.99);
    insert into products (Name, price) values  ('shirts', 14.99);
    insert into products (Name, price) values  ('shirts', 13.99);
    insert into products (Name, price) values  ('shirts', 15.99);
    insert into products (Name, price) values  ('shirts', 16.99);
    Msg 515, Level 16, State 2, Line 2
    Cannot insert the value NULL into column 'ProductID', table 'practice.dbo.products'; column does not allow nulls. INSERT fails.
    The statement has been terminated.
    what am i doing wrong?

    insert into employees (employeeid, firstname, lastname, title) Values ('1001', 'jack', null, 'shepard', 'salesperson');
    i am getting this error message
    Msg 110, Level 15, State 1, Line 3
    There are fewer columns in the INSERT statement than values specified in the VALUES clause. The number of values in the VALUES clause must match the number of columns specified in the INSERT statement.
    also 
    You have 4 columns in the insert( employeeid,fname,lname and title) however you are passing 5 values...
    What does NULL represents? Is it middlename, then you need to add in the column list of  insert as well.
    insert into products (Name, price) values  ('shirts', 12.99);
    Msg 515, Level 16, State 2, Line 2
    Cannot insert the value NULL into column 'ProductID', table 'practice.dbo.products'; column does not allow nulls. INSERT fails.
    The statement has been terminated.
    what am i doing wrong?
    It looks like your table products has a column productid as not null. As long as you are not passing the product id in your insert statement, it will try to insert productid as null which will break. If productid is a increment values, then you need to use
    either identity or sequence(if you version is 2012 and above).

  • Please Help me with long time oracle  select sequence.nextval from dual

    Hi
    I'm in a real problem.In fact i have a J2EE5(JPA,Hibernate 3,EJB 3.0) project deployed at websphere 6 application server and i'm using Oracle 10 g R2.
    Well i have a batch job that inserts into some table called AVERAGEBALANCE.
    the problem is that when i have activated hibernate log i discoverd that the select from dual is the longest sql (it takes some times over second !!)
    here is the log
    11/07/2011 08:49:40,406 DEBUG SQL:DefaultQuartzScheduler-SimpleThreadPoolWorker-2 - insert into AVERAGEBALANCE (CDATE_, CUSER_, AVERAGEBALANCE_, AVERAGECREDITORBALANCE_, AVERAGEDEBITORBALANCE_, BEGINDATE_, CALCULATIONDATE_, CASHSUBACCOUNTCODE_, CASHSUBACCOUNTPK_, CODE_, ENDDATE_, NBCREDITORDAYS_, NBDEBITORDAYS_, TEDABCALCULATIONPERIODICITYPK_, VERSIONNUM_, PK_) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
    11/07/2011 08:49:40,468 DEBUG SQL:DefaultQuartzScheduler-SimpleThreadPoolWorker-2 - select this_.PK_ as PK1_465_0_, this_.CDATE_ as CDATE2_465_0_, this_.CUSER_ as CUSER3_465_0_, this_.UUSER_ as UUSER4_465_0_, this_.BALANCE_ as BALANCE5_465_0_, this_.BALANCETYPE_ as BALANCET6_465_0_, this_.CASHSUBACCOUNTPK_ as CASHSUBA8_465_0_, this_.CASHSUBACCOUNTCODE_ as CASHSUBA7_465_0_, this_.CODE_ as CODE9_465_0_, this_.CURRENCYPK_ as CURRENCYPK11_465_0_, this_.CURRENCYCODE_ as CURRENC10_465_0_, this_.ENDDATE_ as ENDDATE12_465_0_, this_.EXCHANGERATE_ as EXCHANG13_465_0_, this_.ORIGINBALANCEPK_ as ORIGINB15_465_0_, this_.ORIGINBALANCECODE_ as ORIGINB14_465_0_, this_.POSITIONDATE_ as POSITIO16_465_0_, this_.REVALUATIONDATE_ as REVALUA17_465_0_, this_.SUMOFCREDITS_ as SUMOFCR18_465_0_, this_.SUMOFDEBITS_ as SUMOFDE19_465_0_, this_.UDATE_ as UDATE20_465_0_, this_.VERSIONNUM_ as VERSIONNUM21_465_0_ from CASHAB this_ where this_.CASHSUBACCOUNTCODE_=? and this_.BALANCETYPE_=? and this_.POSITIONDATE_<? and this_.ENDDATE_>=? and this_.BALANCE_<>?
    11/07/2011 08:49:40,468 DEBUG SQL:DefaultQuartzScheduler-SimpleThreadPoolWorker-2 - select AVERAGEBALANCE_.nextval from dual
    11/07/2011 08:49:41,484 DEBUG SQL:DefaultQuartzScheduler-SimpleThreadPoolWorker-2 - insert into AVERAGEBALANCE (CDATE_, CUSER_, AVERAGEBALANCE_, AVERAGECREDITORBALANCE_, AVERAGEDEBITORBALANCE_, BEGINDATE_, CALCULATIONDATE_, CASHSUBACCOUNTCODE_, CASHSUBACCOUNTPK_, CODE_, ENDDATE_, NBCREDITORDAYS_, NBDEBITORDAYS_, TEDABCALCULATIONPERIODICITYPK_, VERSIONNUM_, PK_) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)well i have increased the sequence cache in fact here is the creation code of the sequence.
    CREATE SEQUENCE  "COMPTAPERF5"."AVERAGEBALANCE_"  MINVALUE 1 MAXVALUE 999999999999999999999 INCREMENT BY 1 START WITH 1 CACHE 400 NOORDER  NOCYCLE   ;i think that there is some oracle parameter to tune
    Thanks in advance
    Edited by: B.Mansour Nizar on 11 juil. 2011 01:04
    Edited by: B.Mansour Nizar on 11 juil. 2011 06:33
    Edited by: B.Mansour Nizar on 11 juil. 2011 06:34
    Edited by: B.Mansour Nizar on 11 juil. 2011 06:34
    Edited by: B.Mansour Nizar on 11 juil. 2011 06:35
    Edited by: B.Mansour Nizar on 11 juil. 2011 06:35
    Edited by: B.Mansour Nizar on 11 juil. 2011 06:36
    Edited by: B.Mansour Nizar on 15 juil. 2011 07:42

    I found it.
    It's not due to oracle but it's a hibernate issue.In fact if setting FlushMode to Manual.It wil flush the in memory entities after that it will fire the insert statement.
    Here's the log.
    15/07/2011 15:32:47,984 DEBUG SQL:DefaultQuartzScheduler-SimpleThreadPoolWorker-4 - select CASHAB_.nextval from dual
    15/07/2011 15:32:47,984 TRACE AbstractBatcher:DefaultQuartzScheduler-SimpleThreadPoolWorker-4 - preparing statement
    15/07/2011 15:32:47,984 DEBUG SequenceGenerator:DefaultQuartzScheduler-SimpleThreadPoolWorker-4 - Sequence identifier generated: 20441
    15/07/2011 15:32:47,984 DEBUG AbstractBatcher:DefaultQuartzScheduler-SimpleThreadPoolWorker-4 - about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
    15/07/2011 15:32:47,984 TRACE AbstractBatcher:DefaultQuartzScheduler-SimpleThreadPoolWorker-4 - closing statement
    15/07/2011 15:32:47,984 DEBUG ConnectionManager:DefaultQuartzScheduler-SimpleThreadPoolWorker-4 - aggressively releasing JDBC connection
    15/07/2011 15:32:47,984 DEBUG ConnectionManager:DefaultQuartzScheduler-SimpleThreadPoolWorker-4 - releasing JDBC connection [ (open PreparedStatements: 0, globally: 0) (open ResultSets: 0, globally: 0)]
    15/07/2011 15:32:47,984 DEBUG AbstractSaveEventListener:DefaultQuartzScheduler-SimpleThreadPoolWorker-4 - generated identifier: 20441, using strategy: org.hibernate.id.SequenceHiLoGenerator
    15/07/2011 15:32:47,984 TRACE AbstractSaveEventListener:DefaultQuartzScheduler-SimpleThreadPoolWorker-4 - saving [com.bfi.cpt.bal.cas.CashAccountingBalance#20441]
    15/07/2011 15:32:47,984 TRACE Versioning:DefaultQuartzScheduler-SimpleThreadPoolWorker-4 - using initial version: 0
    15/07/2011 15:32:47,984 TRACE AbstractFlushingEventListener:DefaultQuartzScheduler-SimpleThreadPoolWorker-4 - flushing session
    15/07/2011 15:32:47,984 DEBUG AbstractFlushingEventListener:DefaultQuartzScheduler-SimpleThreadPoolWorker-4 - processing flush-time cascades
    15/07/2011 15:32:47,984 TRACE Cascade:DefaultQuartzScheduler-SimpleThreadPoolWorker-4 - processing cascade ACTION_PERSIST_ON_FLUSH for: com.bfi.cpt.cht.cas.CashSubAccount
    15/07/2011 15:32:47,984 TRACE Cascade:DefaultQuartzScheduler-SimpleThreadPoolWorker-4 - done processing cascade ACTION_PERSIST_ON_FLUSH for: com.bfi.cpt.cht.cas.CashSubAccount
    15/07/2011 15:32:47,984 TRACE Cascade:DefaultQuartzScheduler-SimpleThreadPoolWorker-4 - processing cascade ACTION_PERSIST_ON_FLUSH for: com.bfi.ref.cur.Currency
    15/07/2011 15:32:47,984 TRACE Cascade:DefaultQuartzScheduler-SimpleThreadPoolWorker-4 - done processing cascade ACTION_PERSIST_ON_FLUSH for: com.bfi.ref.cur.Currency
    15/07/2011 15:32:47,984 TRACE Cascade:DefaultQuartzScheduler-SimpleThreadPoolWorker-4 - processing cascade ACTION_PERSIST_ON_FLUSH for: com.bfi.cpt.bal.cas.CashAccountingBalance
    15/07/2011 15:32:47,984 TRACE Cascade:DefaultQuartzScheduler-SimpleThreadPoolWorker-4 - done processing cascade ACTION_PERSIST_ON_FLUSH for: com.bfi.cpt.bal.cas.CashAccountingBalance
    15/07/2011 15:32:47,984 DEBUG AbstractFlushingEventListener:DefaultQuartzScheduler-SimpleThreadPoolWorker-4 - dirty checking collections
    15/07/2011 15:32:47,984 TRACE AbstractFlushingEventListener:DefaultQuartzScheduler-SimpleThreadPoolWorker-4 - Flushing entities and processing referenced collections
    15/07/2011 15:32:47,984 TRACE AbstractFlushingEventListener:DefaultQuartzScheduler-SimpleThreadPoolWorker-4 - Processing unreferenced collections
    15/07/2011 15:32:47,984 TRACE AbstractFlushingEventListener:DefaultQuartzScheduler-SimpleThreadPoolWorker-4 - Scheduling collection removes/(re)creates/updates
    15/07/2011 15:32:47,984 DEBUG AbstractFlushingEventListener:DefaultQuartzScheduler-SimpleThreadPoolWorker-4 - Flushed: 1 insertions, 0 updates, 0 deletions to 3 objects
    15/07/2011 15:32:47,984 DEBUG AbstractFlushingEventListener:DefaultQuartzScheduler-SimpleThreadPoolWorker-4 - Flushed: 0 (re)creations, 0 updates, 0 removals to 0 collections
    15/07/2011 15:32:47,984 DEBUG Printer:DefaultQuartzScheduler-SimpleThreadPoolWorker-4 - listing entities:
    15/07/2011 15:32:47,984 DEBUG Printer:DefaultQuartzScheduler-SimpleThreadPoolWorker-4 - com.bfi.ref.cur.Currency{translatedName=null, certain=false, iso3166=788, quotity=1, identifier=TND, creationUser=admin, internalCode=null, name=Dinars Tunisien, creationDate=2011-07-11 14:43:06, code=TND, versionNum=0, decimal=3, updateUser=null, updateDate=null, pk=136, decimalName=millimes}
    15/07/2011 15:32:47,984 DEBUG Printer:DefaultQuartzScheduler-SimpleThreadPoolWorker-4 - com.bfi.cpt.bal.cas.CashAccountingBalance{cashSubAccount=com.bfi.cpt.cht.cas.CashSubAccount#400201, originBalanceCode=null, exchangeRate=null, sumOfDebits=0.0, endDate=31 décembre 9999, creationUser=bna, currencyPk=136, creationDate=2011-07-15 15:32:47, cashSubAccountCode=BNA/PCI_BNA/82-TND, code=2010-07-30/BNA/PCI_BNA/82-TND/AccountingDateBalance/TND, versionNum=0, originBalancePk=null, currency=com.bfi.ref.cur.Currency#136, updateUser=null, originBalance=null, balanceType=AccountingDateBalance, updateDate=null, positionDate=30 juillet 2010, sumOfCredits=10.0, pk=20441, cashSubAccountPk=400201, revaluationDate=null, balance=-10.0, currencyCode=TND}
    15/07/2011 15:32:47,984 DEBUG Printer:DefaultQuartzScheduler-SimpleThreadPoolWorker-4 - com.bfi.cpt.cht.cas.CashSubAccount{name2=null, accountPk=81, name=null, versionNum=0, currency=com.bfi.ref.cur.Currency#136, updateDate=null, chartByEntity=com.bfi.cpt.cht.std.ChartByEntity#2, refAccount=null, currencyCode=TND, chartByEntityCode=BNA/PCI_BNA, refAccountCode=null, creationDate=2011-07-15 15:25:45, account=com.bfi.cpt.cht.cas.StandardAccount#81, freeKey10=null, freeKey11=null, chartByEntityPk=2, freeKey12=null, updateUser=null, refAccountPk=null, freeKey13=null, freeKey14=null, freeKey15=null, freeKey16=null, freeKey17=null, accountCode=PCI_BNA/81, freeKey18=null, freeKey19=null, freeKey0=null, freeKey1=null, freeKey2=null, freeKey3=null, freeKey4=null, freeKey5=null, freeKey6=null, freeKey7=null, freeKey8=null, freeKey9=null, number=82-TND, creationUser=bna, freeKey20=null, freeKey21=null, freeKey22=null, freeKey23=null, freeKey24=null, freeKey25=null, freeKey26=null, freeKey27=null, freeKey28=null, freeKey29=null, currencyPk=136, code=BNA/PCI_BNA/82-TND, freeKey30=null, freeKey31=null, freeKey32=null, pk=400201}
    15/07/2011 15:32:47,984 TRACE AbstractFlushingEventListener:DefaultQuartzScheduler-SimpleThreadPoolWorker-4 - executing flush
    15/07/2011 15:32:47,984 TRACE ConnectionManager:DefaultQuartzScheduler-SimpleThreadPoolWorker-4 - registering flush begin
    15/07/2011 15:32:47,984 DEBUG UpdateTimestampsCache:DefaultQuartzScheduler-SimpleThreadPoolWorker-4 - Pre-invalidating space [CASHAB]
    15/07/2011 15:32:47,984 TRACE AbstractEntityPersister:DefaultQuartzScheduler-SimpleThreadPoolWorker-4 - Inserting entity: [com.bfi.cpt.bal.cas.CashAccountingBalance#20441]
    15/07/2011 15:32:47,984 TRACE AbstractEntityPersister:DefaultQuartzScheduler-SimpleThreadPoolWorker-4 - Version: 0
    15/07/2011 15:32:47,984 DEBUG AbstractBatcher:DefaultQuartzScheduler-SimpleThreadPoolWorker-4 - about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
    15/07/2011 15:32:47,984 DEBUG ConnectionManager:DefaultQuartzScheduler-SimpleThreadPoolWorker-4 - opening JDBC connection
    15/07/2011 15:32:47,984 DEBUG SQL:DefaultQuartzScheduler-SimpleThreadPoolWorker-4 - insert into CASHAB (CDATE_, CUSER_, BALANCE_, BALANCETYPE_, CASHSUBACCOUNTCODE_, CASHSUBACCOUNTPK_, CODE_, CURRENCYCODE_, CURRENCYPK_, ENDDATE_, POSITIONDATE_, SUMOFCREDITS_, SUMOFDEBITS_, VERSIONNUM_, PK_) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)Edited by: B.Mansour Nizar on 15 juil. 2011 07:38
    Edited by: B.Mansour Nizar on 15 juil. 2011 07:39
    Edited by: B.Mansour Nizar on 15 juil. 2011 07:43

  • VLD-1119: Unable to generate Multi-table Insert statement for some or all t

    Hi All -
    I have a map in OWB 10.2.0.4 which is ending with following error: -
    VLD-1119: Unable to generate Multi-table Insert statement for some or all targets.*
    Multi-table insert statement cannot be generated for some or all of the targets due to upstream graphs of those targets are not identical on "active operators" such as "join".*
    The map is created with following logic in mind. Let me know if you need more info. Any directions are highly appreciated and many thanks for your inputs in advance: -
    I have two source tables say T1 and T2. There are full outer joined in a joiner and output of this joined is passed to an expression to evaluate values of columns based on
    business logic i.e. If T1 is available than take T1.C1 else take T2.C1 so on.
    A flag is also evaluated in the expression because these intermediate results needs to be joined to third source table say T3 with different condition.
    Based on value taken a flag is being set in the expression which is used in a splitter to get results in three intermediate tables based on flag value evaluated earlier.
    These three intermediate tables are all truncate insert and these are unioned to fill a final target table.
    Visually it is something like this: -
    T1 -- T3 -- JOINER1
    | -->Join1 (FULL OUTER) --> Expression -->SPLITTER -- JOINER2 UNION --> Target Table
    | JOINER3
    T2 --
    Please suggest.

    I verified that their is a limitation with the splitter operator which will not let you generate a multi split having more than 999 columns in all.
    I had to use two separate splitters to achieve what I was trying to do.
    So the situation is now: -
    Siource -> Split -> Split 1 -> Insert into table -> Union1---------Final tableA
    Siource -> Split -> Split 2 -> Insert into table -> Union1

  • Report with stored proc running multiple stored procedures with insert statement

    Hi,
    I wonder if this is possible in SSRS ... I use the 2012 version (Data Tools).
    I have a report that triggers a stored procedure. See below.
    Within this SP there are 2 insert statements getting data from 2 other SP's.
    When I make a dataset referring to the main SP below, SSRS does not show me any fields at all.
    Is this because it's a SP with insert statements and nested SP's?
    At the end of the SP I make a select so it should see all the fields.
    The parameters @month and @costcenter are multivalue params. I use a special function to convert the multivalues, selected in the report, into a string to pass it correctly to the query (comma separated).
    USE [TestDB]
    GO
    /****** Object:  StoredProcedure [dbo].[_Pink_SP_StandingsRegisterDataset]    Script Date: 15-4-2014 13:31:30 ******/
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    ALTER PROCEDURE [dbo].[_Pink_SP_StandingsRegisterDataset]
    @year INT,
    @month NVARCHAR(50),
    @costcenter NVARCHAR(500),
    @GLaccount NVARCHAR(9)
    AS
    BEGIN
    /* Remove existing content*/
    DELETE FROM _Pink_TB_StandingsRegister
    /* Add records part 1 */
    INSERT INTO _Pink_TB_StandingsRegister
    EXEC _Pink_SP_StandingsRegister @year, @month, @costcenter, @GLaccount
    /* Add records part 2 */
    INSERT INTO _Pink_TB_StandingsRegister
    Type,
    Row,
    Year,
    Month,
    YearDatetable,
    MonthDatetable
    EXEC _Pink_SP_StandingsRegisterDatetable @year
    /* Select all records */
    SELECT *
    FROM _Pink_TB_StandingsRegister
    END
    GO

    Hi bijntjede2e,
    After testing a similar scenario in my own environment, it works well in Reporting Services. In my test, the stored procedure returns all the fields from _Pink_TB_StandingsRegister table in the dataset. Then I select some values from year, month, costcenter
    and Glaccount parameters, it inserts some values in the _Pink_TB_StandingsRegister table. So we can use this stored procedure as the dataset in the report.
    In order to solve the problem more efficiently, I need to clarify some information.
    Are you pass multiple values parameter to one stored procedure correctly? We can refer to the following thread:
    http://social.technet.microsoft.com/Forums/en-US/dbdfa101-cccc-4e9f-aa50-566dc5ebcc27/ssrs-2008-r2-report-dataset-call-a-stored-procedure?forum=sqlrep
    What results are you get when executing the stored procedure in SQL Server Management Studio? Is it works well? We should double those stored procedures.
    If there are any misunderstanding, please elaborate the issue for further investigation.
    Thanks,
    Katherine Xiong
    Katherine Xiong
    TechNet Community Support

  • How to get the table name and bind columns names in an INSERT statement ?

    I have an INSERT statement with input parameters (for example
    INSERT INTO my_table VALUES (:a, :a, :a)) and I want to know
    without parsing the statement which is the name of table to
    insert to and the corresponding columns.
    This is needed to generate the SELECT FOR UPDATE statement to
    refetch a BLOB before actually writing to it. The code does not
    know in advance the schema (generic code).
    Thanks in advance,
    Joseph Canedo

    Once you have prepared your statement, you can execute the
    statement with the OCI_DESCRIBE_ONLY mode before binding any
    columns. Then you can use OCIParamGet to find out about each
    column (column index is 1-based). You should get OCI_NO_DATA or
    ORA-24334 if there are no more columns in the statement. Note
    that the parameter descriptor from OCIParamGet is
    allocated/freed internally by OCI; you do not need to manage it
    explicitly. The parameter descriptor is passed to OCIAttrGet in
    order to obtain for instance the maximum size of data in the
    column OCI_ATTR_DATA_SIZE. You can also get the column name in
    this way, although I do not remember the #define off the top of
    my head. Getting the table name appears to be much more
    difficult; I have never had to do that yet. Good luck. -Ralph

Maybe you are looking for

  • Month to date Actual vs Forecast

    Hi Experts, we have Reporting Requirement like we have monthly sales forecast product vise and sales actuals daywise, now we need to design the Report which shows Actual vs forecast Month to date. to design a report for actuals month to date we can g

  • Top of page in alv report

    Hi all, i have an alv report, in which i  have  form top_of_page form , but i don't see perform top_of_page in the entire program its not been passed to fm also. where this  form comes from my other question is, i have some text in this form, i want

  • Upload probleb

    Hi, I have to upload the data in time infotype 2011. I am using BDC using session method. The prog runs withour giving any error, but the data is not uploaded in the infotype. The data gets stored in TEVEN table if you manuualy create the record. Reg

  • Importing multiple proj (just name, start & end)

    Anyone know how to import a list of projects (just project name and maybe start and end date..no detail or activities necessary) into P6? I have my current list of project names in Excel. Thanks Peter

  • Output Quality from Motion 4

    I have recently upgraded to FCS3 from FCS2 and now when I export a Quicktime movie from Motion the quality is very poor no matter what settings I use. The resulting output appears to be outputting at 'Draft' quality despite it being set to 'Best' in