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

Home -> Community -> Usenet -> c.d.o.misc -> Re: How to do this - SQL

Re: How to do this - SQL

From: Nuno Guerreiro <nuno-v-guerreiro_at_invalid.telecom.pt>
Date: Thu, 01 Oct 1998 13:44:04 GMT
Message-ID: <361385eb.11292207@news.telecom.pt>


On 1 Oct 1998 20:01:23 +0800, "Norazman Abu Sahir" <azhan98_at_tm.net.my> wrote:

>Greetings newsgroup member,
>
>I have two SQL-ORACLE question,
>
>1)How to write SQL statements that will fetch a certain field
> of the "last record in the table". Say table A which contains
> field named Dept. I realized before this in this newsgroup there is
> a way to get the "last 15" using rownum < 16. However how if I
> don't know how many records in the table but I just want to get
> the last one.
>
>2)The 2'nd question is regarding Oracle Report. Just to clarify
> my understanding. I have a report which have a PL/SQL inside.
> This PL/SQL was written in one of my function.
>
> I can insert a data into my table using sequence. Something like
> this. INSERT INTO TABLE1 (FIELD1,FIELD2)
> VALUES(SEQUENCE1.NEXTVAL, 10);
> It's perfectly OK and insert whatever next value on SEQUENCE1.
> However when I tried to assign the SEQUENCE1.CURRVAL to one of my
> variable it generate an error (outside of the DML operation).
>
> myvariable := SEQUENCE1.CURRVAL;
>
> Because it doesn't recognize SEQUENCE1.
>
> How to assign current value of SEQUENCE1 to my variable.Is it possible?
>
> Appreciate any help. Excuse me for asking siple question. I just another
> newbie...
>
> -NORAZMAN-
>
>

  1. Oracle doesn't necessarily select rows from a table in the same order in which they were inserted. Therefore, it doesn't make sense to select the last inserted row on the table without specifying any condition. Of course, if you have a field which stores any information concerning order of records (insertion_date, e.g.), then you can select the row which contains the maximum value of that field.
  2. You must use the following command:

select sequence1.currval into myvariable from dual;

Good luck,

Nuno Guerreiro



As I don't normally appreciate unsolicited commercial e-mail (widely known as SPAM), I encoded my e-mail address. If you want to reply by e-mail, please remove the text added to fool spam software

"The art of arts, the glory of expression and the sunshine that lights the light of letters  is simplicity"

                                                        Walt Whitman Received on Thu Oct 01 1998 - 08:44:04 CDT

Original text of this message

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