Wednesday, October 10, 2018

Removing multiple alpha characters using SQL

using sql translate function to translate characters

I needed to remove alphabetic characters (A - Z) from a field in a file, and left justify the remaining numeric characters. These alpha characters could be before and/or after any numbers contained within the string. As usual I need data in a test file, TESTFILE, that I can play with to find a way to do what I want.

In these examples, as the subject I have only bothered with two records/rows in my table/file. Why have more when I know what works in these examples will work in any scenario.

COLUMN
abc1234defghijklmnop
aaBbcCDd1mmg2k3LLkkH

The problem is that I want to replace any alpha character, no matter where in the string and what order they come in.

Friday, October 5, 2018

What's this thing called IBM i

A video from IBM Champion Trevor Perry explaining what IBM i is, and what is its future.

Video published April 20, 2017

Wednesday, October 3, 2018

Creating uniqueness using rowid

rowid column in sql table to ensure record uniqueness

The Db2 for i manual offers using a row id column, ROWID, as an alternative to an Identity column for ensuring table row uniqueness. While I wrote about using a ROWID SQL data type in RPG, I did not describe how the ROWID works when defined as a column in a table.

ROWID can only be used in SQL DDL tables, I cannot add it to a DDS file, using ALTER TABLE. It is defined in a similar manner to an Identity column where I say that the columns contents are generated by Db2 for i automatically.

For example, here is the DDL table I will be using:

01  CREATE TABLE MYLIB.TESTTABLE
02  (COLUMN1 CHAR(3) NOT NULL,
03   COLUMN2 CHAR(10),
04   COLUMN3 ROWID GENERATED ALWAYS IMPLICITLY HIDDEN
05  )