Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get the return value from a function in Oracle using Toad

Tags:

oracle

toad

How do I find out in Toad what the return value of a function is?

I'm running something like this code:

declare r number;
begin
    r:= packagename.functionname(paraname);
end;

I can't work out how to get "r" returned to the data grid, some posts suggest using DBMS output but nothing is written to it when I run the code.

The function performs updates, commits, calls other functions and has cursors in it.

like image 895
Stagg Avatar asked Jan 28 '11 10:01

Stagg


People also ask

How can a function return a value in PL SQL?

The function must contain a return statement. The RETURN clause specifies the data type you are going to return from the function. function-body contains the executable part. The AS keyword is used instead of the IS keyword for creating a standalone function.

Can procedure return a value in Oracle?

A stored procedure does not have a return value but can optionally take input, output, or input-output parameters. A stored procedure can return output through any output or input-output parameter.

How do I view Toad output?

Right-click the lower pane and select Desktop | DBMS Output. Make sure the Toggle Output On/Off button is on ( ) in the DBMS Output tab. Then, set the interval in the Polling Frequency box. If the toggle is on, Toad periodically scans for and displays DBMS Output content.

How do I view a function in Toad?

Open Explorer by click on icon in main menu (Fig. 1) or by Tools -> Explorer. In explorer : for Treelist view expand Schemas -> [your schema name] -> Functions.


1 Answers

begin
    dbms_output.put_line(packagename.functionname(paraname));
end;

You'll need to turn output on before running this. To do that, select the "DBMS Output" tab at the bottom of the editor, then click the leftmost button under the tab (it should depict a red circle, with the tooltip "Turn Output On" (if it's a green circle, output is already on)).

The results of the query will be written to the "DBMS Output" window, not the "Data Grid" (you may have to wait a few seconds for the polling to pick up the results). If you use a user-defined type or a ref cursor, this will be insufficient and you'll need to process the results in the anonymous block before writing them out.

like image 53
Allan Avatar answered Oct 14 '22 09:10

Allan