0

i had a problem when i am using dbms_output package. When i am executing the following code it display integer is 0

declare
v integer;
asq dbms_output.chararr;
begin
dbms_output.put('hi');
dbms_output.put_line('hello!');
asq(1):='sun';
asq(2):='ant';
dbms_output.put_line(asq(1));
dbms_output.put_line(asq(2));
dbms_output.get_lines(asq,v);
dbms_output.put_line('integer is '||v);
end;

but when i am executing the following code i am getting integer is 3

declare
v integer:=5;
asq dbms_output.chararr;
begin
dbms_output.put('hi');
dbms_output.put_line('hello!');
asq(1):='sun';
asq(2):='ant';
dbms_output.put_line(asq(1));
dbms_output.put_line(asq(2));
dbms_output.get_lines(asq,v);
dbms_output.put_line('integer is '||v);
end;

can any one help me why the variation is there in the two procedures

Noel
  • 10,152
  • 30
  • 45
  • 67
Smart003
  • 1,119
  • 2
  • 16
  • 31

1 Answers1

1

As per documentation, the second parameter to GET_LINES procedure is IN OUT parameter. It tells the procedure, number of lines to be retrieved from buffer. After the procedure call, it holds number of lines actually retrieved.

In your first example, the value of v is null. So no lines are retrieved and v is assigned the value 0.

In your second example, the value if v is 5. So you are requesting 5 lines, but since there are only three lines(hihello!, sun, ant), three lines are put into array asq and v is assigned 3.

Noel
  • 10,152
  • 30
  • 45
  • 67