Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
244 views
in Technique[技术] by (71.8m points)

java - compair 2 strings in sql [first string contain 2nd string's substrings]

i am sharing a java code related to my question, by that you can easily understand what i am exactly looking in SQL.

Java code

String s1 = "http://hdvidz.co/video/file/Naa-Peru-Meenakshi-%7C-11th?id=rj5e--8vQb4";
    String s2 = "Naa Peru Meenakshi";
    String splitStringS2[] = s2.split(" ");// using blank space to split
    int i = 0;
    for (String a : splitStringS2) {
        if (s1.contains(a)) {
            i = i + 1;
        } else {
            System.out.println("break perform");
            i = 0;
            break;
        }
    }
    System.out.println("value of i===  " + i);

i have 2 table ; table A has a column "link" that contain value "http://hdvidz.co/video/file/Naa-Peru-Meenakshi-%7C-11th?id=rj5e--8vQb4"; table B has a column "name" that contain value "Naa Peru Meenakshi"

CREATE TABLE `A` (`link` VARCHAR(255) );
insert into A values("http://hdvidz.co/video/file/Naa-Peru-Meenakshi-%7C-11th?id=rj5e--8vQb4");
CREATE TABLE `B`(`name` VARCHAR(255) );
insert into B values("Naa Peru Meenakshi");

now what exactly i want

1) pick a value from table B and split into substring and store in array splitName.

2) pick a value from table A & store in variable url

3) now checking substring (splitName) exist in variable url

4) if all substring found in url return count (substring match) , else return 0

above java code is doing same thing.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You can write a stored procedure. I haven't used MySQL in a while, but I'm fairly sure it doesn't support a split function. You can write a user-defined procedure as done in here.

I think you can also use LOCATE to find the position of a sub-string inside a string. UPDATE: Check the second answer in the link.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...