6

I'm trying to execute a script on SQL PLus, it's simple.

SET serveroutput ON;
DECLARE
    mode NUMBER(1) := 1;

IF (mode = 1) THEN

    prompt 'HERE'

END IF;

prompt 'fim'

I call the script from SQLPlus using sqlplus user/pw@db and @myscript.sql after a successful connection. But the output is strange for me:

Conectado a:
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options

SQL> @myscript.sql
 9
 10
 11

And it continues to print this sequence indefinitely. What am I doing wrong?

10
  • Definitely you get here printed and nothing else unless you have something else in your script. Commented Jan 7, 2014 at 12:42
  • What do you have in your script.sql? Commented Jan 7, 2014 at 12:42
  • 1
    It prints code's line number, and it probably prints it when you hit enter. The reason for such a behavior is probably your myscript.sql file contains not terminated by / PL/SQL block. Commented Jan 7, 2014 at 12:50
  • 1
    I don't think you're executing the script you think you are. (It does look like it contains a PL/SQL block without a termination). Is it in the same directory you launched SQL*Plus from? Do you have SQLPATH set in your environment? Commented Jan 7, 2014 at 12:50
  • 3
    till u give a '/', your script contents as PL/SQL block will be never sent to oracle, and it waits showing number starting from last line number of ur script as you keep pressing Enter! Commented Jan 7, 2014 at 12:58

3 Answers 3

16

From your edited question... you have to terminate the PL/SQL block with a / on a new line to make it end and run, otherwise SQL*Plus will keep prompting for more lines of code (which is the numbers you're seeing). The documentation shows how to run PL/SQL blocks. And prompt is a SQL*Plus command so you can't use it inside a PL/SQL block. You also don't have your block syntax right:

SET serveroutput ON;
DECLARE
    mode NUMBER(1) := 1;
BEGIN
    IF mode = 1 THEN
        DBMS_OUTPUT.PUT_LINE('HERE');    
    END IF;
END;
/

prompt fim
Sign up to request clarification or add additional context in comments.

1 Comment

@DiogoMoreira - please read the documentation to make sure you understand why it works now, and why your version didn't work. As well as the SQL*Plus guide, you should look the PL/SQL language reference.
3

You cannot use sqlplus command in plsql.We can use dbms_output instead which will display the output in SQL prompt

SET serveroutput ON;
DECLARE
mode NUMBER(1) := 1;
BEGIN
IF (mode = 1) THEN
dbms_output.put_line('HERE');
END IF;
dbms_output.put_line('fim');
END;
/

Comments

0

Go to your oracle home Oracle\product\<version>\client_2\sqlplus\admin\glogin.sql and add the following lines to enable printing globally,

SET ECHO ON;
SET TERM ON;
WHENEVER SQLERROR EXIT FAILURE ROLLBACK;
SET DEFINE OFF;

1 Comment

I don't think that solves the actual problem; your answer will show what is being executed, but the comments to the original post answer the question.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.