INITCAP TRANSLATE Text Cleanup

Normalize messy contact strings with INITCAP for word-initial capitalization and TRANSLATE for per-character masking or deletion via an empty replacement set.

SqlData Integrity

Code

snippet
CREATE TABLE contacts (
    id   int PRIMARY KEY,
    raw  text NOT NULL
);

INSERT INTO contacts VALUES
    (1, 'ADA LOVELACE'),
    (2, 'grace hopper'),
    (3, 'hotline 555-01-1234');

-- text cleanup:INITCAP 每个词首字母大写、其余转小写;
-- TRANSLATE 把 from 集合里的字符逐个映射,映射到空串即删除
SELECT
    id,
    INITCAP(raw) AS display,
    TRANSLATE(raw, '0123456789', '**********') AS masked,
    TRANSLATE(raw, '0123456789-', '')          AS digits_only
FROM contacts
ORDER BY id;

How the snippet works

SELECT / INSERT / CREATE statements share the script, touching contacts.

Mechanically, the statements are built from: an ORDER BY that fixes the output order; NOT NULL qualifiers on the required columns; a PRIMARY KEY that enforces row identity.

Using it

The contacts table is the working surface here.

Key statements

SELECT
    id,
    INITCAP(raw) AS display,
    TRANSLATE(raw, '0123456789', '**********') AS masked,
    TRANSLATE(raw, '0123456789-', '')          AS digits_only
FROM contacts
ORDER BY id;
INSERT INTO contacts VALUES
    (1, 'ADA LOVELACE'),
    (2, 'grace hopper'),
    (3, 'hotline 555-01-1234');
CREATE TABLE contacts (
    id   int PRIMARY KEY,
    raw  text NOT NULL
);

Interactive Tools for This Topic

FAQ

Which objects does the SQL touch?
`contacts` — referenced directly, no join needed.