简体   繁体   中英

How to do MySQL + Substring? + replace?

  • I am not very good with SQL and would like to be able to become better.

  • I am having some trouble trying to preform a certain table manipulation.

  • I would like to be able to select the substring out of the ProgUID column below

something like...

SUBSTRING(table.ProgUID,3,12);

which would give me CAMVE-9701 for the ProgUID P-CAMVE-9701-1 (removing the P- from the beginning and the -1 from the end), and then insert the substring into that rows UID.

I assume this should be fairly easy, and I have been trying to figure it out but havent had much luck.

If there is a better approach please let me know!

Thanks in advance for your thoughts / help!

在此输入图像描述

use UPDATE statement

UPDATE tableName
   SET UID = SUBSTRING(ProgUID,3,12)

If the portion you want is always 12 characters, then

UPDATE table
SET UID = SUBSTRING(ProgUID, 3, 12)

otherwise

UPDATE table
SET UID = SUBSTRING(ProgUID, 3, LENGTH(ProgUID)-2)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM