Subscribe to this feed

Navigation

Recent Posts

Archive

Oracle SQL*Plus Last Full Month

Saturday 24 Mar, 2007 - 18:15pm | 0 comments |

Although Crystal Reports has a built in LastFullMonth function SQL*Plus doesn't.

If you want to use SQL*Plus for your report and want the date parameter to be dynamic you can do so by manipulating sysdate and using some of the built in date functions.

Here is how

select * from db_table
where date_col between add_months((last_day(sysdate))+1,-2) AND add_months((last_day(sysdate))+1,-1)

Tags: Oracle |SQL*Plus |Dates |Crystal Reports

Add a comment
 | Link | Back to top | del.icio.us digg it furl reddit

SQL*Plus Spool File

Saturday 24 Mar, 2007 - 12:40pm | 1 comments |

If you want to produce a csv file from a SQL select query in SQL*Plus use the following syntax.

set echo off
set heading off
set feedback off
set pagesize 0
spool c:\filename.csv
select col1||','||col2 from db_table;
spool off

This will produce a csv formatted file. Straight to excel, change csv to xls but bear in mind two potential issues (a) row limit in Excel, and (b) leading zeros in number fields will be lost in excel.

The leading zeros can be resolved if you instead spool the file as a txt as you will be forced to use excels conversion wizard to open the file.

Tags: Oracle |SQL |SQL*Plus |csv

Add a comment
 | Link | Back to top | del.icio.us digg it furl reddit
Previous Next

© Eriginal Ltd 2011, all rights reserved