Home » Developer & Programmer » Forms » last record.......
last record....... [message #221168] Sat, 24 February 2007 11:53 Go to next message
rajat_chaudhary
Messages: 141
Registered: November 2006
Location: india
Senior Member

hi everyone,
how should i will get last record of a table in 9.1

please assist me ,it's urgent.......
Re: last record....... [message #221173 is a reply to message #221168] Sat, 24 February 2007 12:56 Go to previous messageGo to next message
Littlefoot
Messages: 20897
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
It depends on what you call "the last record". In a relational database, there's no first, last or any other record, unless you specify how to order records using the ORDER BY clause.
Re: last record....... [message #221176 is a reply to message #221173] Sat, 24 February 2007 13:28 Go to previous messageGo to next message
rajat_chaudhary
Messages: 141
Registered: November 2006
Location: india
Senior Member

according to u sir, if i will go for "order by" clause then it gives me according to ascending order not the last record but either by useing sql or by pl/sql ,i want only last record please try to give me result,,,,,,,,,,,,,,
i awaited for ur result /..............
Re: last record....... [message #221181 is a reply to message #221176] Sat, 24 February 2007 15:12 Go to previous messageGo to next message
Littlefoot
Messages: 20897
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
OK, but I still don't know how do you define "last record". Last inserted into a table? The one with smallest value in one of the columns? Something different?

It would help if you could provide an example of what you have and what you'd like to get as a result, or explain it with more than a single sentence.
Re: last record....... [message #221604 is a reply to message #221181] Tue, 27 February 2007 11:45 Go to previous messageGo to next message
rajat_chaudhary
Messages: 141
Registered: November 2006
Location: india
Senior Member

actually i have a table having lacs of records .........
and in FORMS i want that whenever my FORM will open ,there should be a display item which shows an additional value in the last value............
suppose i have a table in which last record having an employee id 100 and now when i open my form to enter some data in that table ,that display field should show me 101,, by that i don't retrieve data table for last value of employee id............. now i hope u get my question
please try to give me reply as soon as it possible because i need it very urgently.................

NOTE :- ACTUALLY I GET IT (NEXT VALUE IN DISPLAY FIELD) IN ORACLE 9.2.0.1.0 BUT I WANT THE SAME RESULT IN 9.1 ALSO. THE QUERY WHICH I FIRE IN 9.2 IS...........

FOR AN EXAMPLE... NAME OF DISPLAY ITEM IN FORMS IS 'NEXT_VALUE'..........
-----------------------------------------------------------------
DECLARE
X NUMBER;
BEGIN
SELECT EMPLOYEE_ID
INTO X
FROM (SELECT EMPLOYEE_ID FROM EMPLOYEES ORDER BY ROWNUM DESC)
WHERE ROWNUM = 1;
:NEXT_VALUE := X + 1;
END;
-----------------------------------------------------------------
IT GIVES ME LAST VALUE OF EMPLOYEE_ID........
Re: last record....... [message #221613 is a reply to message #221604] Tue, 27 February 2007 12:27 Go to previous messageGo to next message
Littlefoot
Messages: 20897
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
Forms? So why did you post a question on Reports forum?

Basically, what you are saying is wrong. As long as it will be fine in a single-user environment, it is about to fail as soon as this form enters a multi-user environment. Why? Because, sooner or later, two users will run the same form at the same time and - using that trigger - create the same ID. For such a purpose, SEQUENCE is a better choice. You'd simply select sequence_name.nextval and that'll do it. This value can be obtained either in a form or using a database trigger.

Furthermore, your code can be written a little bit simplest:
SELECT NVL(MAX(employee_id), 0) + 1
INTO something
FROM employees;

Finally, although I don't have neither 9.2.0.1.0 nor 9.1 to test it, I believe those versions are similar enough to support the code you've written.
Re: last record....... [message #221614 is a reply to message #221613] Tue, 27 February 2007 12:50 Go to previous messageGo to next message
rajat_chaudhary
Messages: 141
Registered: November 2006
Location: india
Senior Member

but if i am not wrong according to ur query 1 is added in max employee_id and then display item shows the +1 value of employee_id

but in my table there are some records which are at 100th position having employee_id greater than latest provided employee_id ,which creates a problem because i get an employee_id with added +1 in the maximum one ,not in the latest entered employee_id........
please try again.....
Re: last record....... [message #221712 is a reply to message #221614] Wed, 28 February 2007 02:39 Go to previous messageGo to next message
Maaher
Messages: 7062
Registered: December 2001
Senior Member
You are scaring me. You are bound to run into problems with your approach. Oracle has sequences for generating unique id's. Granted, sequences have gaps but that's not a real problem.

MHE
Re: last record....... [message #221785 is a reply to message #221168] Wed, 28 February 2007 07:13 Go to previous messageGo to next message
krishna123
Messages: 4
Registered: August 2006
Junior Member
i think if i am not wrong this may help u


select * from emp where rowid=(select max(rowid) from emp)
Re: last record....... [message #221801 is a reply to message #221785] Wed, 28 February 2007 09:03 Go to previous messageGo to next message
Maaher
Messages: 7062
Registered: December 2001
Senior Member
krishna123 wrote on Wed, 28 February 2007 14:13
i think if i am not wrong this may help u
You are wrong. ROWID has nothing, I repeat: NOTHING, to do with order of any kind. Not even order of insert. This is fact.

MHE
Re: last record....... [message #221837 is a reply to message #221168] Wed, 28 February 2007 11:02 Go to previous messageGo to next message
rajat_chaudhary
Messages: 141
Registered: November 2006
Location: india
Senior Member

thanks krishna123 , actually i can't make out that point........

but thanks again...............
GOD BLESS YOU............
Re: last record....... [message #221841 is a reply to message #221837] Wed, 28 February 2007 11:14 Go to previous message
Littlefoot
Messages: 20897
Registered: June 2005
Location: Croatia, Europe
Senior Member
Account Moderator
You seem to keep relying on false presumptions. Why do you insist on simple solutions which are wrong, instead of listening to advices which suggest you different, but correct approach to the solution of your problem?
Previous Topic: TITLE BAR CHANGE
Next Topic: beginers of d2k
Goto Forum:
  


Current Time: Tue Dec 06 16:20:34 CST 2016

Total time taken to generate the page: 0.13090 seconds