15

I want to declare multiple variable in one line, Is there any way to write it ?

DECLARE
A integer :=10;
B integer :=5;
BEGIN

END;

i want to declare a and b in one line.

Thanks in Advance,

3
  • i have not come across this but it can be done using collection or record datatype Commented Mar 20, 2014 at 8:19
  • off topic, just curious here, why do you want to do this? Commented Mar 20, 2014 at 8:19
  • I, for one, would love to see this syntax (seen in some other languages) added to PL/SQL, e.g. a, b, c, d, e integer; although I'm not sure how defaults would work. Commented Mar 24, 2014 at 5:59

2 Answers 2

20

No idea why you'd intentionally make your code less readable, but just... put them on one line:

set serveroutput on
DECLARE
  A integer :=10;B integer :=5;
BEGIN
  dbms_output.put_line(a ||':'|| b);
END;
/

anonymous block completed
10:5

The semicolon is a statement separator within PL/SQL and it doesn't matter whether or not you have whitespace or new lines; unlike plain SQL run in SQL*Plus, say, where a new statement after a separator does have to be on a new line, but that's a client thing.

Maybe you mean something else though...

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks for your help, But is there any better way for this ?
@AdarshPatel - better in what way? Are you asking to define two variables in one statement? That can't be done with scalar variables.
I think he was looking for something like this, but for PL/SQL: stackoverflow.com/questions/6202818/…
6

no, this is the way it works in PLSQL.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.