January 24


Hey AI — “What are the different types of IBM i SQL Variable?”

By NickLitten

January 24, 2024

SQL, AI, AI Generated Answers

AI is getting clever.

I’m honestly not too sure that AI is a good thing. We all watched the Terminator movies, right?

But that being said, I like to use the Microsoft’s COPILOT AI, because it makes collating answers to questions so very simple. It certainly makes researching answers to quick questions just about a hundred percent easier.

I even used it to generate the image header for this blog post.

I told it to generate a picture of Nick Litten fighting a giant rabbit robot!

What are the different types of ibm i sql variable?

Anyhoo, back to topic — I’ve been using a lot of IBM i SQL recently and regularly finding that my ten-year-old SQL knowledge is shockingly out of date. So, it’s time to double check everything I know and add new, cool code snippets to my mental Squirrel bucket.

So, let’s ask AI some basic questions and see what it tells us.

I’m going to record any salient AI answers as blogs just in case it helps anyone – because I know it helps me 🙂


What are the different types of IBM i SQL Variable?


In IBM i SQL, variables can be defined to store different types of data. Here are some of the variable types you can use:

  • CHAR(n): A fixed-length character string with a length of n.
  • NUMERIC(p, s): A numeric type with precision p and scale s.
  • DECIMAL(p, s): Similar to NUMERIC, a packed decimal number with precision p and scale s.
  • SMALLINT: A small integer that is typically a 2-byte binary number.
  • INTEGER: A 4-byte binary number, which is a standard integer.
  • BIGINT: An 8-byte binary number for larger integer values.
  • FLOAT: A floating-point number, which can be single precision (4 bytes) or double precision (8 bytes).

Additionally, there are date, time, and timestamp data types that are represented in an internal form not seen by an SQL user but can be represented by character string values [more]

For more detailed mappings between SQL data types and ILE RPG data types, you can refer to the official IBM documentation

{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}

Join the IBM i Community for FREE Presentations, Lessons, Hints and Tips