is there a simpler way to do this?

From: Keith Langer <tanalbit_at_aol.com>
Date: 21 Feb 2003 15:16:16 -0800
Message-ID: <15c7b652.0302211516.5819a704_at_posting.google.com>


I am tring to select the a MAX value from a table into a variable. In SQL Server, I would do the following:

declare _at_n_ID int
SELECT _at_n_ID = MAX(Change_ID) FROM Daily_Changes print _at_n_id

Is there a simple way to do this in Oracle? For now, the best I could come up with is a cursor or a for loop:

declare
  n_ID NUMBER := 0;

        cursor ChangeIDCursor IS SELECT MAX(Change_ID) MaxID FROM Daily_Changes where daily_id=1;

        cursor_val ChangeIDCursor%ROWTYPE;
BEGIN
OPEN ChangeIDCursor;
FETCH ChangeIDCursor INTO cursor_val;
  n_ID := cursor_val.MaxID;
  dbms_output.put_line('value is: ' || n_ID); CLOSE ChangeIDCursor;
end;

thanks,
Keith Received on Sat Feb 22 2003 - 00:16:16 CET

Original text of this message