Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.server -> Re: PL/SQL Declare and Define a variable
Oxnard wrote:
> I'm just wondering if there's anyway to do this, I guess it could help
> readability.
>
> if I have a procedure:
>
> create or replace procedure test as
> v_test NUMBER := 25; -- Works no big deal
> v_test1 NUMBER := select my_valid_sequence.nextval from dual; -- does
> not work
> BEGIN
> -- So I end up doing with v_test1 properly defined
> select my_valid_sequence.nextval into v_test1 from dual;
> END;
> /
>
> The "select my_valid_sequence.nextval into v_test1 from dual;" is OK but it
> seems to me the code would be a bit easier to read if I could Define the
> variable in the declarative section. My question is without using a cursor
> can a select be put into the declarative section?
>
> Thanks
Depending on where you are using the sequence why are you selecting it at all?
CREATE TABLE test (
testcol NUMBER(5));
CREATE SEQUENCE seq;
BEGIN
INSERT INTO test
(testcol)
VALUES
(seq.NEXTVAL);
END;
/
-- Daniel A. Morgan University of Washington damorgan_at_x.washington.edu (replace 'x' with 'u' to respond)Received on Thu Sep 30 2004 - 00:03:32 CDT