0

In UNIX, in a SQL script, i have following code:

LOOP    
  DBMS_OUTPUT.put_line (p_key||'|'||p_loc||'\n');    
END LOOP

Output is:

5482004|Dir/3-30-2017/file:47923.xml

5482009|Dir/3-30-2017/file:49288.xml

However in Linux, since "\n" doesn't work, i am replacing the above code with following code:

LOOP    
  DBMS_OUTPUT.put_line (p_key||'|'||p_loc);    
  DBMS_OUTPUT.new_line;    
END LOOP

Output is:

20 5482004|Dir/3-30-2017/file:447923.xml 5482009|Dir/3-30-2017/file:449288.xml 5482010|Dir/3-30-2017/file:449739.xml 5482012|Dir/3-30-2017/file:45015.xml

The output in this format is without the new line after each line. Please suggest what is in correct in the loop.

P.S. I have also tried DBMS_OUTPUT.put_line (p_key||'|'||p_loc||chr(10)) but the output is still without the new line.

1

2 Answers 2

1

Please refer below SO answer for this question.

New Line Character in dbms_output

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

3 Comments

I did use DBMS_OUTPUT.put_line (p_key||'|'||p_loc||chr(10)); but the output is still 5482004|Dir/3-30-2017/file:447923.xml 5482009|Dir/3-30-2017/file:449288.xml 5482010|Dir/3-30-2017/file:449739.xml 5482012|Dir/3-30-2017/file:45015.xml format and not in new line one
LOOP DBMS_OUTPUT.put_line (p_key||'|'||p_loc); DBMS_OUTPUT.put_line(chr(10)); END LOOP
i tried the same, but didn't make any difference to the output format
1

You can use chr(10) My code in which i was trying to swap numbers ,where i need new line so i used chr(10)

DECLARE 
    A NUMBER;
    B NUMBER;
    TEMP NUMBER;
BEGIN
    A:=&A;
    B:=&B;
    DBMS_OUTPUT.PUT_LINE(chr(10)||'BEFORE SWAP A is : '||A||' AND B is : '||B);
    TEMP:=B;
    B:=A;
    A:=TEMP;
    DBMS_OUTPUT.PUT_LINE(' AFTER  SWAP A is : '||A||' AND B is : '||B);
END;
/
Output:

Enter value for a: 1
old   6:   A:=&A;
new   6:   A:=1;
Enter value for b: 2
old   7:   B:=&B;
new   7:   B:=2;
                                 -- here i got new line
BEFORE SWAP A is : 1 AND B is : 2
AFTER  SWAP A is : 2 AND B is : 1

PL/SQL procedure successfully completed.

So before line(i.e BEFORE SWAP A is : 1 AND B is : 2) in output i got new line.

Comments

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.