I run following procedure in sql developer window to search all oracle tables for specific string and at the end in Statement Output window it says "anonymous block completed" and now can't understand where is result rows, how to get it?
thanks
We have option in SQL Developer
and also you have to execute your procedure as below
SET SERVEROUTPUT ON;
begin
dbms_output.put_line('Testing output');
end;
/
Click ->View->Dbms Output and then click + symbol on Dbms output window. now you can run the procedure and can see output.
Related
I'm new to Oracle, and I use Toad Data Point to create and test stored procedures.
I created this simple stored procedure:
CREATE OR REPLACE PROCEDURE dummy_sp (
p_recordset OUT SYS_REFCURSOR) AS
BEGIN
OPEN p_recordset FOR
select sysdate, user from dual;
END dummy_sp ;
/
I executed this, and the result from Toad is Executed Successfully.
Now, I would like to view the results of this stored procedure. In Toad Data Point I type the following:
variable mycursor refcursor;
call dummy_sp ( :mycursor );
I get a popup asking for a parameter. I click OK and I get the error ORA-00900: invalid SQL statement.
How can I see the result of SP dummy_sp in Toad Data Point?
In SQL Server I can run exec usp_sales and see the results of a select statement. There has to be something like that in Oracle and Toad, right?
Here you go, using Toad Data Point.
Execute the stored procedure with a bind variable in it, like :mycursor, and then make sure to configure the type as CURSOR and direction as OUT when Toad Data Point prompts you for the bind variable settings.
Here's the result:
Finally, if you wish to avoid the popup for bind variables, you can execute the procedure directly from the object explorer:
Right-click the procedure and choose Operations / Execute Procedure, and Toad will run it, without prompting for data type.
In case you need a workaround while you wait for help with your tool, the default, free IDE for Oracle Database makes this pretty easy.
If you execute the program using the code editor, it will automatically grab any outputs, whether those be OUT params or RETURNs from a function, including your refcursor
Or if your GUI has proper SQLPlus script execution support (SQL Developer does, not sure about your program):
var x refcursor
exec dummy_sp(:x);
print :x;
And the output:
PL/SQL procedure successfully completed.
SYSDATE USER
------------------- --------------------------------------------------------------------------------------------------------------------------------
27-JUN-19 13.58.47 HR
I am trying to code PL/SQL in SQL Developer but it is not displaying the output. My program is compiling successfully. Here is the code:
set serveroutput on
declare
begin
dbms_output.put_line('Hi');
end;
Please suggest what should I do to display the output? Is there any settings I need to change?
View->Dbms Output->Enable DBMS_OUTPUT for connection->OK
It may not be appearing because you are on an older version of Oracle Database. Make sure you're on 11gR2 or higher.
And then as an alterntative to the previous answer, you can simply
set serveroutput on
declare
begin
dbms_output.put_line('Hi');
end;
And then use the Execute as Script (F5) button on the worksheet toolbar.
Once serveroutput is set to 'on' we'll grab the DBMS_OUTPUT for you in the output panel anytime you run a Script.
I am using sqlplus and have a table named users from which I wish to retrieve all values with the help of a stored procedure in oracle. Here is what I am trying to do -
create or replace procedure getall(prc out sys_refcursor)
is
begin
open prc for select * from users
end;
/
When I hit return after this, I get the following error -
Warning: Procedure created with compilation errors.
Why does this happen? And how do I get the desired output? Help much appreciated!
To see the compilation errors use the show errors SQL*Plus command (which also works in SQL Developer), or query the user_errors view which works with any client. You can also query all_errors to see problems with objects that are not in your schema.
But you are just missing a semicolon after the select:
create or replace procedure getall(prc out sys_refcursor)
is
begin
open prc for select * from users;
end;
/
You'll need a bind variable to be able to see the output in SQL*Plus, e.g.:
variable rc refcursor;
exec getall(:rc);
print rc
Notice the colon before the rc in the procedure call, which shows it's a bind variable reference. And exec is a shorthand anonymous block.
You might find it simpler to have a function that returns a ref cursor, or a pipelined function; or just query the table directly of course.
I just started to learn PLSQL. I had only SQLDEVELOPER to access Oracle Database.
When I run following code:
DECLARE
title VARCHAR(8);
salary NUMBER;
BEGIN
title := 'DBA';
salary := 50000;
DBMS_OUTPUT.PUT_LINE('Job Title: '|| title);
DBMS_OUTPUT.PUT_LINE('Expected Salary'|| TO_CHAR(salary));
END;
/
I get the output "anonymous block completed".
Also, On running the command "set serveroutput on", I get a blank output.
I had other option is to download oracle database express edition and install on the local system.
In SQL Developer there is a menu option View -> Dbms output which you need to follow to set the serveroutput on for your database connection.
Once done, you will see the DBMS Output window pane, you then need to click the green plus "+" icon to enable serveroutput for your connection.
Other than that, you haven't asked a specific question....
put just above this line of code :
SET SERVEROUTPUT ON
As a follow-up to the question "Get resultset from oracle stored procedure", is there a way to show the results of a stored procedure that returns a REFCURSOR in a grid (instead of the plain text Script Output window) within SQL Developer?
EDIT: The answer helped, but I'm still having a problem displaying the result set in the "View Value" window:
The columns can only be expanded a small amount, probably due to the number of results being returned. Expanding the window with the resizer control doesn't help:
I don't think you can with a procedure.
Edit: Thanks to DCookie for simplifying my original answer.
But as a work-around you can write a function that calls the procedure and then invoke that using SQL.
e.g.
create or replace function callmyproc
return sys_refcursor
IS
rc sys_refcursor;
BEGIN
myproc(rc);
return rc;
END;
Which you can then call with:
select callmyproc()
from dual;
When this example is run, the SQL Developer data grid shows one result but if you scroll right and click on the edit button, you will see the results in a grid.