Archive for May, 2008

Using the & (ampersand) character in Oracle SQL*Plus scripts

Friday, May 30th, 2008

It can be very frustrating when using Oracle SQL*PLus (sqlplus) to run a SQL script that contains an ampersand (&) character only to have the script stop mid-way through and ask you for a value :

Enter value for .... :

For example, this simple script :

-- This is a test script to show

-- what happens when an & (ampersand)

-- is in a SQL file

drop table t;

create table t (id number, name varchar2(32));

insert into t values (1, 'Bodget & Scarper');

commit;
When run via sqlplus generates this 'error' :
[steve@barney ~]$ sqlplus @test.sql

SQL*Plus: Release 10.2.0.1.0 - Production on Fri May 30 13:05:27 2008

Copyright (c) 1982, 2005, Oracle.  All rights reserved.

Connected to:

Oracle Database 10g Express Edition Release 10.2.0.1.0 - Production

Table dropped.

Table created.

Enter value for scarper:

And simply stops waiting for some input from us.  To disable this simply add ’set define off’ to the top of the script :

set define off

-- This is a test script to show

-- what happens when an & (ampersand)

-- is in a SQL file
.....

And voila!

[steve@barney ~]$ sqlplus @test.sql

SQL*Plus: Release 10.2.0.1.0 - Production on Fri May 30 13:06:46 2008

Copyright (c) 1982, 2005, Oracle.  All rights reserved.

Connected to:

Oracle Database 10g Express Edition Release 10.2.0.1.0 - Production

Table dropped.

Table created.

1 row created.

Commit complete.

Disconnected from Oracle Database 10g Express Edition Release 10.2.0.1.0 - Production

[steve@barney ~]$
The 'set define' option is actually used to tell SQL*Plus which character identifies a substitution variable which, by default, is the & character.  Using 'off' we're turning off substitutions but you could equally change the character something else if you needed to.

Using OGR2OGR to re-project a shape file

Friday, May 30th, 2008

OGR2OGR is a great command line tool for GIS format conversions providing support for all the ‘mainstream’ formats as well as plenty of more obscure ones.  It is also useful for changing the projection & coordinate system of a map layer.  The syntax for this is :

ogr2ogr -f "ESRI Shapefile" original.shp wgs84.shp -s_srs EPSG:27700 -t_srs EPSG:4326

where in this case we are re-projecting ‘original.shp’ from OSGB36 British National Grid to Longitude / Lattitude WGS84 and called ‘wgs84.shp’.

The re-projection can also be invoked as part of a format conversion also, like this :

ogr2ogr -f "MapInfo File" original.tab wgs84.shp -s_srs EPSG:27700 -t_srs EPSG:4326

where we convert the file from a MapInfo file to a Shapefile.

Our new blog

Thursday, May 29th, 2008

Hi all,

Welcome to the new Mercator GeoSystems Blog, ‘A Different Projection’. Here we’ll try to provide little snippets of useful information, scripts and general tips ‘n’ tricks that we discover on a day to day basis.

We’ll also try go through our notes and post little one-liners and other useful techniques that we’ve learnt over the years.  We’ll cover such subjects as GIS, mostly from an Open Source perspective featuring MapServer, PostGIS and uDig.  We’ll also cover the databases that we use on a daily basis which are Oracle and Postgres.  From a software development perspective we’ll try to write some interesting posts on Oracle Application Express (ApEx), PHP and some C,C++ & C# code.

Thanks for looking,

The Mercator GeoSystems Team.