12

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,

Adarsh
  • 270
  • 1
  • 3
  • 16

2 Answers2

16

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...

Alex Poole
  • 183,384
  • 11
  • 179
  • 318
  • Thanks for your help, But is there any better way for this ? – Adarsh Mar 20 '14 at 08:19
  • @AdarshPatel - better in what way? Are you asking to define two variables in one statement? That can't be done with scalar variables. – Alex Poole Mar 20 '14 at 08:21
  • I think he was looking for something like this, but for PL/SQL: https://stackoverflow.com/questions/6202818/initializing-multiple-variables-to-the-same-value-in-java/31910261 – James Daily Oct 18 '17 at 12:13
6

no, this is the way it works in PLSQL.

Rene
  • 10,391
  • 5
  • 33
  • 46