Insert into table primary key (automatic numbering) for back in class resultset

Hello

I connect to Oracle 10 g via JDBC (ojdbc14.jar is).
My SQL statement is:

INSERT into student (studentName, phone, e-mail, address) values ('Jason', '12345678', 'test', 'test');
SELECT Student_studentId_SEQ. NEXTVAL FROM DUAL;

FYI - the Student table has a trigger to support the generation of a primary key (integer) based on a sequence when a new record is inserted.

The above will do (from the point of view of Java app) is to create a school record and automatically select the student card and student card is accessible via the resultset in Java.

I get the error message ' ORA-00911: invalid character '. Can you please help?


Kind regards
Jason

Published by: user10394130 on October 13, 2008 02:40

As I said already try using a refcursor like that.

DECLARE
seqNbr_studentId NUMBER (12): = 0;
stud_cur SYS_REFCURSOR;
BEGIN
INSERT into student (studentName, phone, e-mail, address) values ('Jason', '12345678', 'test', 'test')
StudentId INTO seqNbr_studentId RETURN;
     
Stud_cur OPEN to SELECT seqNbr_studentId OF MODEL;
END;

Thank you
Knani.

Tags: Database

Similar Questions

  • INSERT INTO table (columns...) with table_tmp in select... ...

    Hi guru,.

    Is less than a valid SQL | Statement of PLSQL? or several instructions and what it does?

    insert into table (col1, col2, col3, col4)
    with table_tmp as
    (select ccol1, ccol2, ccol3, ccol4, ccol5, ccol6
    from table1, table2 t2 t1
    where t1.id = t2.id
    and t2.start > sysdate()
    )
    Select tcol1, tcol2, tcol3, tcol4
    of table_tmp tt1, table3 t3
    where tt1.id = tt3.id;

    I checked the SQL quick reference card and don't see anything similar to this... I wonder where I can find a better book of reference for the syntax.

    Thanks in advance
    KH

    user5885318 wrote:
    Is less than a valid SQL | Statement of PLSQL? or several instructions and what it does?

    It inserts data into the table

    insert into table (col1, col2, col3, col4)

    (ok, ignoring the fact that you can't have a table named table)

    using the select statement located below

    with table_tmp as
    (select ccol1, ccol2, ccol3, ccol4, ccol5, ccol6
    from table1, table2 t2 t1
    where t1.id = t2.id
    and t2.start > sysdate()
    )
    Select tcol1, tcol2, tcol3, tcol4
    of table_tmp tt1, table3 t3
    where tt1.id = tt3.id;

    I checked the SQL quick reference card and don't see anything similar to this... I wonder where I can find a better book of reference for the syntax.

    SQL reference documentation contains the complete syntax for Oracle SQL, so how can you find a better reference for the syntax. I think your concept to better is all simply because you are not familiar with things and don't know where to find things. SQL is a huge beast, so you cannot expect to find things very quickly in all cases, especially if you don't really know what you are looking for.

    I'm guessing you are struggling to find information about the clause "WITH"?

    It is called subquery factoring and lie under the SELECT statement in the SQL reference:

    http://download.Oracle.com/docs/CD/B19306_01/server.102/b14200/statements_10002.htm#i2161315

    An equivalent statement without the WITH clause (using your insert as a base statement)...

    insert into table(col1, col2, col3, col4)
    select tcol1, tcol2, tcol3, tcol4
    from (select ccol1, ccol2, ccol3, ccol4, ccol5, ccol6
          from table1 t1, table2 t2
          where t1.id=t2.id
          and t2.start > sysdate()
         ) tt1
         , table3 t3
    where tt1.id=tt3.id;
    

    The done WITH clause takes the subquery in the main query. This is useful if the same subquery is needed more than once in the main query.

  • MySQL Insert with autoincremented primary key

    I did not before MySQL.  I try and hit a roadblock soon enough.

    I would like to insert new records and have the auto-generated primary key / auto-increment.

    So, I have attached a few screenshots.  The first is a screenshot of the MySQL settings for the table that I'm writing.  The second is the Labview code that I threw as well as I am trying to run.

    The complete of the error I get is:

    > Database Connection.viADO error: 0x80004005
    Exception occurred in the Microsoft OLE DB provider for ODBC drivers: [MySQL] [ODBC 3.51 Driver] [mysqld - 5.7.11 - log] field 'techniciansID' didn't is not a default value to create a NI_Database_API.lvlib:Rec - Command.vi-> NI_Database_API.lvlib:Cmd Execute.vi-> NI_Database_API.lvlibData.vi B tools insert-> Connection.vi in the database

    I know that this error indicates that the techniciansID has no default value and he won't write because of it... but since it is an AutoIncrement field, it seems like it should work.

    Any help would be appreciated.  Thank you

    Thad

    Setting to 0 did not work, but I understand it.  For some reason any when I was refreshing my tables in MySQL server and using the "Forward Engineer" feature, the changes were not multiplication.  I had to drop the schema of the database (attached image) and then do an "engineer forward."  I made the changes, but the tables and the columns still had the attributes of origin... guess they cannot be updated by the script during execution.

    After doing this and the original settings I had (autoincremented primary key), the insert works in MySQL and Labview.

    Thanks for all the answers.  They made me think and check some things I didn't have before.

    -Thad

  • The values of cursor two corresponding and insertion into tables

    I ' am using sql developer oracle 11g.

    I have 3 tables called

    PRODUCT_NOTIFICATION

    RECORD

    PCS_NOTIFICATION

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

    PRODUCT_NOTIFICATION

    IDTITLEMessage
    21sale50% discount on all brand products

    RECORD

    IDREGNAMEACTIVATIONCODESTATUSMOBILENUM
    747407931107TESTTHERE12345
    39717371107TESTuco1THERE6789

    Now, I want to take only the message of product_notification table column and

    pick up the registered customer of registration table where the activationcode_status = 'Y '.

    PCS_NOTIFICATION

    Output of desire in the PCS_NOTIFICATION TABLE

    IDMOBILENUMMessage
    11234550% discount on all brand products
    2678950% discount on all brand products

    THEN insert the message in pcs_notification.

    It is the procedure goes as...

    create or replace

    PROCEDURE sp_notification)

    p_out_msg OUT VARCHAR2

    )

    AS

    CURSOR C_product_notification

    IS

    Select the description of product_notification;

    -Search for registered customer

    CURSOR C_registered

    IS

    Select * from registration where activation_code = 'Y ';

    for k C_INSERT

    LOOP

    THEN

    BEGIN

    If C_product_notification = C_registered THEN

    INSERT INTO PRODUCT_CLOUD_NOTIFICATION VALUES () - stuck here

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

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

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

    Goal is to send the generic message for every individual mobile numbers of registered customers.

    Help, please...

    Create a sequence object to fill PCS_NOTIFICATION.ID. allows you to call him PCS_NOTIFICATION_ID_SEQ.

    Now all you need is a simple insert statement.

    insert into pcs_notification (id, mobilenum, message)
    select pcs_notification_id_seq.nextval, r.mobilenum, pn.message
      from product_notification pn
      cross join registration r
     where r.activationcodestatus = 'Y';
    
  • Insert into table fault

    When I use the function 'insert into array' index(like 5), it does not work. When I put the index zero, it works, and inserts the new item at the end of the table. ?. ?

    Hello

    I think the problem is that you have not initialized your table to which you will add an element. You must double clik and adds a number. You can inicialize, only the last element and the other elements will also be inicialized.

    Try looking at the photo.

    Hope it helps

  • Insert into a primary database of Eve Active Data Guard

    I use Oracle EE 11.2.0.3.8 on Solaris 10.

    I read that it is possible to do an insert in my database for the standby Active Data Guard by redirecting the insert to get on the primary via DB link.  I GLOBAL_NAMES set to TRUE and he needs to stay that way.  This means that I can't create a DB link pointing to my first as such:

    CREATE DATABASE LINK PROD. WORLD WITH THE HELP OF "PROD_PRIM";

    How can I get around this in order to insert data in my standby ADG primary?

    Hello;

    There is an article about it here by Uwe Hesse:

    http://uhesse.files.WordPress.com/2012/03/realtimequery.PDF

    I understand that if GLOBAL_NAMES is true, then, the database link must have the same name as the database in which it connects.

    Best regards

    mseberg

  • Reading data from a file txt and inserting into table

    I have a text file and have uploaded data in this text file in an internal table,

    the data is normally placed online and I managed to recover most of the data, but I have problems by inserting a few conditions

    OK, well it goes like this.

    I got the right reailer id,

    Well, I have a table with all the columns in the file. Now it I'll try to throw it out as simple as I can


    Reseller 1

    column 1 column 1 column 1 column 1 column 1 column 1 column 1 column 1
    ===============
    Total 0 0 0 0 0 0 0
    -------------------------------------

    Distributor 2

    column 1 column 1 column 1 column 1 column 1 column 1 column 1 column 1
    ===============
    X 1123... .. .. .. .. ..
    234 Y... .. .. .. .. ..

    Total 23... .. .. .. .. ..

    see the problem is I have to associate the retailer number to their corresponding x and y and also not all retailers have values X and Y

    The remains of standard file format but only the values of the columns may change, but they must be inserted in the table according to the number of retailers.

    U understand what I mean...

    How about you, including both terminal number (just for the fun of it... hehe!):

    SQL> ed
    Wrote file afiedt.buf
    
      1  select retailer_no, terminal_no, retailer_name, val1, val2, val3, val4, val5, val6, val7, val8, val9, val10
      2  from (
      3        select case when retailer_no is null then lag(retailer_no, decode(val1, 'Loto', 1, 'Inst Tk', 2, 3)) over (order by line_no) else null end as retailer_no
      4              ,case when terminal_no is null then lag(terminal_no, decode(val1, 'Loto', 1, 'Inst Tk', 2, 3)) over (order by line_no) else null end as terminal_no
      5              ,case when retailer_name is null then lag(retailer_name, decode(val1, 'Loto', 1, 'Inst Tk', 2, 3)) over (order by line_no) else null end as retailer_name
      6              ,val1, val2, val3, val4, val5, val6, val7, val8, val9, val10
      7        from (
      8              select rownum as line_no
      9                    ,case when regexp_like(line, '^Retailer Number:') then regexp_replace(line, '^Retailer Number: +([0-9]+).*$', '\1') else null end as retailer_no
     10                    ,case when regexp_like(line, '^Retailer Number:') then regexp_replace(line, '^.* Terminal Number: +([0-9]+).*$', '\1') else null end as terminal_no
     11                    ,case when regexp_like(line, '^Retailer Number:') then regexp_replace(line, '^.* Retailer Name: +(.*)$', '\1') else null end as retailer_name
     12                    ,case when regexp_like(line, '^( +Loto | +Inst Tk|Totals)') then trim(substr(line, 1, 15)) else null end as val1
     13                    ,case when regexp_like(line, '^( +Loto | +Inst Tk|Totals)') then regexp_substr(line, '[^ ]+', 16, 1) else null end  as val2
     14                    ,case when regexp_like(line, '^( +Loto | +Inst Tk|Totals)') then regexp_substr(line, '[^ ]+', 16, 2) else null end  as val3
     15                    ,case when regexp_like(line, '^( +Loto | +Inst Tk|Totals)') then regexp_substr(line, '[^ ]+', 16, 3) else null end  as val4
     16                    ,case when regexp_like(line, '^( +Loto | +Inst Tk|Totals)') then regexp_substr(line, '[^ ]+', 16, 4) else null end  as val5
     17                    ,case when regexp_like(line, '^( +Loto | +Inst Tk|Totals)') then regexp_substr(line, '[^ ]+', 16, 5) else null end  as val6
     18                    ,case when regexp_like(line, '^( +Loto | +Inst Tk|Totals)') then regexp_substr(line, '[^ ]+', 16, 6) else null end  as val7
     19                    ,case when regexp_like(line, '^( +Loto | +Inst Tk|Totals)') then regexp_substr(line, '[^ ]+', 16, 7) else null end  as val8
     20                    ,case when regexp_like(line, '^( +Loto | +Inst Tk|Totals)') then regexp_substr(line, '[^ ]+', 16, 8) else null end  as val9
     21                    ,case when regexp_like(line, '^( +Loto | +Inst Tk|Totals)') then regexp_substr(line, '[^ ]+', 16, 9) else null end  as val10
     22              from cdc_file
     23              where regexp_like(line, '^( +Loto | +Inst Tk |Totals|Retailer Number:)')
     24             )
     25        )
     26  where retailer_no is not null
     27* order by 1, decode(val1, 'Loto', 1, 'Inst Tk', 2, 3)
    SQL> /
    
    RETAILER_N TERMINAL_N RETAILER_NAME                  VAL1       VAL2       VAL3       VAL4       VAL5       VAL6       VAL7       VAL8       VAL9       VAL10
    ---------- ---------- ------------------------------ ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ---------- ----------
    10000      1000006    XXXX XXXX XX Default Location  Totals     0.00       0.00       0          0.00       0          0.00       0          0.00       0
    10000      1000008    XXXX XXXX XX Default Location  Totals     0.00       0.00       0          0.00       0          0.00       0          0.00       0
    200101     20010100   XXXXXXX Popular Store          Loto       36,100.00  0.00       0          0.00       36         -5,646.00  0          0.00       0
    200101     20010100   XXXXXXX Popular Store          Inst Tk    22,000.00  0.00       0          0.00       166        -9,360.00  0          0.00       0.00
    200101     20010100   XXXXXXX Popular Store          Totals     58,100.00  0.00       0          0.00       202        -15,006.00 0          0.00       0
    200103     20010300   XX XXXXXXXX Snack              Loto       35,980.00  0.00       0          0.00       20         -3,426.00  0          0.00       0
    200103     20010300   XX XXXXXXXX Snack              Inst Tk    14,000.00  0.00       0          0.00       157        -9,180.00  0          0.00       0.00
    200103     20010300   XX XXXXXXXX Snack              Totals     49,980.00  0.00       0          0.00       177        -12,606.00 0          0.00       0
    
    8 rows selected.
    
    SQL>
    

    Published by: BluShadow on January 22, 2010 13:37
    added the retailer's name as well, but out anonymous that we dislike the actual data on the forums... ;)

  • How is it, I can't insert into table inside the function?

    If I have a simple function that takes the same data with SELECT... IN... and then the information I need to insert back to the same table, but the error message says I can't insert, update, delete on a table I'm working on, but I understand that is SELECT... Will be actually copy the data from a select query in these variables that I use in my SQL function. So why, after completing Select I can't update in my SELECT stopped working already on the table.

    Procedures may not be called from a SQL statement.

    However, you can [call procedures PHP | http://www.oracle.com/technology/pub/articles/oracle_php_cookbook/fuecks_sps.html].

    Justin

  • Update/insert into table in another schema

    Hello

    I have a custom table that is located in another schema used by our dashboard for custom tables. I want to allow users to add/edit users and the security groups for dashboards.

    I see two possible solutions to this issue, I was wondering if anyone has done so and has a better solution or pointers.

    Possible solutions:

    1. move the table to the APEX workspace. Not desirable, would lead to changes in the Production for the pools of connections in the repository.

    2. create a temporary table where you would load the security table data when the user wishes to add/modify records in the security table and then use triggers to update the table by using the synonym to the table.

    Any help would be appreciated.

    Thank you
    Rob

    Modify the procedure to look like to...

    create or replace PROCEDURE UPDATE_TABLE(p_table IN VARCHAR2,
                                             p_column IN VARCHAR2,
                                             p_value IN VARCHAR2,
                                             p_condition IN VARCHAR2)
    AS
    v_sql_stmt VARCHAR2(4000);
    BEGIN
      v_sql_stmt := 'UPDATE ' || p_table || '  SET ' || p_column || ' = ' || p_value || ' WHERE ' || p_condition;
      EXECUTE IMMEDIATE v_sql_stmt;
      COMMIT;
    END UPDATE_TABLE;
    
    {code}
    
    Edited by: Tyson Jouglet on Sep 25, 2008 8:03 AM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    
    
  • How to add the primary key for the table with the existing data?

    The table is already busy data. There was no primary key before, so for each column, there are some duplicate values.

    I want to add a new column, which should be of the integer data type and can automatically incremented, from 001. I tried with Oracle SQL Developer, but it says "ORA-01758: table must be empty to add mandatory (NOT NULL) column. How can I do? Thank you!

    Hello

    Look for the [ALTER TABLE | http://download.oracle.com/docs/cd/B28359_01/server.111/b28286/statements_3001.htm#sthref4803] command to find out how to add a column (step (1)) and a (step (3)) constraint to an existing table.

    For the step (2):

    CREATE SEQUENCE  employee_id_seq
    START WITH  1
    ;
    
    UPDATE  employee
    SET     id  = employee_id_seq.NEXTVAL;
    

    When you create a sequence, START WITH 1 is the default value, so that the line is not really necessary above... I've included just to show how you could start with any number you have chosen.

  • How to get generated automatically the primary key to create procedure

    I have a service of physical data corresponding to a table named ACCOUNT. The primary key on the table is called ACCOUNT_ID. There's a trigger on the database which generates the primary key value and adds it during an insert. I would like to have this primary key value returned by the procedure of creation of physical data service. Any ideas on how this can be done? Thanks in advance.

    as the primary key automatically obtained by ODSI leave a sequence in the DB and used during a procedure for creating

    Go to the design for the physical data service view

    Click the column which is filled from the sequence.

    In the Properties tab (bottom window), under general, for automatic numbering, click the 'Value' column, select sequence. You get a noise on some things have changed, just click OK. With AutoNumber = sequence setting, this column appears as optional (question mark).

    Just below that, for purpose of sequence, type the name of the sequence (you can also specify MYSCHEMA. In case the sequence SEQUENCE_NAME is under another schema).

    When you create objects SDO - leave the update vacuum column.

    that is if he were CUSTOMER_ID, your client would look like this...


    John
    Smith

    and when you read it back to the database, it would be...


    38738
    John
    Smith

    Published by: mikereiche on April 28, 2009 11:40

  • Impossible to insert a 1 d table in a 2D array using "insert into array.

    Hi all

    I have a very simple problem.

    I try to insert a table 1 d as a column in a table 2D using 'insert into array"as stated in image1.

    When I try to connect the table 1 d in the "new element/sub-table" terminal I get the error indicated in image2.

    According to the help files, I should be able to wire a table of size n-1 this as the 'new item/sub-table"terminal. In other words

    I should be able to connect a table 1 d here.

    Can someone tell me what I am doing wrong?

    Thanks for your help,

    Apparently I had converted the table to float in a 'worksheet chain' and I needed to convert it into an array before sending it to 'insert into array.

    Discover image3 for more details.

  • Diagram of all the tables list of primary key column names

    Hi people,

    I have a Scott user for example, I want to retrieve all tables primary key column names in the user Scott.

    can someone help me please.

    Thanks in advance,
    karmaya

    You can log in to SCOTT and try this

    select c.constraint_name
         , cc.table_name
         , cc.column_name
      from user_constraints c
      join user_cons_columns cc
        on c.constraint_name = cc.constraint_name
     where c.constraint_type = 'P';
    
  • Bad generation of DDL for indexes primary key partitioned - lost partitions

    Hello

    In our design of the database, we want to divide some tables and their indexes. The partition type is hash indexes must be local, also divided No problem affecting storage of the table partitions. Also no aucun probleme problem with the index partitions, not included the primary key.

    Our problem appears in the generation of DDL: partitions of tables and indexes are generated fine except the primary partitions it shows key - phrase-'alter table' primary key as if it was not partitioned.

    Apparently indexes primary keys must be generated as the other indices, is it not?

    Thanks in advance,

    Bernat Fabregat

    Published by: Berni 11/29/2010 12:37

    Hello Bernat,

    for local partitioning, you need to create indexes separated on column PK (if you do not already). Set partitioning for this index, and then in the dialog box for the primary key in the physical model:
    (1) in the 'Général' tab, clause "with the help of the index' - select 'by the name of the index.
    (2) in tab 'using Index' - 'Existing Index' drop-down list box - select defined index.

    Global partitioning can be created directly on the primary key in the physical model.

    Philippe

  • Problem with the primary key

    Hi all
    I have a table with the same data repeat 2 times. I mean that the lines are depating twice. so now, I create a primary key for the table. He throws me an error saying voilation key primary. I'll give you the clear script.

    create table employee)
    ID VARCHAR2 (4 BYTE) NOT NULL,
    First name VARCHAR2 (10 BYTE),
    VARCHAR2 (10 BYTE) last_name,
    START_DATE DATE,
    End_date DATE,
    Number (8.2) of salary.
    City VARCHAR2 (10 BYTE),
    Description VARCHAR2 (15 BYTE)
    )


    insert into employee values ('01', 'Jason', 'Martin', to_date('19960725','YYYYMMDD'), to_date('20060725','YYYYMMDD'), 1234.56, 'Toronto', 'Program');
    insert into employee values ('02', "Alison", "Mathews', to_date('19760321','YYYYMMDD'), to_date('19860221','YYYYMMDD'), 6661.78, 'Vancouver', 'Tester');
    insert into employee values ('03', 'James', 'Smith', to_date('19781212','YYYYMMDD'), to_date('19900315','YYYYMMDD'), 6544.78, 'Vancouver', 'Tester');
    insert into employee values ('04', 'Celia', 'Rice', to_date('19821024','YYYYMMDD'), to_date('19990421','YYYYMMDD'), 2344.78, "Vancouver", "Manager");
    insert into employee values ('05', 'Robert', 'Black', to_date('19840115','YYYYMMDD'), to_date('19980808','YYYYMMDD'), 2334.78, 'Vancouver', 'Tester');
    insert into employee values ('07', 'David', 'Larry', to_date('19901231','YYYYMMDD'), to_date('19980212','YYYYMMDD'), 7897.78, 'New York', 'Manager');
    insert into employee values ('06', 'Linda', 'Green', to_date('19870730','YYYYMMDD'), to_date('19960104','YYYYMMDD'), 4322.78, 'New York', 'Tester');
    insert into employee values ('08', 'James', 'Cat', to_date('19960917','YYYYMMDD'), to_date('20020415','YYYYMMDD'), 1232.78, 'Vancouver', 'Tester')
    insert into employee values ('07', 'David', 'Larry', to_date('19901231','YYYYMMDD'), to_date('19980212','YYYYMMDD'), 7897.78, 'New York', 'Manager');
    insert into employee values ('06', 'Linda', 'Green', to_date('19870730','YYYYMMDD'), to_date('19960104','YYYYMMDD'), 4322.78, 'New York', 'Tester');


    The table is now with 10 columns

    ID FIRST_NAME LAST_NAME START_DAT END_DATE SALARY CITY DESCRIPTION
    ---- ---------- ---------- --------- --------- ---------- ---------- ---------------
    Jason Martin 25 July 96 01 25 July 06 1234.56 Toronto programmer
    02 Alison Mathews 21 March 76 February 21, 86 6661.78 Vancouver Tester
    03 James Smith December 12, 78 March 15, 90 6544.78 Vancouver Tester
    04 Celia rice 24 October 82 21 April 99 2344.78 Vancouver Manager
    Robert Black 05 January 15, 84 8 August 98 2334.78 Vancouver Tester
    Linda Green 06 July 30, 87 January 4, 96 4322.78 tester of New York
    Manager of New York 07 David Larry 31 December 90 February 12, 98 7897.78
    08 James Cat 17-AUG-96 April 15 02 1232.78 ester of Vancouver


    Create a primary key for the table

    "Employee to ALTER TABLE PRIMARY KEY (ID, First_Name, Last_Name, start_date, end_date,
    Salary, city, Description); »

    I get error voilation primary key

    IS IT POSSIBLE TO CREATE THE KEY PRIMARY ON THE TABLE WITH ON THE DELETION OF THE DATA?
    Is IT POSSIBLE CREATING PRIMARY KEY USING 'GROUP BY' FUNCTION or OTHER FUNCTIONS?

    Published by: user11872870 on September 23, 2010 17:41

    Primary key columns cannot contain NULL values. If you tried to create a primary key constraint, you will get an error like this:

    ERROR at line 1:
    ORA-01449: column contains NULL values: cannot alter to NOT NULL
    

    However, you can add a unique constraint by doing something like the following:

    ALTER TABLE test ADD CONSTRAINT test_unq UNIQUE (column1, column2);
    

    I still wonder why you take the approach you take. I have a vague feeling that're missing us the key pieces of information to recommend the correct solution.

Maybe you are looking for