Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.server -> Re: Strange PB !?

Re: Strange PB !?

From: Sybrand Bakker <postbus_at_sybrandb.demon.nl>
Date: Sun, 13 Jun 1999 09:52:51 +0200
Message-ID: <929260291.9662.0.pluto.d4ee154e@news.demon.nl>


Hi Wassim,
Just
create sequence key_seq start with 1 etc.. in your pl/sql code
begin
new_key_code := key_seq.nextval;
insert into table
values (new_key_code) etc.

You need to grant select to all users, who will need this sequence, and create public or private synonyms.
A sequence is not bound to any table!

Hth,

Sybrand Bakker, Oracle DBA

Wassim wrote in message <7jv0gf$l7i$1_at_nnrp1.deja.com>...
>
>
>Hi, all
>
>I've in many of my PL/SQL procedures to create a new record in a table
>just with Key code = Last key + 1, (key_code is the table primary key)
>
>to do this i've written the following PL/SQL code :
>
>------------------------------------------------------------------------
>last_key_code := 0;
>begin
>select max(key_code) into last_key_code from myTable;
>exception when OTHERS then last_key_code:=0; -- when myTable is empty !!
>end;
>
>htp.print(last_key_code);
>
>insert into myTable values (last_key_code+1,...);
>------------------------------------------------------------------------
>
>When myTable is empty this algorithm never works, when attemping to
>print value to 'last_key_code' in such situation (myTable is empty)
>nothing is printed, and 'insert into' procedure return error !!! i add
>an 'if' statment to make it work but doesn't solve the pb :
>
>----
>if last_key_code=null then last_key_code:=0; end if
>----
>
>I think that we can automate such operations by creating a 'sequence' ?
>how ?
>
>Anyone can help please?
>Thanks.
>
>Wassim,
>e-mail: net2000_at_francemel.com
>
>
>
>
>Sent via Deja.com http://www.deja.com/
>Share what you know. Learn what you don't.
Received on Sun Jun 13 1999 - 02:52:51 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US