MySQL 8.0+ এ REGEXP_REPLACE() ফাংশন ব্যবহার করে স্ট্রিংয়ের শুধু প্রথম যাবতীয় ঘটনা রিপ্লেস করা যায়।
উদাহরণ
মান लीজিয়ে আমাদের স্ট্রিংটি:
'This is my first MySQL query. This is the first tutorial. I am learning for the first time.'এখানে শুধু প্রথম
'first'শব্দটিকে'second'দিয়ে রিপ্লেস করতে চাই। আউটপুট হবে:'This is my second MySQL query. This is the first tutorial. I am learning for the first time.'টেবিল তৈরি ও ডেটা ইনসার্ট
CREATE TABLE demo26 ( value TEXT ); INSERT INTO demo26 VALUES ('This is my first MySQL query. This is the first tutorial. I am learning for the first time.');কোয়েরি
REGEXP_REPLACEএর সিনট্যাক্স:REGEXP_REPLACE(column, pattern, replacement, position, occurrence)এখানে
position = 1(শুরু থেকে) এবংoccurrence = 1(প্রথম ঘটনা)।UPDATE demo26 SET value = REGEXP_REPLACE(value, 'first', 'second', 1, 1);আউটপুট
আপডেটের পর:
+----------------------------------------------------------------------------------------------+ | value | +----------------------------------------------------------------------------------------------+ | This is my second MySQL query. This is the first tutorial. I am learning for the first time. | +----------------------------------------------------------------------------------------------+নোট:
REGEXP_REPLACEMySQL 8.0.4 সংস্করণ থেকে উপলব্ধ। পুরনো ভার্সনে এই ফাংশন নেই। সেক্ষেত্রে সাবস্ট্রিং ও লোকেশন ফাংশন কম্বাইন করে করতে হয়।