SQL statement for guidance, how to resolve

Source: Internet
Author: User
SQL statement seeking guidance
Table Name: table1
Field: ID value (number plus comma/number of digits indeterminate)
Content A:1 3,5
Content B:2 3,3
Content C:3 3,4,5
Content D:4 5,3,6
All I have to do is find the corresponding ID. Replace 3 in the Value field with 4 to replace only one

The final effect to achieve
Content A:1 4,5
Content B:2 4,3
Content C:3 4,4,5
Content D:4 5,4,6

SQL statements: SQL PHP MySQL

Share to:


------Solution--------------------
Oracle, MySQL does not test, the corresponding function for MySQL should be able to.
Select Replace (firststr, ' s ', ' a ')
------Solution--------------------
Secondstr
From (SELECT substr (str, 0, InStr (str, ' s ')) Firststr,
substr (str, InStr (str, ' s ') +1) secondstr
From (select T1.value str from table1 t1 where t1.id=1))
------Solution--------------------
Sorry I just forgot to change the character.
Oracle, MySQL does not test, the corresponding function for MySQL should be able to.
Select Replace (FIRSTSTR, ' 4 ', ' 3 ')
------Solution--------------------
Secondstr
From (SELECT substr (str, 0, InStr (str, ' 4 ')) Firststr,
substr (str, InStr (str, ' 4 ') +1) secondstr
From (select T1.value str from table1 t1 where t1.id=1))
------Solution--------------------
Select Replace (FIRSTSTR, ' 3 ', ' 4 ')
------Solution--------------------
Secondstr
From (SELECT substr (str, 0, InStr (str, ' 3 ')) Firststr,
substr (str, InStr (str, ' 3 ') +1) secondstr
From (select T1.value str from table1 t1 where t1.id=1))
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.