CREATE SEQUENCE in jsp

Dear all
i have one question would like to ask someone who can help that .
if when i create one table with sequence in that table when i want to add any value use jsp script how can i declare sequence data type?
for example
in sql command line = INSERT INTO test VALUES( some_sequence.nextval
and how can i defind some_sequence.nextval in jsp page ?
what should i use ? string or int

Yes, it's possible to create classes inside JSP files.
<%!
class Whatever {
   String variable = "java";
   void doSomething() {
      // Doing nothing :) ...
%>

Similar Messages

  • Create sequence product_seq in jsp

    dear all
    when i use create sequence product_seq start with 1 increment by 1
    this function in databae and
    how can i declare int type in jsp ?
    int i = product_seq.nextval ?

    Hello,
    i want to create online shopping cart using html and JSP.
    At first i want to create 1html page where login ad logup optios are provided. After his login, a JSP page containing 3 links namly T-shirts,Jeanspat and Formals is displayed.
    After user select any of the link it must go to particular page.
    There, option of color, size is provided.
    And some 5 to 6 items are displayed with its pfxd prices.
    And in the same page a cart is provided. Whe the user selects(clicks) any item the same must display in cart.
    In the same page link to T-shirts,Jeanspat and Formals is displayed agaiT-shirts,Jeanspat and Formals is displayed agaiT-shirts,Jeanspat and Formals is privided again.
    next page must show the items selected. And finally it must show the "thank you" page stating that your delivary will be delivered to you within 24 hrs.
    Thanks in advance ,
    sameer

  • Oracle sequence from JSP

    Hi,
    I have to generate sequence numbers in Oracle and access it through my JSP page. For that i
    created a sequnce in Oracle as:
    create sequence trans_no increment by 1 start with 1 maxvalue 10000 minvalue 1;
    and in my JSP page, the following code is given:
    ResultSet resultSet=db.executeQuery("select trans_no.nextval from dual");
    resultSet.next();
    int transaction_no=resultSet.getInt("trans_no");
    where db is my bean. But it is giving error. Is my code wrong? Please help.
    Suman, Kochi

    There is a mistake in mapping for ResultSet with the query you executed.
    You have to modify either the query as
    ResultSet resultSet=db.executeQuery("select trans_no trans_no.nextval from dual");
    or have to change retreival from ResultSet to
    int transaction_no=resultSet.getInt(1);
    This should work now.
    Try this and see...

  • CREATE SEQUENCE from a stored procedure

    Hello,
    Is it possible, to create a sequence object from an own written stored procedure? Can I reinitialize the actual value of a sequence object without recreating it from a stored procedure?
    Thank you for recommendations,
    Matthias Schoelzel
    EDV Studio ALINA GmbH
    Bad Oeynhausen

    maybe this example might be of some help.
    SQL> create or replace procedure dy_sequence (pSeqName varchar2,
      2                                           pStart number,
      3                                           pIncrement number) as
      4    vCnt     number := 0;
      5  begin
      6    select count(*) into vCnt
      7      from all_sequences
      8     where sequence_name = upper(pSeqName);
      9 
    10    if vCnt = 0 then
    11      execute immediate 'create sequence '||pSeqName||
    12                        ' start with '||to_char(pStart)||
    13                        ' increment by '||to_char(pIncrement);
    14    else
    15      execute immediate 'alter sequence '||pSeqName||' increment by '||to_char(pIncrement);
    16    end if;
    17  end;
    18  /
    Procedure created.
    SQL> -- create the sequence by calling the dy_sequence procedure
    SQL> execute dy_sequence ('test_sequence',1,1);
    PL/SQL procedure successfully completed.
    SQL> select test_sequence.nextval from dual;
       NEXTVAL
             1
    SQL> -- alter the sequence to increment by 2
    SQL> execute dy_sequence ('test_sequence',0,2);
    PL/SQL procedure successfully completed.
    SQL> select test_sequence.nextval from dual;
       NEXTVAL
             3
    SQL>

  • Error while Creating sequence. Please help

    I'm using below script to create sequence but getting error
    Error report:
    SQL Error: ORA-01722: invalid number
    01722. 00000 - "invalid number"
    CREATE SEQUENCE BL_BTN_MASTER_SEQ
    MINVALUE 1
    MAXVALUE 999999999999999999
    INCREMENT BY 1
    START WITH (SELECT MAX(BULLETIN_MASTER_ID)+1
    FROM BL_BTN_MASTER)
    NOCACHE;
    FYI..Data type of bulletin_master_id column is NUMBER(22,0)
    PLease help.
    Edited by: user11228834 on May 29, 2013 10:22 AM
    Edited by: user11228834 on May 29, 2013 10:23 AM
    Edited by: user11228834 on May 29, 2013 10:25 AM

    Oracle doesn't like the "(select max(bulletin_master_id)+1 from bl_btn_master)' statement embedded in the CREATE SEQUENCE statement because if you look at the syntax it is expecting an acual number. You could use execute immediate to create the sequence this way:
    {code}
    declare
    v_seq number;
    v_statement varchar2(200);
    begin
    select max(bulletin_master_id)+1
    into v_seq
    from bl_btn_master;
    v_statement := 'CREATE SEQUENCE BL_BTN_MASTER_SEQ ' ||
    'MINVALUE 1 ' ||
    'MAXVALUE 999999999999999999 ' ||
    'INCREMENT BY 1 ' ||
    'START WITH ' || v_seq ||
    'NOCACHE';
    execute immediate(v_statement);
    end;
    {code}

  • Assigning a 'dynamically created sequence' value to a variable

    in my procedure i am creating a sequence on the fly, i am preparing the name with some passed parameters like below
    v_seq_name := 'seq_'||loadid||v_table_name;
    execute immediate 'CREATE SEQUENCE '||v_seq_name||' MINVALUE 1 MAXVALUE 999999999999999999999999999 START WITH 1 increment by 1 cache 20';
    and now after doing some operations i need to assign the current value of sequence to a number variable i tried following but not working
    1) v_curr_value : = v_seq_name.currval ;
    2) select v_seq_name||'.nextval' into v_curr_value from dual;
    can you please suggest me how i can get the value in plsql block.

    DIVI wrote:
    in my procedure i am creating a sequence on the fly, i am preparing the name with some passed parameters like below
    v_seq_name := 'seq_'||loadid||v_table_name;
    execute immediate 'CREATE SEQUENCE '||v_seq_name||' MINVALUE 1 MAXVALUE 999999999999999999999999999 START WITH 1 increment by 1 cache 20';
    and now after doing some operations i need to assign the current value of sequence to a number variable i tried following but not working
    1) v_curr_value : = v_seq_name.currval ;
    2) select v_seq_name||'.nextval' into v_curr_value from dual;
    can you please suggest me how i can get the value in plsql block.Well, you haven't given the error you are getting but I guess the procedure isn't compiling? You need to execute immediate any reference to the sequence.
    Having said that, your architecture is probably wrong if you are dynamically creating things in a procedure.
    Why do you need to create them dynamically?

  • Issue in creating a new JSP in Quoting

    I have created a new JSP in the quoting. That JSP is displaying the data properly but the cue card menu is not visible in that JSP. Is there any mapping need to be done to make it visble.

    Thank you for the response.
    The JSP has a function defined in the menu structure. For a trial I copied an existing jsp into another and called the copied one. the side menu bar did not get displayed, but the content got displayed.
    Can you please tell me, if we create a new JSP page how many mappings need to done and what are they.

  • Issue in creating Sequence

    Hi All,
    I am using
    Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - 64bi
    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 - ProductionI have schema with following roles
    ALTER ANY OUTLINE
    CREATE ANY OUTLINE
    CREATE ANY SYNONYM
    CREATE DATABASE LINK
    CREATE MATERIALIZED VIEW
    CREATE PUBLIC DATABASE LINK
    CREATE VIEW
    DROP ANY OUTLINE
    DROP PUBLIC DATABASE LINK
    SELECT ANY TABLE
    UNLIMITED TABLESPACE
    CONNECT
    DBA
    EXP_FULL_DATABASE
    IMP_FULL_DATABASE
    OEM_MONITOR
    RESOURCEI can able create a sequence through SQLPLUS as well as from toad.
    SQL> CREATE SEQUENCE ROLE_ACTIVITY_SEQ START WITH 225006249 INCREMENT BY 1 MAXVALUE 9999999999999999999 MINVALUE 225006249 NOCYCLE CACHE 100 ORDER;
    Sequence created.
    SQL>when i try to create sequence dynamically through PL/SQL procedure getting error
    SQL> execute PROC_CLONE_BU;
    BEGIN PROC_CLONE_BU; END;
    ERROR at line 1:
    ORA-01031: insufficient privileges
    ORA-06512: at "SUPERNOVA.PROC_CLONE_BU", line 19
    ORA-06512: at line 1
    SQL>Even though I have DBA role for the schema. I don't know what privileges oracle still excepting..
    Pls guide me to resolve it..
    Thanks & Regards
    Sami

    Hi All,
    As said early creating sequence through dynamic SQL
    its creating sequence fine but when i try to use sequence in same procedure then procedure getting error..
    create or replace procedure proc_seq_genrate as
    begin
    EXECUTE IMMEDIATE 'CREATE SEQUENCE BU_ROLE_DSK_ITEM_SEQ START WITH 100 INCREMENT BY 1 MAXVALUE 9999999999999999999 '||
    'MINVALUE 100 NOCYCLE CACHE 100 ORDER';--- hard coded value 100 will changed according to  PK max value of the table .. for getting max value i will write SQL Query
    end;
    Procedure created.
    create or replace procedure proc_seq_genrate as
    begin
    EXECUTE IMMEDIATE 'CREATE SEQUENCE BU_ROLE_DSK_ITEM_SEQ START WITH 100 INCREMENT BY 1 MAXVALUE 9999999999999999999 '||
    'MINVALUE 100 NOCYCLE CACHE 100 ORDER';--- hard coded value 100 will changed according to  PK max value of the table .. for getting max value i will write SQL Query
    INSERT INTO ROLE_ACTIVITY (SELECT ROLE_ACTIVITY_SEQ.NEXTVAL, -98, ACTIVITY_CD, REC_ST, 1, ROW_TS, USER_ID, CREATE_DT, SYS_CREATE_TS, CREATED_BY FROM ROLE_ACTIVITY WHERE ROLE_ID=-99 );
    end;
    7     35     PL/SQL: ORA-02289: sequence does not existI have understood that its looking for Sequence but
    pls any one explain me why its looking sequence in compile time itself.. any way we are going to use the sequence only at run time right.. i would like to know is there any technical reason behind this..
    Thanks & regards
    Sami.

  • Creating sequences for all tables in the database at a time

    Hi ,
    I need to create sequences for all the tables in my database.
    i can create individually ,using toad and sqlplus.
    Can any one give me a code for creating the sequences dynamically at a time for all the tables.
    it is urgent ..
    Regards.

    I need to create sequences for majority of the tables that are having ID column
    which is sequences."The majority" is not the same as all. So you probably want to drive your generation script off the ALL_TAB_COLUMNS view...
    where column_name = 'ID'You need to think about this carefully. You might want different CACHE sizes or different INCREMENT BY clauses for certain tables. You might even (whisper it) want a sequence to be shared by more than one table.
    Code generation is a useful technique, but it is a rare application where one case fits all.
    Cheers, APC
    Blog : http://radiofreetooting.blogspot.com/

  • How to CREATE SEQUENCE in one table

    dear all
    the one thing i want to know when i use CREATE SEQUENCE in one table like this and then at that table
    CREATE SEQUENCE oproduct_sequence
    START WITH 1  INCREMENT BY 1 
    nocache
    create table oproduct(
    tname varchar2(20) not null,
    tid int default  oproduct_sequence.nextval
    the system indicat that i cannot use this way to create table , so i really want to know how can i achieve this method
    becuase when i want to insert inot table oproduct only use
    insert into oproduct  valuse('aaaa');
    and the result like
    aaaaa 1
    bbbb   2

    Actual name is before insert trigger. Some examples are listed below:
    Example Number 1 ...
    create sequence product_seq start with 1 increment 1
    create or replace trigger product_insert before insert for each row begin
    select productseq.nextval
    into :new.product_id
    from dual;
    end;
    Example Number 2 ...
    How to create an autoincrement field in a table with a sequence ...
    SQLWKS> create table bob(a number , b varchar2(21));
    Statement processed.
    First create a sequence
    SQLWKS> create sequence x ;
    Statement processed.
    Then create the trigger.
    create trigger y before insert on bob
    for each row
    when (new.a is null)
    begin
    select x.nextval into :new.a from dual;
    end;
    Example Number 3 ...
    First create a sequence:
    create sequence emp_no_seq;By default it increments by 1 starting at 0.
    Use its values when inserting data into the table:
    insert into t_emp values (emp_no_seq.nexval, 'Joe Black');~ Madrid.

  • Using dynamic query to create sequence

    Hello,
    I created the sequence dynamically in a Procedure, but when I executed, it gave me an Insufficient privileges error:
    SQL> create table dummy (id number, module_id varchar2(20), p_order number, status varchar2(1));
    SQL> insert into dummy values (10, 'test', 0, 'D');
    SQL> CREATE OR REPLACE PROCEDURE PRO_SEQ_ARRNGE(P_ID NUMBER) AS
    V_MOD DUMMY.MODULE_ID%TYPE;
    v_query1 varchar2(200);
    v_query2 varchar2(200);
    V_COUNT NUMBER;
    begin
    v_query1 := 'drop sequence unqid';
    v_query2 := 'create sequence unqid start with 1 increment by 1 minvalue 1';
    SELECT COUNT(*)
    INTO V_COUNT
    FROM USER_SEQUENCES
    WHERE SEQUENCE_NAME = 'UNQID';
    IF V_COUNT = 0 THEN
    execute immediate v_query2;
    ELSE
    execute immediate v_query1;
    execute immediate v_query2;
    END IF;
    SELECT distinct MODULE_ID INTO V_MOD FROM DUMMY WHERE ID = P_ID;
    update dummy
    set P_order = 0, status = 'D'
    WHERE ID = P_ID
    and module_id = v_mod;
    --COMMIT;
    execute immediate 'UPDATE DUMMY SET P_ORDER = UNQID.NEXTVAL WHERE MODULE_ID = V_MOD AND STATUS = ''A''';
    --COMMIT;
    END PRO_SEQ_ARRNGE;
    SQL> exec PRO_SEQ_ARRNGE(10);
    BEGIN PRO_SEQ_ARRNGE(10); END;
    ERROR at line 1:
    ORA-01031: insufficient privileges
    ORA-06512: at "SYSTEM.PRO_SEQ_ARRNGE", line 15
    ORA-06512: at line 1
    Can you please advise how to resolve it?
    Thanks in advance,
    Tinku

    When I try it, I get a different error
    SQL> create table dummy (id number, module_id varchar2(20), p_order number, status varchar2(1));
    Table created.
    SQL>  insert into dummy values (10, 'test', 0, 'D');
    1 row created.
    SQL>  CREATE OR REPLACE PROCEDURE PRO_SEQ_ARRNGE(P_ID NUMBER) AS
      2  V_MOD DUMMY.MODULE_ID%TYPE;
      3  v_query1 varchar2(200);
      4  v_query2 varchar2(200);
      5  V_COUNT NUMBER;
      6  begin
      7  v_query1 := 'drop sequence unqid';
      8  v_query2 := 'create sequence unqid start with 1 increment by 1 minvalue 1';
      9  SELECT COUNT(*)
    10  INTO V_COUNT
    11  FROM USER_SEQUENCES
    12  WHERE SEQUENCE_NAME = 'UNQID';
    13
    14  IF V_COUNT = 0 THEN
    15  execute immediate v_query2;
    16  ELSE
    17  execute immediate v_query1;
    18  execute immediate v_query2;
    19  END IF;
    20
    21  SELECT distinct MODULE_ID INTO V_MOD FROM DUMMY WHERE ID = P_ID;
    22
    23  update dummy
    24  set P_order = 0, status = 'D'
    25  WHERE ID = P_ID
    26  and module_id = v_mod;
    27  --COMMIT;
    28
    29  execute immediate 'UPDATE DUMMY SET P_ORDER = UNQID.NEXTVAL WHERE MODULE_ID = V_MOD AND STATUS = ''A''';
    30  --COMMIT;
    31
    32  END PRO_SEQ_ARRNGE;
    33  /
    Procedure created.
    SQL> exec PRO_SEQ_ARRNGE(10);
    BEGIN PRO_SEQ_ARRNGE(10); END;
    ERROR at line 1:
    ORA-00904: "V_MOD": invalid identifier
    ORA-06512: at "SCOTT.PRO_SEQ_ARRNGE", line 29
    ORA-06512: at line 1The problem is that you can't refer to a local variable like V_MOD in a dynamic SQL statement. You'd need to use a bind variable
    SQL> ed
    Wrote file afiedt.buf
      1   CREATE OR REPLACE PROCEDURE PRO_SEQ_ARRNGE(P_ID NUMBER) AS
      2  V_MOD DUMMY.MODULE_ID%TYPE;
      3  v_query1 varchar2(200);
      4  v_query2 varchar2(200);
      5  V_COUNT NUMBER;
      6  begin
      7  v_query1 := 'drop sequence unqid';
      8  v_query2 := 'create sequence unqid start with 1 increment by 1 minvalue 1';
      9  SELECT COUNT(*)
    10  INTO V_COUNT
    11  FROM USER_SEQUENCES
    12  WHERE SEQUENCE_NAME = 'UNQID';
    13  IF V_COUNT = 0 THEN
    14  execute immediate v_query2;
    15  ELSE
    16  execute immediate v_query1;
    17  execute immediate v_query2;
    18  END IF;
    19  SELECT distinct MODULE_ID INTO V_MOD FROM DUMMY WHERE ID = P_ID;
    20  update dummy
    21  set P_order = 0, status = 'D'
    22  WHERE ID = P_ID
    23  and module_id = v_mod;
    24  --COMMIT;
    25  execute immediate 'UPDATE DUMMY SET P_ORDER = UNQID.NEXTVAL WHERE MODULE_ID = :1 AND STATUS = ''A'''
    26    using v_mod;
    27  --COMMIT;
    28* END PRO_SEQ_ARRNGE;
    29  /
    Procedure created.
    SQL> exec pro_seq_arrnge(10);
    PL/SQL procedure successfully completed.Of course, I'm not using the SYSTEM schema. You should really, really avoid SYS and SYSTEM-- things often work differently there than they do normally. I also join the other folks that have tried to help you in suggesting that creating a sequence dynamically in a procedure is a very poor idea and almost certainly indicates that you need to reconsider your design.
    Justin

  • Create sequence, function and view all at once -script or something similar

    Hi I would like to know in what way can I write a script or something like that which would define names for a sequence, function and a view in the beginning (for example TEST_SEQ, TEST_FJ, TEST_VIEW...) and after that create this sequence, function and view with definitions like
    CREATE SEQUENCE  TEST_SEQ
    MINVALUE 1 MAXVALUE 999999999999999999999999999
    INCREMENT BY 1 START WITH 1 NOCACHE  NOORDER  NOCYCLE;
    create or replace FUNCTION TEST_FJ RETURN NUMBER AS
    tmp number;
    BEGIN
    select TEST_SEQ.NEXTVAL  into tmp from dual
    RETURN tmp;
    END TEST_FJ;
    and so on...
    In the end I would also like to grant some rights on these objects I just created:
    grant select on TEST_SEQ to public;
    grant execute on TEST_FJ to public;
    So my question is how to package all these things together so I can execute them from a single file in SQL Developer, and if i need to change the names of these tables I want do it in one place in the beginning of this script (or something like a script, I'm not sure what)...
    Thanks in advance!

    hi,
    hope help you...
    this is my basic generic solution...
    create or replace procedure createSequence( psequenceName in varchar2 ) is
    begin
    execute immediate 'create sequence ' || psequenceName ;
    execute immediate 'grant select on ' || psequenceName || ' to public ';
    end ;
    create or replace function getNextVal( psequenceName in varchar2 ) return number is
    queryText varchar2(100) := 'select <sequence_name>.nextval into :next_value from DUAL' ;
    next_value number ;
    begin
    queryText := replace(queryText,'<sequence_name>',psequenceName);
    execute immediate queryText into next_value ;
    return( next_value ) ;
    end ;
    Edited by: edogt on Nov 27, 2008 5:33 AM
    Edited by: edogt on Nov 27, 2008 5:35 AM
    Edited by: edogt on Nov 27, 2008 5:35 AM

  • Cannot use sqlplus variable in create sequence statement

    Hello!
    I would like to create a sequence object starting with a number retrieved from a select statement:
    var max_resp_no number;
    begin
    select max(substr(resp_no,2)) into :max_resp_no from brc_mast
    where substr(resp_no,1,1)='Z';
    end;
    print max_resp_no;
    drop sequence p659_resp;
    create sequence p659_resp start with :max_resp_no;
    It tells me that :max_resp_no is an 'invalid number';
    TIA,
    habeeb

    You need to do this entirely in PL/SQL. You can either create a procedure, or use an anonymous block. The procedure version is below. Just change the CREATE to a DECLARE to get an anonymous block.
    CREATE OR REPLACE PROCEDURE new_seq IS
    max_resp_no NUMBER;
    BEGIN
    SELECT to_number(MAX(SUBSTR(resp_no,2)))
    INTO max_resp_no
    FROM brc_mast
    WHERE SUBSTR(resp_no,1,1)='Z';
    EXECUTE IMMEDIATE 'DROP SEQUENCE p659_resp';
    EXECUTE IMMEDIATE 'CREATE SEQUENCE p659_resp START WITH '|| max_resp_no;
    END;
    SQL> CREATE SEQUENCE p659_resp START WITH 1;
    Sequence created.
    SQL> SELECT p659_resp.nextval from dual;
       NEXTVAL
             1
    SQL> SELECT * FROM brc_mast;
    RESP_
    Z001
    Z002
    Z003
    Z075
    SQL> exec new_seq;
    PL/SQL procedure successfully completed.
    SQL> select p659_resp.nextval from dual;
       NEXTVAL
            75Note that the user creating this procedure will need to have CREATE SEQUENCE granted explicitly for the procedure to work. The anonymous block version should work if CREATE SEQUENCE is granted through a role.
    John

  • How to create sequence when minvalue is unknown?

    I am currently migrating a lot of tables (that already have data) over to using sequences. I'd like to have a script that creates these sequences without having to hardcode the minimum value that the sequence should start at.
    I am trying to do something like this:
    create sequence mySeq minvalue (select max(id)+1 from table) increment BY 1 cache 20;
    This always gives the error "Invalid number". Can anyone provide some guidance on how to solve this problem?

    Like this..?
    SQL> declare
      2   min_val number;
      3   str varchar2(1000);
      4  begin
      5   select nvl(max(empno),0)+1
      6   into min_val
      7   from emp;
      8   str := 'create sequence seq1 start with '||min_val||' increment by 1 cache  20';
      9   execute immediate str;
    10  end;
    11  /
    PL/SQL procedure successfully completed.
    SQL> select seq1.nextval
      2  from dual;
       NEXTVAL
          7935
    http://download-uk.oracle.com/docs/cd/B19306_01/appdev.102/b14251/adfns_dynamic_sql.htm#i1006172                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • How to create sequence

    How to create sequence(Auto generated no in oralce) with out using Triggers?
    If i create trigger sequence of numbers are getting generated but in case if i want to include explicit sequence no at the end of the table say like '9999'...it is not getting updated
    Pls help very urgent..

    user2134711 wrote:
    How to create sequence(Auto generated no in oralce) with out using Triggers? Sequence is an oracle object used to create unique number sequence. It has no connection with trigger.
    Generally Sequence is used in a Trigger to generate some column value automatically. Something like the IDENTITY column used in SQL Server.
    If i create trigger sequence of numbers are getting generated but in case if i want to include explicit sequence no at the end of the table say like '9999'...it is not getting updated This totally depends on how you have written the trigger. If you can show your trigger code we can help you out.

Maybe you are looking for