• The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
Menu
  • The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
  • Repeated Characters in SQL

    February 2, 2005 Hey, Ted

    Using SQL, how do I fill a 128-byte character field with asterisks? Please don’t tell me I have to key every one of those puppies into my SQL command.

    –Jack

    I’ve got good news. Use the SPACE function to generate 128 spaces. Use the TRANSLATE function to convert the spaces into asterisks.

    insert into somefile (somefield)
            values (translate(space(128),'*',' '))
    

    Or use the REPLACE function to convert the spaces into asterisks.

    insert into somefile (somefield)
            values (replace(space(128),' ','*'))
    

    I haven’t run any speed tests, but TRANSLATE seems to run faster than REPLACE.

    If you had wanted to fill your field with a literal longer than one character, you would have had to use REPLACE. The following SQL command repeats the word VOID, followed by one blank, throughout the field.

    insert into somefile (somefield)
            values (replace(space(128),'     ','VOID '))
    


    Notice there are five blanks between the first two apostrophes and one blank after VOID.

    –Ted

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    Tags:

    Sponsored by
    Rocket Software

    Two Steps Forward, No Steps Back

    For over 35 years, Rocket Software’s solutions have empowered businesses to modernize their infrastructure, unlock data value, and drive transformation – all while ensuring modernization without disruption.

    LEARN MORE

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    Stampede Regains Edge for Compression of Notes/Domino R6 JDE Shops Have Plenty of Options for Third-Party Maintenance

    Leave a Reply Cancel reply

Volume 5, Number 5 -- February 2, 2005
THIS ISSUE
SPONSORED BY:

WorksRight Software
Advanced Systems Concepts
COMMON

Table of Contents

  • Repeated Characters in SQL
  • Yet Another Way to Build CSV Files
  • Admin Alert: Things to Check After Upgrading OS/400 V5R1 to V5R3

Content archive

  • The Four Hundred
  • Four Hundred Stuff
  • Four Hundred Guru

Recent Posts

  • Liam Allan Shares What’s Coming Next With Code For IBM i
  • From Stable To Scalable: Visual LANSA 16 Powers IBM i Growth – Launching July 8
  • VS Code Will Be The Heart Of The Modern IBM i Platform
  • The AS/400: A 37-Year-Old Dog That Loves To Learn New Tricks
  • IBM i PTF Guide, Volume 27, Number 25
  • Meet The Next Gen Of IBMers Helping To Build IBM i
  • Looks Like IBM Is Building A Linux-Like PASE For IBM i After All
  • Will Independent IBM i Clouds Survive PowerVS?
  • Now, IBM Is Jacking Up Hardware Maintenance Prices
  • IBM i PTF Guide, Volume 27, Number 24

Subscribe

To get news from IT Jungle sent to your inbox every week, subscribe to our newsletter.

Pages

  • About Us
  • Contact
  • Contributors
  • Four Hundred Monitor
  • IBM i PTF Guide
  • Media Kit
  • Subscribe

Search

Copyright © 2025 IT Jungle