Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

LINK TO THIS FORUM!

Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Feedback

"...I've learned more from your forums in 3 days than 3 months at school and on the job combined..."

Geography

Where in the world do Tek-Tips members come from?
bilalch (Programmer)
20 Oct 03 1:31

can any1 plz help me with an XMPLE,how to create and attach a sequence to a field in the table.

  thanks in advance
Helpful Member!  sem (Programmer)
20 Oct 03 4:08
You can not attach sequence to the field, though you may assign the value in trigger. Sequence has many options, but the simpliest (most common) command is

CREATE SEQUENCE <sequence name>

Then you may create "before insert row-level" trigger and assign sequence value to the field you need to be "attached":

CREATE SEQUENCE EMP_SEQ

CREATE TRIGGER EMP_BRI_TRG
BEFORE INSERT ON EMP
FOR EACH ROW
BEGIN
  select emp_seq.nextval into :new.empno from dual;
END;

Regards, Dima

bilalch (Programmer)
20 Oct 03 8:20
HI DEAR SEM,
 THANX FOR UR RESPONSE,
 PLZ TELL ME WUT'S THIS

  :new.empno

 IS IT THE TEXTBOX IN THE DATA BLOCK.

 AND THAT WHERE TO WRITE THIS TRIGGER

 THANX
 BYE
sem (Programmer)
20 Oct 03 9:40
You should write it in sql*plus or any other sql command tool. :new is obviously not a text field in Forms and trigger is obviously not a Forms trigger, because you've asked about "field in the table", not about field in Forms block. If you need to make it in Forms, you may create pre-insert trigger and select sequence value into text item, but that's completely another story

Regards, Dima

bilalch (Programmer)
21 Oct 03 0:27
hi dear sem,
 thanx for ur reply, but i want it on the form as i'm inserting values from the form.

 now i've a trigger "pre-text-item" like this

  begin
  select emp_seq.nextval into :block.txtitem from dual
  end;

 but it returns compilation error

 plz help me , i want the sequence no to b inserted when i'm going to insert the row.
sem (Programmer)
21 Oct 03 4:08
If the code provided is EXACT, add semicolon after dual at least. It would be much better if you provide a little bit more information about error, at least its code, because it may be caused by dozens of your mistakes: wrong field/block/table names, no access to sequence etc.

You may also set Default Value property for block.textitem as :SEQUENCE.emp_seq.NEXTVAL instead. The drawback is that you may have a lot of gaps in your values.

Regards, Dima

bilalch (Programmer)
21 Oct 03 6:59
thank u dear Dima,
 there was a little bit problem in my code now i've removed and tis working

 i'm so grateful to u , u really helped me a lot
 i didn't have the idea of sequences.

 thanks
bye
SheepDog (Programmer)
22 Oct 03 10:55
I would like to know if I have 100 records how can I bring them back in a sequentially? Like record 1, record 2, record 3, record 4, record 5 and so on.
sem (Programmer)
23 Oct 03 7:18
You may use ROWNUM pseudocolumn:

select ename, ROWNUM from emp

Note, that the records are "numbered" at the moment the result set already exists but before sorting it according to ORDER BY clause Thus conditions like rownum><some value> make no sence.

Regards, Dima

bilalch (Programmer)
24 Oct 03 0:10

if u hav sequence applied to your PK column, now how'll u refer this column as FK while u dont know wut's the PK value for some record.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close