DEV Community

Cover image for Search for Records Containing a Specified String Group in Multi Fields — From SQL to SPL #40
Judith-Data-Processing-Hacks
Judith-Data-Processing-Hacks

Posted on

4 2 2 2 2

Search for Records Containing a Specified String Group in Multi Fields — From SQL to SPL #40

Problem Description & Analysis:

A table in an Oracle database has multiple string fields.

source table
Task: Now we need to input a parameter that contains multiple strings separated by commas. We need to find the records in the table that contain all these strings in the fields, or those records where the set of fields is a superset of the parameter. For example, when the parameter argA=”street,John,Doe”, the calculation result is as follows:

expected results

Solution Highlights:

We can convert string parameters and each record into sets respectively, and filter out those records where the difference set of the two is an empty set.

But it is not easy to split string parameters into sets in SQL. Regular expressions and CONNECT BY functions are required, and the code is quite cumbersome. Some databases do not support this writing method and can only implement it using custom functions or stored procedures, which is even more troublesome. Converting a certain record into a set is also very cumbersome, usually requiring writing comparative judgments for each field, which is very tedious.

SPL provides directly usable functions that can easily convert string parameters and records into sets for intersection, union and difference operations.

esProc SPL code

A1: Query the database through JDBC.

A2: Split the parameter into a string set by commas. The split function splits a string using the specified delimiter, @c indicates that the delimiter is a comma.

A3: Filter out records where the difference between the parameter and the field set is an empty set, which is equivalent to finding records where the set of fields is a superset of the parameter.


🌟 Try esProc SPL for Free — esProc SPL FREE Download.

Build seamlessly, securely, and flexibly with MongoDB Atlas. Try free.

Build seamlessly, securely, and flexibly with MongoDB Atlas. Try free.

MongoDB Atlas lets you build and run modern apps in 125+ regions across AWS, Azure, and Google Cloud. Multi-cloud clusters distribute data seamlessly and auto-failover between providers for high availability and flexibility. Start free!

Learn More

Top comments (3)

Collapse
 
nevodavid profile image
Nevo David

Pretty cool seeing tools that make the annoying stuff in SQL way easier. Been there, done that.

Collapse
 
judith677 profile image
Judith-Data-Processing-Hacks

Totally agree — some of those repetitive SQL tasks can get frustrating. Pretty glad you found this helpful! Thanks for checking it out! 😊

Some comments may only be visible to logged-in visitors. Sign in to view all comments.

Gen AI apps are built with MongoDB Atlas

Gen AI apps are built with MongoDB Atlas

MongoDB Atlas is the developer-friendly database for building, scaling, and running gen AI & LLM apps—no separate vector DB needed. Enjoy native vector search, 115+ regions, and flexible document modeling. Build AI faster, all in one place.

Start Free

👋 Kindness is contagious

Discover fresh viewpoints in this insightful post, supported by our vibrant DEV Community. Every developer’s experience matters—add your thoughts and help us grow together.

A simple “thank you” can uplift the author and spark new discussions—leave yours below!

On DEV, knowledge-sharing connects us and drives innovation. Found this useful? A quick note of appreciation makes a real impact.

Okay