2

I have (test.batch) a batch file that calls (gett.sql) sql file and executes it.

The problem is how to display the output of sql file on the screen to user.

test.batch file:

@echo off
set mypath=%cd%
@ECHO Counter...
set user_name=hr
set password=hr
set net_service_name=ORCL
echo exit | sqlplus -s %user_name%/%password%@%net_service_name% @%mypath%\gett.sql
pause

gett.sql file:

SET ECHO ON
DECLARE
BEGIN
  FOR i IN 1..5 LOOP
      DBMS_OUTPUT.PUT_LINE('Message# '||i);
  END LOOP;
END;

PAUSE

1 Answer 1

4

You did everything right (OK, almost everything):

M:\a1_maknuto>@test
Counter...

Message# 1
Message# 2
Message# 3
Message# 4
Message# 5

PL/SQL procedure successfully completed.

Press any key to continue . . .

M:\a1_maknuto>

What you miss, is a slash that terminates PL/SQL block in gett.sql script; also, don't forget to enable output by SET SERVEROUTPUT ON:

SET ECHO ON
SET SERVEROUTPUT ON       --> this
DECLARE
BEGIN
  FOR i IN 1..5 LOOP
      DBMS_OUTPUT.PUT_LINE('Message# '||i);
  END LOOP;
END;
/                         --> this
PAUSE
Sign up to request clarification or add additional context in comments.

2 Comments

thanks, it works great , however i got 'Input truncated to n characters' and found I must insert new line at the end of sql file
You're welcome. If you had to fix truncated input and managed to do that - good for you! I'm glad you made it.

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.