Subscribe to this feed

Navigation

Recent Posts

Archive

Popular Tags

Click tag to retrieve blogs
  1. Excel (9)
  2. Oracle (6)
  3. csv (5)
  4. batch files (5)
  5. bat (3)
  6. PHP (3)
  7. SQLPLus (3)
  8. VBA (3)
  9. Apache (3)
  10. DOS (3)
  11. SQL*Plus (3)
  12. Macro (3)
  13. data migration (2)
  14. System Implementation (2)
  15. MySQL (2)
  16. Microsoft (2)
  17. Windows (2)
  18. new systems (2)
  19. SQL (2)
  20. Regex (1)
  21. timestamp (1)
  22. Wireless (1)
  23. Google Maps (1)
  24. Windows Vista (1)
  25. Updates (1)

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

Comment
 | Link | Back to top | del.icio.us digg it furl reddit

Using datetime stamp in MySQL query

Tuesday 16 Jan, 2007 - 18:59pm | 0 comments |

I would have to describe this as a hack rather than anything else as the convert function wouldn't work for me and date() is not supported, i.e. you can't use "SELECT date(timestamp_field) from db"; to extract only the date element; whereas you can use year(timestamp_field) or month(timestamp_field).

I needed to filter records based on the date, to extract rows from the table where the date was equal to today. The date field in the table was a datetime column. My workaround was to use the left function and extract the ten characters of the date which I could then compare to today as in the following.


$query = "SELECT title, contents FROM articles WHERE left(timestamp_field,10) = '$date'";

This worked. I don't think it's the elegant solution, alternatives welcomed.

Tags:SQL |MySQL |timestamp |date function

Comment
 | Link | Back to top | del.icio.us digg it furl reddit

© Eriginal Ltd 2011, all rights reserved