Logo DWBI.org Login / Sign Up
Sign Up
Have Login?
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.
Login
New Account?
Recovery
Go to Login
By continuing you indicate that you agree to Terms of Service and Privacy Policy of the site.
Oracle

Oracle Spool

 
Updated on Sep 29, 2020

Oracle Spool for SQLplus command line utility, can be used in conjunction with OS to export data from Oracle to flat file.

--INTERFACE.txt

set echo off
set feedback off
set termout off
set heading off
set headsep off
set underline off
set linesize 2000
set pagesize 10000
set trimspool on
set embedded on
set colsep '	'

connect scott/tiger@orcl

column cdcdate noprint
SELECT TO_CHAR( SYSDATE, 'YYYYMMDD' ) cdcdate FROM dual;
column empno format 9999999999 heading "EMP_NUM"
column deptno format 9999999999 heading "DEPT_NUM"
column ename format A60 heading "EMP_NAME"
column dname format A20 heading "DEPT_NAME"
column hiredate format 'YYYYMMDD' heading "HIRE_DATE"
column sal format 999999999.99 heading "SALARY"

spool C:\Output_Files\Employee_&cdcdate..txt

SELECT

emp.empno EMP_NUM,
emp.deptno DEPT_NUM,
emp.ename EMP_NAME,
dept.dname DEPT_NAME,
TO_CHAR( emp.hiredate, 'YYYYMMDD' ) HIRE_DATE,
emp,salary SALARY
FROM
emp, dept
WHERE emp.deptno = dept.deptno
AND TO_CHAR( emp.hiredate, 'YYYYMMDD' ) = TO_CHAR( SYSDATE - 1, 'YYYYMMDD' )
/

spool off

set feedback on

set heading on

exit
@REM Windows Batch Script to Upload Data file to FTP location
@echo off
@REM Connect to SQLPlus, execute SQL & generate Spool file

sqlplus /nolog @C:\Scripts\INTERFACE.txt

@REM Generate Script file for WinSCP for automation
@echo off

SET File=Employee
SET Dir=C:\Output_Files\
SET mydate=%date:~10,4%%date:~4,2%%date:~7,2%

@REM SET mydate=%date:~10,4%%date:~7,2%%date:~4,2%
@REM echo %mydate%

SET Filename=%File%_%mydate%.txt
SET FilenameNew=%File%_%mydate%_New.txt

@REM echo %Filename%
@REM Remove Blank Lines from Data File

cd "C:\Output_Files\"

For /F "tokens=* delims=" %%A in (%Filename%) Do Echo %%A >> %FilenameNew%

move %FilenameNew% %Filename%

echo # Automatically abort script on errors > C:\Scripts\file_upload_sftp.txt
echo option batch abort  >> C:\Scripts\file_upload_sftp.txt

echo # Disable overwrite confirmations that conflict with the previous  >> C:\Scripts\file_upload_sftp.txt
echo option confirm off >> C:\Scripts\file_upload_sftp.txt

echo # Connect using a password >> C:\Scripts\file_upload_sftp.txt
echo open ftp://ftpuser@ftpsite.xyz.com >> C:\Scripts\file_upload_sftp.txt

echo # Change the remote directory >> C:\Scripts\file_upload_sftp.txt
echo lcd %Dir% >> C:\Scripts\file_upload_sftp.txt

echo put %Filename% >> C:\Scripts\file_upload_sftp.txt

echo # Disconnect >> C:\Scripts\file_upload_sftp.txt
echo close >> C:\Scripts\file_upload_sftp.txt

echo # Exit WinSCP >> C:\Scripts\file_upload_sftp.txt
echo exit >> C:\Scripts\file_upload_sftp.txt

@REM Run WinSCP to upload file
"C:\Program Files\WinSCP\winscp.com" /ini="C:\Scripts\WinSCP.ini" /script="C:\Scripts\file_upload_sftp.txt" /log="C:\Scripts\ftp.log"

exit
PrimeChess

PrimeChess.org

PrimeChess.org makes elite chess training accessible and affordable for everyone. For the past 6 years, we have offered free chess camps for kids in Singapore and India, and during that time, we also observed many average-rated coaches charging far too much for their services.

To change that, we assembled a team of top-rated coaches including International Masters (IM) or coaches with multiple IM or GM norms, to provide online classes starting from $50 per month (8 classes each month + 4 tournaments)

This affordability is only possible if we get more students. This is why it will be very helpful if you could please pass-on this message to others.

Exclucively For Indian Residents: 
Basic - ₹1500
Intermediate- ₹2000
Advanced - ₹2500

Top 10 Articles