• 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
    New Generation Software

    FREE Webinar:

    Creating Great Data for Enterprise AI

    Enterprise AI relies on many data sources and types, but every AI project needs a data quality, governance, and security plan.

    Wherever and however you want to analyze your data, adopting modern ETL and BI software like NGS-IQ is a great way to support your effort.

    Webinar: June 26, 2025

    RSVP today.

    www.ngsi.com – 800-824-1220

    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

  • Public Preview For Watson Code Assistant for i Available Soon
  • COMMON Youth Movement Continues at POWERUp 2025
  • IBM Preserves Memory Investments Across Power10 And Power11
  • Eradani Uses AI For New EDI And API Service
  • Picking Apart IBM’s $150 Billion In US Manufacturing And R&D
  • FAX/400 And CICS For i Are Dead. What Will IBM Kill Next?
  • Fresche Overhauls X-Analysis With Web UI, AI Smarts
  • Is It Time To Add The Rust Programming Language To IBM i?
  • Is IBM Going To Raise Prices On Power10 Expert Care?
  • IBM i PTF Guide, Volume 27, Number 20

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