Skip to Main Content
  • Questions
  • How to get FINAL One Line Text Message of "Any Query" in variable???

Breadcrumb

Question and Answer

Tom Kyte

Thanks for the question, Gokul.

Asked: November 28, 2014 - 10:19 am UTC

Last updated: November 28, 2014 - 11:31 pm UTC

Version: 11

Viewed 1000+ times

You Asked

Hi Guru,

I have a table which consist of columns like

sql_stmt varchar2(2000),
sql_output_msg varchar2(2000).


You know that, Every successful sql stmt comes with result msg like 10 Rows Updated, Grant Succeed, Table Created, Table Dropped etc...

I want to capture that last message into variable and update(populate) sql_output_msg with this message.

Please help me in that.

Thanks in Advance,
Virus

and Tom said...

I know that every successful sql statement comes with a return code and other possible metadata like the number of rows affected. I know that *no* sql statement "comes with a result msg like 10 rows updated"

That message is simply sqlplus, toad or sqldeveloper running your statement and then deciding "i will print on the screen the output of this for you". It is not part of the database - it is part of their user interface.

You would have to program your own UI to "capture" these (but you wouldn't be capturing them, you'd be *generating* them).


for example:



ops$tkyte%ORA11GR2> begin
  2      update emp set ename = lower(ename);
  3      dbms_output.put_line( sql%rowcount || ' rows updated!' );
  4  end;
  5  /
14 rows updated!

PL/SQL procedure successfully completed.



14 rows updated - we did that.

pl/sql procedure successfully completed - that is what sqlplus decided would be a nice thing to print on your screen after running your plsql block....


If you need to review this information, you'd have to spool out the output of what sqlplus wrote to you and retrieve it from the spooled file.




Is this answer out of date? If it is, please let us know via a Comment

More to Explore

PL/SQL demos

Check out more PL/SQL tutorials on our LiveSQL tool.

PL/SQL docs

PL/SQL reference manual from the Oracle documentation library