how to set serveroutput on using jdbc connection i

2019-08-11 07:30发布

问题:

I am trying to execute a block of PL/SQL code using JDBC request as below

set serveroutput on; 
declare
..
BEGIN
DBMS_OUTPUT.ENABLE();
..
..
DBMS_OUTPUT.PUT_LINE(X);
END;

But I am getting error as ORA-00922: missing or invalid option in the Response. If I remove the set serveroutput on, the SQL block is executing successfully. But I am not getting any values in the Response.

I tried to run the exact same piece of SQL block in SQL Developer and it does show me the values expected.

How do I run this block of code and get the values to be populated in JMeter ?

回答1:

set serveroutput on SQLPlus specific command. You have to call DBMS_OUTOUT.GET_LINES after PL/SQL block execution.



回答2:

Tweaking an old answer, you could create a function that lets you get the dbms_output buffer as a result set - which may be easier for you handle from JMeter:

create or replace function get_lines
return sys.odcivarchar2list pipelined is
  lines dbms_output.chararr;
  numlines integer;
begin
  numlines := 999;
  dbms_output.get_lines(lines, numlines);
  if numlines > 0 then
    for i in 1..numlines loop
      pipe row (lines(i));
    end loop;
  end if;
end;
/

After executing your block you can query:

select * from table(get_lines);

You canread more about how dbms_output.get_lines works in the documentation. You might be able to call it directly from Jmeter, as @ibre5041 suggested. Or there may be a better alternative to using dbms_output at all.