Sponsored Content
Top Forums Shell Programming and Scripting DBMS_OUTPUT.PUT_LINE doesn't print values in shell script Post 303038942 by mail.chiranjit on Wednesday 18th of September 2019 02:04:05 AM
Old 09-18-2019
DBMS_OUTPUT.PUT_LINE doesn't print values in shell script

Hello,
I'm trying to print the value of my cursor in the dbms_output.put_line in shell script, but it only shows "PL/SQL procedure successfully completed." nothing else. I have set serveroutput on,
Below is my script : Any advise would be really helpful.
Code:
sqlplus -s $ORACLE_LOGON <<EOF >> $alert_file
set serveroutput on size 30000;
set lines 1000
set pagesize 50000
set trimspool on
set heading off
set echo off
set newpage none
set heading OFF;
DECLARE
CURSOR C1
IS
SELECT DISTINCT A.KNOWLEDGE_SESSION_UID AS KSUID
FROM KNOWLEDGE_SESSION A ,
  PROV_KNOWLEDGE_SESSION_USE B ,
  WORK_ORDER_STEPS C
WHERE A.SERIALISED_STATE LIKE '%<STRING>US</STRING>%'
AND A.SERIALISED_STATE NOT LIKE '%<STRING>FA</STRING>%'
AND A.SERIALISED_STATE NOT LIKE '%<STRING>CG</STRING>%'
AND ROUND((SYSDATE -A.LAST_UPDATED_DT )*24*60) > 5
AND A.KNOWLEDGE_SESSION_UID=B.KNOWLEDGE_SESSION_UID
AND B.WO_NO IS NOT NULL
AND A.REVIVE_AFTER_DT IS NULL
AND A.LAST_UPDATED_DT >= SYSDATE -5
AND C.WO_NO=B.WO_NO
AND C.STATUS_CD='LP'
AND C.STEP_DEF_CODE='PRO'
fetch first 20 rows only ;
KS_UID KNOWLEDGE_SESSION.KNOWLEDGE_SESSION_UID%TYPE;
BEGIN
OPEN C1;
FETCH C1 into KS_UID;
DBMS_OUTPUT.PUT_LINE(KS_UID);
END;
/

Regards,
Chiranjit

--- Post updated at 12:34 PM ---

I have now able to print the values, however it is only printing the first value where i am selecting first 20 rows in the cursor.
Is there a way to print all the values ?

Thanks,
Chiranjit

Last edited by mail.chiranjit; 09-18-2019 at 02:39 AM..
 

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script doesn't get executed using crontab

I have the following crontab entry to run a shell script for every 30 minutes of every day: 30 * * * * $HOME/main.sh > $HOME/main.log 2>$HOME/error.log after I created the crontab file I have also done: $crontab my_crontab I also check to make sure it exists, by using the following... (11 Replies)
Discussion started by: radhika
11 Replies

2. Shell Programming and Scripting

sqlplus and dbms_output.put_line in shell script

Hi, I have created a pl/sql block utilises dbms_output.put_line. This script works fine when I call from sqlplus ie sqlplus @./scriptname but when I embed it within my shell script I get no output to screen so I end up with an empty spool file. I know it's executing successfully when called from... (6 Replies)
Discussion started by: stuck1
6 Replies

3. Shell Programming and Scripting

shell script, echo doesn't work

#!/bin/sh something(){ echo "Inside something" echo $1 $2 } val=$(something "Hello " "world") Output expected: Inside somethingHello world But it's not echoing. (4 Replies)
Discussion started by: cola
4 Replies

4. Programming

How to Format database output (DBMS_OUTPUT.PUT_LINE) in unix?

Dear All, As I'm new here, please forgive me if any rule violation occurred. I have a script like this: #! /bin/ksh # Author : Saptarshi # Date : 18-Mar-2011 # Version : 1.0 Return_op=`sqlplus -s <<ENDOFSQL db_user/db_pass@db_nm WHENEVER SQLERROR EXIT 1 set ... (1 Reply)
Discussion started by: saps19
1 Replies

5. Shell Programming and Scripting

[Solved] How to display only output of DBMS_OUTPUT.PUT_LINE , rest should be neglected

Hi All, I Have written a script through that i am calling sql file Sqlfile.sql set time on set timing on set echo on set head off set scan on set feedback on set serveroutput on set linesize 1000 DECLARE v_acc_no NUMBER(10); v_product_no NUMBER(10); BEGIN... (3 Replies)
Discussion started by: sujit_kashyap
3 Replies

6. Shell Programming and Scripting

Query the table and return values to shell script and search result values from another files.

Hi, I need a shell script, which would search the result values from another files. 1)execute " select column1 from table_name" query on the table. 2)Based on the result, need to be grep from .wft files. could please explain about this.Below is the way i am using. #!/bin/sh... (4 Replies)
Discussion started by: Rami Reddy
4 Replies

7. Shell Programming and Scripting

Script doesn't print error.

Hi Gurus, I have below sample script. I expect it print error when running script without input parameter. but the it doesn't. would you please help me about this issue. thanks in advance. /script$cat test.ksh #!/bin/ksh while getopts :f: arg do case $arg in ... (4 Replies)
Discussion started by: ken6503
4 Replies

8. UNIX for Dummies Questions & Answers

Reading XML file and print the values in the text file using Linux shell script

hi guys, i want help... Reding XML file and print the values into the text file using linux shell script file as per below xml file <sequence> <Filename>aldorzum.doc</Filename> <DivisionCode>US</DivisionCode> <ContentType>Template</ContentType> <ProductCode>VIMZIM</ProductCode> </sequence>... (1 Reply)
Discussion started by: sravanreddy
1 Replies

9. Shell Programming and Scripting

The shell script doesn't get arguments, but parse them

Hello, I have a simple shell script, which starts from crontab like this: 00 03 * * 2-6 /export/applications/dte/sh/fwmarg.sh > /export/applications/dte/data/cron_log/fwmarg.cronlog.`date +\%m.\%d` 2>&1 The script doesn't get any argument. But inside it I see the line ... (10 Replies)
Discussion started by: digioleg54
10 Replies
DECLARE(7)							   SQL Commands 							DECLARE(7)

NAME
DECLARE - define a cursor SYNOPSIS
DECLARE cursorname [ BINARY ] [ INSENSITIVE ] [ SCROLL ] CURSOR FOR query [ FOR { READ ONLY | UPDATE [ OF column [, ...] ] ] INPUTS cursorname The name of the cursor to be used in subsequent FETCH operations. BINARY Causes the cursor to fetch data in binary rather than in text format. INSENSITIVE SQL92 keyword indicating that data retrieved from the cursor should be unaffected by updates from other processes or cursors. Since cursor operations occur within transactions in PostgreSQL this is always the case. This keyword has no effect. SCROLL SQL92 keyword indicating that data may be retrieved in multiple rows per FETCH operation. Since this is allowed at all times by PostgreSQL this keyword has no effect. query An SQL query which will provide the rows to be governed by the cursor. Refer to the SELECT statement for further information about valid arguments. READ ONLY SQL92 keyword indicating that the cursor will be used in a read only mode. Since this is the only cursor access mode available in PostgreSQL this keyword has no effect. UPDATE SQL92 keyword indicating that the cursor will be used to update tables. Since cursor updates are not currently supported in Post- greSQL this keyword provokes an informational error message. column Column(s) to be updated. Since cursor updates are not currently supported in PostgreSQL the UPDATE clause provokes an informational error message. OUTPUTS DECLARE CURSOR The message returned if the SELECT is run successfully. WARNING: Closing pre-existing portal "cursorname" This message is reported if the same cursor name was already declared in the current transaction block. The previous definition is discarded. ERROR: DECLARE CURSOR may only be used in begin/end transaction blocks This error occurs if the cursor is not declared within a transaction block. DESCRIPTION
DECLARE allows a user to create cursors, which can be used to retrieve a small number of rows at a time out of a larger query. Cursors can return data either in text or in binary format using FETCH [fetch(7)]. Normal cursors return data in text format, either ASCII or another encoding scheme depending on how the PostgreSQL backend was built. Since data is stored natively in binary format, the system must do a conversion to produce the text format. In addition, text formats are often larger in size than the corresponding binary format. Once the information comes back in text form, the client application may need to con- vert it to a binary format to manipulate it. BINARY cursors give you back the data in the native binary representation. As an example, if a query returns a value of one from an integer column, you would get a string of 1 with a default cursor whereas with a binary cursor you would get a 4-byte value equal to control-A (^A). BINARY cursors should be used carefully. User applications such as psql are not aware of binary cursors and expect data to come back in a text format. String representation is architecture-neutral whereas binary representation can differ between different machine architectures. PostgreSQL does not resolve byte ordering or representation issues for binary cursors. Therefore, if your client machine and server machine use dif- ferent representations (e.g., ``big-endian'' versus ``little-endian''), you will probably not want your data returned in binary format. However, binary cursors may be a little more efficient since there is less conversion overhead in the server to client data transfer. Tip: If you intend to display the data in ASCII, getting it back in ASCII will save you some effort on the client side. NOTES Cursors are only available in transactions. Use to BEGIN [begin(7)], COMMIT [commit(7)] and ROLLBACK [rollback(7)] to define a transaction block. In SQL92 cursors are only available in embedded SQL (ESQL) applications. The PostgreSQL backend does not implement an explicit OPEN cursor statement; a cursor is considered to be open when it is declared. However, ecpg, the embedded SQL preprocessor for PostgreSQL, supports the SQL92 cursor conventions, including those involving DECLARE and OPEN statements. USAGE
To declare a cursor: DECLARE liahona CURSOR FOR SELECT * FROM films; COMPATIBILITY
SQL92 SQL92 allows cursors only in embedded SQL and in modules. PostgreSQL permits cursors to be used interactively. SQL92 allows embedded or modular cursors to update database information. All PostgreSQL cursors are read only. The BINARY keyword is a PostgreSQL extension. SQL - Language Statements 2002-11-22 DECLARE(7)
All times are GMT -4. The time now is 03:27 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy