Questions tagged [string-manipulation]

String manipulation on the database server side is achieved using built-in string processing functionality (operators, functions). Use this tag for questions where string processing is central to the problem.

Filter by
Sorted by
Tagged with
1 vote
1 answer
101 views

Find and show special character codes from nvarchar column

I want to know which special characters (line breaks, tabs, etc) are in my column of type nvarchar. I know how I can select which rows contain a specific character. e.g. SELECT * FROM your_table WHERE ...
user avatar
  • 229
1 vote
1 answer
37 views

Remove third coordinate from string

I have geometries represented as strings (Oracle 18c): with cte as ( select 'LINESTRING ( 1.0 2.0, 3 4)' as txt from dual union all select 'LINESTRING M ( 1 2 3, 4 5 6.0)'...
user avatar
  • 1,389
0 votes
1 answer
31 views

Compare occurence of chars in PostgreSQL string

I have some data like this: metaphone lag FLKSW [null] PPS FLKSW PPS PPS PSP PPS And I want to compare the string values in both columns on the folowing condition: they're similar (assign some ...
user avatar
1 vote
1 answer
36 views

In a string, replace third number in each set with new number

I have a string that has coordinates. Individual coordinates are separated by spaces. Vertices (X Y Z coordinates) are separated by commas. Vertex groups are wrapped in brackets and separated by ...
user avatar
  • 1,389
0 votes
1 answer
29 views

SQL in Access to add leading 0 in front of zip codes

for a project I am working with a table of zip-codes that I imported from a *.csv file, exported form Excel. Those zipcodes all have 5 numbers and are formatted as text within my database. Some of ...
user avatar
  • 1
-5 votes
1 answer
141 views

Select INTs from start of string separated by a character (pipe). Update other columns using these INTs

In the above screen shot, the Description column has many special characters. We want before | number update in T1 column and | after number in T2 column. Please suggest the proper syntax. If there ...
user avatar
1 vote
2 answers
73 views

Determine Ideal Collation Set for correct data storage

Alright so I have a MariaDB DB and I've just noticed some weird storage issues, like the following: My JSON columns (which in MariaDB are LONGTEXT) have an automatically set collation of utf8mb4_bin. ...
user avatar
  • 147
0 votes
0 answers
41 views

Convert any string to url valid percent encoding in BigQuery

I am trying to convert any string with any set of special characters into a valid url of the format below. In Bigquery Example: /artwork-v2/-̴̕ι-̶͔͛n̴e̷p̸u̴̒n̵uś̵̥o̵̙̾rt̷͗um̶̹͐-20380 encodes to: /...
user avatar
0 votes
2 answers
441 views

Batch update to replace special characters in SQL Studio Management

I am trying to remove/correct some special characters in my database that show strange behaviour when exported. Specifically & and the apostrophe ’ I ran a query to find the values that contain ...
user avatar
2 votes
1 answer
198 views

How can I change string output in a hierarchy tree with PostgreSQL?

I have a table like this: ------------------------------------------------- | id | description | parent_id | cost -------------------------------------------------- | 1 | Radiology ...
user avatar
  • 37
1 vote
3 answers
91 views

String concatenation and DATE/Number ordinals in one string?

How can I combine functions with strings to end up with a whole in one sentence? I mean something like this (expected result): Today is the 3rd day of the year, the 2nd week of the year and the 1st ...
user avatar
  • 11
0 votes
2 answers
525 views

How to remove specials characters, but replace spaces?

I have a string with spaces & special characters: ABC%$! DEF*& GHI I want to remove all the specials characters, but replace the spaces with an underscore: ABC_DEF_GHI I have: REGEXP_REPLACE(...
user avatar
0 votes
1 answer
241 views

Stored procedure to change string to datetime in MySQL

This is a follow up to this question. Turns out the driver that I am using (can't change it) is not compatible with timestamp values. Lets say it is set in stone that I have to load the data into my ...
user avatar
  • 105
0 votes
1 answer
40 views

Problem using 'Regular expression' in order to split characters of a column when there is no delimiter between them

I have a table with below structure: create table TBL_TEST ( col_id NUMBER, col_name VARCHAR2(500) ) Some example data : col_id | col_name ----------------- 1 | aetnap 2 | ...
user avatar
  • 1,302
0 votes
1 answer
33 views

How to massively change string capitalization in a table?

I have a project where authors' names have been inserted in all capital letters (ex. JOHN KRAUS, LEONARD MILES, NAOMI DAWSON). Now I need these values in "normal" case (ex. John Kraus, ...
user avatar
0 votes
2 answers
68 views

How do I speed up a string manipulation query where I want to replace characters, extract certain values and update a table with the results?

I am trying to extract information from strings that are presented in a key-value format, with the keys and values being separated by commas. I want to extract the values associated with certain keys ...
user avatar
1 vote
1 answer
588 views

Error "ORA-12726:unmatched bracket in regular expression" while trying to separate a part of a string from other part

I have a string like this : v_sgtring:'sum:[sum(x)>1 and sum(y)>2 and sum(z)>3],where:[n=1 and m=2]' and I need to separate sum:[] from where:[] and assign them to different variables like ...
user avatar
  • 1,302
0 votes
0 answers
29 views

How to separate a part of a string from other parts in Oracle SQL using regular_expression

I have a string like this : string := ' (sum(x) = 12 and sum(y) = 13 and sum(z) = 14 ) and w = 'p' AND q = 'p' AND l ...
user avatar
  • 1,302
3 votes
2 answers
1k views

Replace a sequential set of numbers with special character

I have a varchar(200) column that contains entries such as, ABC123124_A12312 ABC123_A1212 ABC123124_B12312 AC123124_AD12312 A12312_123 etc.. I want to replace a sequence of numbers with a single * ...
user avatar
  • 33
1 vote
3 answers
116 views

REPLICATE() return type for VARBINARY input

REPLICATE ( string_expression ,integer_expression ) As documentation says, it returns the same type as string_expression. I see that return type is always VARCHAR. declare @vb varbinary(10) = ...
user avatar
  • 335
3 votes
1 answer
152 views

Concatenate a string value from table A to a text field in table B, in a scalable way

On a daily basis, I am adding values from the following table (table1): Id Name Value 1 'Name 1' 789 2 'Name 2' 789 3 'Name 3' 789 To the text field (Values) in the following ...
user avatar
0 votes
1 answer
79 views

Behavior of STUFF function for empty strings

When working on answering another question (on SO), I came across some unexpected (to me) behavior with the STUFF function. SELECT STUFF ( 'a', -- character expression 1, -- start 1, -- ...
user avatar
  • 173
2 votes
4 answers
2k views

remove leading and trailing quotes

I have a field that may start and end with quotes. I only want to remove the quotes if the string starts and ends with quotes. If quotes exists inside the string then I wish to retain them. I have ...
user avatar
  • 123
0 votes
1 answer
57 views

How to use query result as REPLACE parameters

i'm trying to: 1- Find a string inside a lot of content 2- Replace that specific part of the string with a new one using REPLACE function like this: REPLACE(column_name, query#1, query#2) Is this ...
user avatar
1 vote
1 answer
34 views

Using LOCATE() Function as SUBSTRING() parameter gives ramdom result. Extracting string from text

I have several rows with a lot of content and i'm trying to find some code and extract it. It looks like this: Some code... <div>&nbsp;</div> <div>[flv:http://submarino-libre....
user avatar
0 votes
2 answers
61 views

Get matching part from conditional pattern

I'm having a table like this: |id|key |value | ------------------------ | 0|name |Homer | | 1|surname|Simpson | | 2|town |Springfield| I'm running this query: SELECT * FROM ...
user avatar
  • 103
5 votes
1 answer
4k views

How to pass variable to PL/pgSQL code from the command line?

I am running a psql script from the command line with variables something like: psql ...... -v now_utc=$NOW_UTC Then I want to use this in my script like: $$ DECLARE _now_date timestamp := :...
user avatar
0 votes
3 answers
683 views

How to trim a string by finding multiple words

I want to trim a string if it contains certain words or characters. This is just part of a big stored procedure. I want if v_selection_name contains any of those characters .eg: ' (RES)' or ' (R)' ...
user avatar
  • 115
5 votes
2 answers
968 views

Wordcount in a field (all and unique) - is there a more elegant/optimal way?

Answering this question, Given this table (constructed from the question): CREATE TABLE wordcount (id SERIAL NOT NULL PRIMARY KEY, description TEXT NOT NULL); INSERT INTO wordcount (description) ...
user avatar
1 vote
1 answer
20 views

pgsql Return Partial Text Field Ending In A Whole Word

I found this PHP code that returns a sub-string ending with a whole word (IE separated by a space): if ( strlen( $body ) < $maxlength ) return $body; $body = substr( $body , 0 , $maxlength ); $...
user avatar
1 vote
1 answer
877 views

Using SUBSTRING and RTRIM Together

I have a VARCHAR field that contains a city and a 2 digit state abbreviation, but there tends to be leading and trailing spaces in the field. I need to parse out the City and State Abbrev into ...
user avatar
3 votes
2 answers
6k views

How to replace multiple parts of a string with data from multiple rows?

Here's a fiddle to show what I'm after. Given a table with two columns - an integer ID and a text-based string - I want to start with a string value that encodes any number of integers wrapped in ...
user avatar
3 votes
1 answer
43 views

Unexpected behavior from ltrim in postgres

select ltrim('Test Thing', 'Test '); Expected: 'Thing' Actual Result: 'hing' Why does the 'T' in 'Test' match and trim the 'T' from 'Thing'?
user avatar
  • 31
0 votes
1 answer
227 views

How to eliminate for loop in a nested aggregate problem

I have a parsing problem that I am solving with a FOR LOOP in plpgsql, basically because I can't figure out how to solve it with subqueries and nested aggregates. My question is can the for loop be ...
user avatar
  • 169
0 votes
1 answer
134 views

SQL Server 2017 - Extracting source and target column names within a string containing column mappings

I have the following format string stored in text (could be any number of columns): col1_source|col1_target;col2_source|col2_target;col3_source|col3_target;... I'm trying to come up with an ...
user avatar
1 vote
2 answers
360 views

Strip longest common suffix and concat in Postgres

Given a table t: id | name ------------ 1 | abcfug 1 | deffug 1 | hijfug 2 | etc How can I do something like: select string_agg(strip_lcs(name), ', ') from t where id = 1 returning: abc, def, ...
user avatar
  • 129
1 vote
3 answers
1k views

How do You concatenate a value to an array that was retrieved through a query in sql?

I have a table named "mkvtable" that establishes a correspondence between individual strings and arrays of strings: word | mkvword ---------+----------------- hello | {world,friend} ...
user avatar
1 vote
2 answers
177 views

SUBSTRING and IF statement

I have varchar column, its name is column1 and has records like 111232435-0 and 1123443530. The last digit is not always 0; it can be 0-9. Some of them are digits with (-), other are digits. I want ...
user avatar
  • 37
-1 votes
2 answers
597 views

TSQL Query to Remove Dates in Multiple Formats from Text Values [closed]

I have a table with list of text values that contain dates in any format types. I need a TSQL query to remove the dates from each row in the table. The date samples are below. What is the best way ...
user avatar
  • 503
0 votes
0 answers
268 views

nText and String manipulation. SQL SERVER

Parent question - Thanks to Paul White and Tom V for answer. I am making little modification's to Paul White's answer to suit my requirements. I would like to change the following to replace a ...
user avatar
  • 1
2 votes
2 answers
349 views

String manipulation tools to populate a variable for two "functions"

Versions: SQL Server 2008 R2 - 2014 I'm using a server audit to find changes to logins on my SQL Server instances, and writing it to the ERRORLOG directory path. Unfortunately, not all the instances ...
user avatar
1 vote
1 answer
473 views

Does a Levenshtein distance involve some computation for each single row?

Let's say I have, in a SQL DB, a table with 2 columns: id integer, description text and 100,000 rows. The column description has always < 20 characters. If I want to: SELECT * FROM mytable WHERE ...
user avatar
  • 161
0 votes
0 answers
650 views

MySQL version of split_to_array or split_to_table?

PostgreSQL supports two String Functions, that are incredibly useful regexp_split_to_array regexp_split_to_table Both of these functions essentially take two strings, (a) a pattern and (b) an input ...
user avatar
  • 56.2k
0 votes
1 answer
38 views

PostgreSQL: Function to reformat a string

Suppose I have a string such as: abcdefghi and I would like to reformat it as: abc def ghi (that is, I have added some formatting spaces to the string). Is there a PostgreSQL function which will ...
user avatar
  • 2,337
-2 votes
2 answers
583 views

Error when using a query as a function parameter [closed]

I have followed this tutorial for creating a string splitting function. When I try to run the function from the article using a SELECT as the first parameter, I get the following error: select '...
user avatar
  • 97
7 votes
1 answer
2k views

Is the function PARSENAME() the opposite of QUOTENAME()

In the question Is there any (hidden) built-in function on MS-SQL to unquote object names? the author was seeking advice on if there was an internal function to "UNQUOTE" a quoted string. The author ...
user avatar
1 vote
1 answer
3k views

Use STUFF function to insert at multiple points in a string?

Is there a way that I can replace a substring in SQL server while remaining 'aware' of what I'm replacing so that I can then re-insert that content? I am building a string of column names to pivot on,...
user avatar
  • 2,222
24 votes
1 answer
69k views

Decode Base64 String Natively in SQL Server

I have a varchar column in a table in SQL Server which hold a base64-encoded text string which I would like to decode into it's plain text equivalent Does SQL Server have any native functionality to ...
user avatar
  • 2,507
0 votes
1 answer
5k views

Concatenate with NULL values ( Should not replace NULL )

After some time searching for an answer, I got a LOT of question saying to use coalesce,concat(), and etc, but what I need is: Table: create table nulos ( nome varchar(max)) alter table nulos add ...
user avatar
  • 7,104
6 votes
3 answers
6k views

Filtering characters to just return numeric characters in a string?

I want to filter an nvarchar field to return just the numeric values. I have some SQL to do this but it seems way more complicated than it needs to be. I am interested in finding out if anyone has a ...
user avatar