PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, October 24, 2022

[FIXED] How to write the exact text next to the text and replace certain letters in it? SQLite

 October 24, 2022     db-browser-sqlite, replace, sql-update, sqlite     No comments   

Issue

I am creating a phonetic dictionary for American English. Here are some examples:

vocabulary      phonetic_transcription
dream           dɹim
drain           dɹeɪn
drink           dɹɪŋk
adrenaline      əˈdɹɛnəlɪn

If dɹ is in the phonetic_transcription, I want to write an alternative to it replacing 'd' with 'ʤ'. The expected outcome is:

vocabulary      phonetic_transcription
dream           dɹim / ʤɹim
drain           dɹeɪn / ʤɹeɪn
drink           dɹɪŋk / ʤɹɪŋk
adrenaline      əˈdɹɛnəlɪn / əˈʤɹɛnəlɪn

I know how to change a certain element with another with replace function but I have no idea how to do it like above.


Solution

Use string functions like INSTR() to filter the table so that only rows with phonetic_transcription that contain 'dɹ' will be updated and REPLACE() to replace the string 'dɹ' with 'ʤɹ':

UPDATE tablename
SET phonetic_transcription = phonetic_transcription || ' / ' || REPLACE(phonetic_transcription, 'dɹ', 'ʤɹ')
WHERE INSTR(phonetic_transcription, 'dɹ');

See the demo.



Answered By - forpas
Answer Checked By - Robin (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing