0

I would to like to replace a letter in a string by position in big query. for example XXXXX, YYYYY, ZZZZZ the 5th letter in the string to 0 I've tried to use the Stuff function, but big query doesn't find the function Stuff(XXXXX, 5, 1, '0')

Shany H.
  • 113
  • 1
  • 6

2 Answers2

2

Probably the simplest method is more basic string operations:

select concat(substr(x, 1, 4), '0', substr(x, 6))
Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786
0

Below is for BigQuery Standard SQL and Legacy SQL (works for both)

SELECT REGEXP_REPLACE(str, r'(.{4}).(.*)', r'\10\2')
Mikhail Berlyant
  • 165,386
  • 8
  • 154
  • 230