• 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
    ARCAD Software

    [Webinar] Creating test data, easily and quickly!

    June 22 at 12 p.m. EST

    Software testing needs realistic, consistent data available on demand, where and when needed. However, providing testers with a copy of the entire production database is costly both in time and disk space.

    In this webinar, we’ll demonstrate how to:

    • Easily create coherent test datasets, small enough for rapid test cycles, but large enough to accurately reflect the variety of production data
    • Anonymize the datasets to protect any PII
    • Inject into test environments in a snap

    Join us on this webinar with Alan Ashley, solution architect, and learn how to subset your data.

    Register now!

    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

  • IBM i Delivers Sizable Benefits, Forrester Consulting Reports
  • SBOMs Will Come to IBM i, Eventually
  • IBM i Backup Provider Storagepipe Snapped Up By Thrive
  • Four Hundred Monitor, June 7
  • IBM i PTF Guide, Volume 25, Number 23
  • Power10 Boosts NVM-Express Flash Performance
  • Fortra Completes Postmortem Of GoAnywhere Vulnerability
  • Guru: Binding Directory Entries
  • How Does Your Infrastructure Spending Stack Up To The World?
  • IBM i PTF Guide, Volume 25, Number 22

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 © 2023 IT Jungle