Friday, January 5, 2018

Oracle - Create Table from Another Table and Add a New Column

Let's say we want to add a new column to an existing database table T.

Get the DDL for the table and its constraints (e.g. use SQL Developer or DBMS_METADATA.GET_DDL).

Duplicate the old table. This table will be temporary for transferring existing data to the new table.

CREATE TABLE T_TMP AS (SELECT * FROM T);

Drop the old table.

DROP TABLE T CASCADE CONSTRAINTS;

Duplicate the temporary table and add the column.

CREATE TABLE T AS
  SELECT COL_1, COL_2, COL_3, CAST(NULL AS NUMBER(15)) AS COL_NEW
  FROM RUN_T_TMP;

Recreate all constraints, primary keys and indexes.

Drop the temporary table.

DROP TABLE T_TMP CASCADE CONSTRAINTS;


That's it.

Thursday, January 4, 2018

Ant Build Problem in Eclipse Oxygen - JRE less than 1.8 is not supported

When executing ant build within Eclipse using JRE 1.6, the following error occurs:



One would ask, "Why use old JRE when there are newer and better versions?"

The answer to this question is, in some environments, there are existing legacy system that cannot be upgraded due to various reasons including financial constraints.
The Eclipse Oxygen comes with Ant version 1.10.1 plugin. Apache Ant 1.10.x requires Java Runtime 1.8, whereas Ant 1.9.x stays compatible with Java 1.5 to 1.7.

Since Ant 1.10.x requires JRE8 and above, if you run an ant build file using the default Ant Home that points to the ant plugin, the ant launcher checks for the JRE version and prevent ant from launching with older JRE. However, if you configure to run your ant build with an external Ant runtime (configure Ant Home in the classpath to point to the external Ant 1.9.x runtime), it does not block ant runtime from launching.

Below is the source code of the ant launching method in org\eclipse\ant\internal\launching\launchConfigurations\AntLauchDelegate.java 


First download Apache Ant 1.9.9 and extract it. Then, configure external ant runtime in the ant build launcher and change the Ant Home in the Classpath tab.








That's it. Now the ant build file can be executed in Eclipse with JRE6.