Top 5 Recent Articles
ARTICLES CATEGORIES
- Algorithms (22)
- All (399)
- Biography (1)
- Blog (44)
- Business Requirements (1)
- Commentary (1)
- Conversion (2)
- Customers (2)
- Data Models (1)
- Education (2)
- GeoRaptor (13)
- GPS (1)
- Image Processing (2)
- Import Export (8)
- Licensing (2)
- LiDAR (1)
- Linear Referencing (4)
- Manifold GIS (3)
- Mapping (1)
- MySQL Spatial (7)
- Networking and Routing (including Optimization) (5)
- Open Source (18)
- Oracle Spatial and Locator (194)
- Partitioning (1)
- PostGIS (36)
- Projections (1)
- Published Articles (1)
- qGIS (1)
- Recommendations (1)
- Services (1)
- Software Change Log (1)
- Source Code (37)
- Space Curves (9)
- Spatial Database Functions (109)
- Spatial DB comparison (1)
- Spatial XML Processing (11)
- SQL Server Spatial (92)
- Standards (3)
- Stored Procedure (17)
- Tessellation or Gridding (10)
- Tools (2)
- Topological Relationships (1)
- Training (2)
- Triangulation (2)
Writing Excel Spreadsheets files from within the Oracle database using Java and PL/SQL
My EXPORTER package + Java code has functions called WriteExcelSpreadsheet that can be used to create and export any SQL SELECT statement to disk as an Excel Spreadsheet using Oracle database’s DBMS_JOB or DBMS_SCHEDULER.
Because Excel Spreadsheets have limited number of rows (65535) and columns (255) per sheet (the maximum size of data in a cell is 32767 characters), control of what I call the overflow of a result-set’s contents across Sheets can be controlled by the _stratification parameters:
If number of rows in result-set is greater than 65535 and _stratification is N (NONE) or V (VERTICAL) then the result-set processing will only output 65535 rows in the first sheet. No more sheets will be created and no more data output.
If _stratification is H (HORIZONTAL) a new sheet is created for the next 65535 rows etc.
If the result-set contains greater than 255 columns and _stratification is set to V (VERTICAL) then the first 255 columns will be in the first sheet, the next 255 in the second sheet etc up to the maximum number of rows that can be output in a SELECT statement.
If greater than 255 columns exist and _stratification is H or N then only the first 255 columns will be output in the first sheet: if greater than 65535 rows also exists then overflow is controlled by _stratification = H or N.
You will note that when exporting a SQL SELECT statement with an SDO_GEOMETRY object that you can specify the export text format for all the SDO_GEOMETRY objects in the result set. This format can be Well Known Text (WKT) or Geography Markup Language (GML) version 2 (version 3 can only be made available for Oracle databases supporting JVM 1.5 or above).
Finally, a number of default date and time formats are made available for the formatting of date, datetime (concatenation of parameters p_dateFormat and p_timeFormat) and time:
/* 2. Date/Time formats */ c_DATEFORMAT CONSTANT varchar2(20) := 'yyyyMMdd'; c_DATEFORMAT1 CONSTANT varchar2(20) := 'M/d/yy'; c_DATEFORMAT2 CONSTANT varchar2(20) := 'd-MMM-yy'; c_DATEFORMAT3 CONSTANT varchar2(20) := 'd-MMM'; c_DATEFORMAT4 CONSTANT varchar2(20) := 'MMM-yy'; c_TIMEFORMAT CONSTANT varchar2(20) := 'h:mm a'; c_TIMEFORMAT1 CONSTANT varchar2(20) := 'h:mm:ss a'; c_TIMEFORMAT2 CONSTANT varchar2(20) := 'H:mm'; c_TIMEFORMAT3 CONSTANT varchar2(20) := 'H:mm:ss'; c_TIMEFORMAT4 CONSTANT varchar2(20) := 'mm:ss'; c_TIMEFORMAT5 CONSTANT varchar2(20) := 'H:mm:ss'; c_TIMEFORMAT6 CONSTANT varchar2(20) := 'H:mm:ss';
You are not limited to these default values. Here is an example of an export.
Prompt Exporting Excel Spreadsheet BEGIN codesys.exporter.writeExcelSpreadsheet( p_sql => 'SELECT ID,LONGITUDE,LATITUDE,SPECIES,STATION_NUMBER as STATION,LENGTH,WEIGHT,SEX,MATURITY,WATER_CHECK as H2O,OBSERVATION_DATE as obsn_date,GEOM FROM GUTDATA', p_outputDirectory => 'C:\temp\', p_fileName => 'gutdata', p_sheetName => 'GutData', p_stratification => 'N', p_geomFormat => codesys.EXPORTER.c_WKT_FORMAT, p_DateFormat => codesys.EXPORTER.c_DATEFORMAT, p_TimeFormat => codesys.EXPORTER.c_TIMEFORMAT, p_precision => 7); End; /
With the export file looking like….
I hope this helps someone.
Documentation
- MySQL Spatial General Functions
- Oracle LRS Objects
- Oracle Spatial Exporter (Java + pl/SQL)
- Oracle Spatial Object Functions
- Oracle Spatial Object Functions (Multi Page)
- PostGIS pl/pgSQL Functions
- SC4O Oracle Java Topology Suite (Java + pl/SQL)
- SQL Server Spatial General TSQL Functions
- SQL Server Spatial LRS TSQL Functions