PL/SQL command not properly working though successfully completed [duplicate] - oracle

This question already has answers here:
Printing the value of a variable in SQL Developer
(9 answers)
Closed 10 months ago.
I have written a simple PL/SQL command of printing hello world to console but it prints nothing and still message is prompted that PL/SQL procedure successfully completed. I am not able to figure it out as to what to do in this case?
Code:
BEGIN
dbms_output.put_line ('Hello World..');
END;
OUTPUT:

You're missing the set serveroutput on.
This is what you have:
SQL> begin
2 dbms_output.put_line('Hello world');
3 end;
4 /
PL/SQL procedure successfully completed.
This is what you should have:
SQL> set serveroutput on --> this
SQL> begin
2 dbms_output.put_line('Hello world');
3 end;
4 /
Hello world --> here's the result
PL/SQL procedure successfully completed.
SQL>

Related

Oracle - How to use & without being asked about the value? [duplicate]

This question already has answers here:
How to declare variable and use it in the same Oracle SQL script?
(11 answers)
Closed 11 months ago.
Basically, I don't want to be asked about the value like this::
SQL> select &test from dual;
Enter value for test:
I want only declare the &test along the script, something like it:
&test varchar2(100):= 'some value'; --of course, this don't work.
Execute
SQL> set define off
before running your code.
SQL> select '&test' from dual;
'&TES
-----
&test
SQL>
If you want to "declare" it, then use var:
SQL> var test varchar2(200);
SQL> exec :test := 'some value';
PL/SQL procedure successfully completed.
SQL> print test
TEST
----------------------------------------------------------------------------------------------------
some value
SQL>
In dynamic SQL: I won't lock anyone, but - I'll change my password.
SQL> connect scott/tiger
Connected.
SQL> var test varchar2(200);
SQL> exec :test := 'lion';
PL/SQL procedure successfully completed.
SQL> print test
TEST
----------------------------------------------------------------------------------------------------
lion
SQL> begin
2 execute immediate 'alter user scott identified by ' || :test;
3 end;
4 /
PL/SQL procedure successfully completed.
SQL> connect scott/tiger
ERROR:
ORA-01017: invalid username/password; logon denied
Warning: You are no longer connected to ORACLE.
SQL> connect scott/lion
Connected.
SQL>

sqlcl vs sqlplus pl/sql compatability

I apologize up-front for this super-lightweight question, but I'm missing something when starting to work with sqlcl as a potential replacement for sqlplus.
sqlcl is compelling, but I'm troubled in that I'm missing how to run anonymous-blocks interactively. The below example works fine when saved as Little-Anonymous-Block.sql and run in sqlcl via #Little-Anonymous-Block.sql, but the raw pl/sql fails with the the below PLS-00103.
Little-Anonymous-Block.sql:
BEGIN
DBMS_OUTPUT.PUT_LINE('This anonymous-block ran in sqlcl!');
END;
/
Running as a Script:
SQL> SET SERVEROUTPUT ON;
SQL> #Little-Anonymous-Block.sql;
This anonymous-block ran in sqlcl!
PL/SQL procedure successfully completed.
But running ad-hoc:
SQL> BEGIN
2 DBMS_OUTPUT.PUT_LINE('This anonymous-block ran in sqlcl!');
3 END;
4 /
gives:
Error starting at line : 1 in command -
BEGIN
DBMS_OUTPUT.PUT_LINE('This anonymous-block ran in sqlcl!');
END;/
PLS-00103: Encountered the symbol "/" The symbol "/" was ignored.
sqlcl appears to be conjoining the "/" with the block-terminating END;
The same command works fine in sqlplus.
Can you tell me, how do I interactively run anonymous blocks in sqlcl? I've got the early-adopter release from 20160513. java 8.0_77. Apologies for this question if its in the sqlcl manual, I didn't find much to go by on the oracle sqlcl-page.
I've found that you can run an anonymous block with exec but that has its limitations (e.g. all code on one line).
As far as I can tell what you've found is a bug. A workaround would be to end your block with a . then execute the buffer with a / as shown below:
This was indeed a bug. It should be fixed in the latest release on OTN
BARRY#orcl☘ >BEGIN
2 DBMS_OUTPUT.PUT_LINE('This anonymous-block ran in sqlcl!');
3 END;
4 /
PL/SQL procedure successfully completed.
BARRY#orcl☘ >l
1 BEGIN
2 DBMS_OUTPUT.PUT_LINE('This anonymous-block ran in sqlcl!');
3* END;
BARRY#orcl☘ >

How to make to see the output result to execute PL/SQL from SQL Plus?

When i run PL/SQL statment from SQL Plus,I don't see my output result.However,it was successful completed but it don't show output result.
My code is here
DECLARE
message varchar2(20):= 'Hello World';
BEGIN
dbms_output.put_line(message);
END;
/
RESULT: PL/SQL is successfully completed.
It didn't show Hello World output.
You need use the command set serveroutput on to configure buffering for dbms_output like below. Check this Oracle Community Post
set serveroutput on size 15000;

How to call a stored procedure in oracle from shell

I have installed cygwin and i have Oracle 10 g now i want to connect database from shell.can anyone help me??
SQL> create or replace procedure get_area
2 (n_length in number,
3 n_width in number,
4 n_area out number)
5 as
6 begin
7 n_area := n_length*n_width;
8 end get_area;
9 /
This is my procedure i have created in oracle 10g.I want to call the get_area from shell
i am doing this to start that process
subho#subho-PC ~$ #!/bin/csh-f
you can just do it like this
sqlplus login/pass #get_area.sql
where get_area.sql contains your SQL code
the last detail is to put an exit; at the end of the script oftherwise you will stay on the SQL > prompt

PL SQL output is not getting displayed

I have fairly simply code ..running in Oracle Virtualbox. However for some reason it is not displaying pl/sql output.
Here is code snippet
SQL> set serveroutput on
SQL> list
1 Create or Replace procedure mytz
2 IS
3 v_mytz TIMESTAMP WITH TIME ZONE DEFAULT '2013-05-05 12:00:00 AM';
4 BEGIN
5 DBMS_OUTPUT.PUT_LINE ('Default timestamp is ' );
6* end mytz ;
SQL> /
Procedure created.
SQL>
Is there anything I need to do special to see the output on SQL prompt ?
You have to actually run the procedure, not just create it, e.g.:
set serverputput on
exec mytz;
The set serveroutput SQL*Plus command has to be in the session the procedure is executed, not the one where it is created (if they are different).
You are not showing the value of your variable at the moment; maybe you wanted this?
dbms_output.put_line('Default timestamp is: ' || v_mytz);

Resources