add
remove
language
chart
show hidden
hide
db<>fiddle
Db2
DocumentDB
DuckDB
Firebird
MariaDB
MySQL
Oracle
Postgres
SQL Server
SQLite
TimescaleDB
YugabyteDB
11.1
11.5
12.1
0.114 (MongoDB 7.0)
0.116 (MongoDB 7.0)
1.4 LTS
3.0
4.0
5.0
10.2
10.3
10.4
10.5
10.6
10.7
10.8
10.9
10.11
11.4
11.8
12.3
5.5
5.6
5.7
8.0
8.4
9.7
11g Release 2
18c
21c
23c
23ai
26ai
8.4
9.3
9.4
9.5
9.6
10
11
12
13
14
15
16
17
18
19 beta 4
2012
2014
2016
2017 (Linux)
2017
2019 (Linux)
2019
2022
2025
3.8
3.16
3.27
3.39
3.45
3.53
2.11
2.14
2.28
2.6
2.8
2.18
2024.2 LTS
2025.2 LTS
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
Sakila
no sample DB
Sakila
no sample DB
Sakila
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
HR
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
db<>fiddle Statistics
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
AdventureWorks
no sample DB
AdventureWorks
no sample DB
AdventureWorks
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
no sample DB
run with 2025
abort
markdown
clear
donate
feedback
about
By using db<>fiddle, you agree to license everything you submit by
Creative Commons CC0
.
CREATE FUNCTION dbo.fnPattern_Split ( @str VARCHAR(MAX), @pattern VARCHAR(100) ) RETURNS @tbl TABLE ( ordinal INT, value VARCHAR(MAX), match BIT ) WITH SCHEMABINDING AS BEGIN DECLARE @value NVARCHAR(MAX) , @splitvalue NVARCHAR(MAX) , @startpos INT = 0 , @endpos INT = 0 , @ordinal INT = 0 , @foundend BIT = 0 , @patminlen INT = ISNULL(NULLIF(LEN(REPLACE(@pattern,'%','')),0),1); WHILE (LEN(@str) > 0) BEGIN SET @startpos = ISNULL(NULLIF(PATINDEX('%'+@pattern+'%', @str),0), LEN(@str)+1); IF @startpos < LEN(@str) BEGIN SET @foundend = 0; SET @endpos = @startpos+@patminlen-1; WHILE @endpos < LEN(@str) AND @foundend = 0 BEGIN IF SUBSTRING(@str, @startpos, 1+@endpos-@startpos) LIKE @pattern SET @foundend = 1; ELSE SET @endpos += 1; END END ELSE SET @endpos = LEN(@str); IF @startpos > 1 BEGIN SET @ordinal += 1; SET @value = LEFT(@str, @startpos-1); INSERT INTO @tbl (ordinal, value, match) VALUES (@ordinal, @value, 0); END IF @endpos >= @startpos BEGIN SET @ordinal += 1; SET @splitvalue = SUBSTRING(@str, @startpos, 1+@endpos-@startpos); INSERT INTO @tbl (ordinal, value, match) VALUES (@ordinal, @splitvalue, 1); END SET @str = SUBSTRING(@str, @endpos+1, LEN(@str)); END; RETURN; END;
DECLARE @vchNewValue VARCHAR(100), @result VARCHAR(100); SET @vchNewValue = 'A OR B or C OR D or E OR F'; SET @result = LTRIM(RTRIM(( SELECT CASE WHEN match = 1 THEN ' '+quotename(ltrim(rtrim(replace(value,' OR ',' or ') )),'''')+' ' ELSE UPPER(value) END FROM dbo.fnPattern_Split(' '+@vchNewValue+' ', ' % OR % ') AS spl ORDER BY ordinal FOR XML PATH(''), TYPE).value(N'./text()[1]', N'nvarchar(max)') )); SELECT @result AS result;
result
'A or B' OR 'C or D' OR 'E or F'