WP: Search and replace in DB programmatically

Is it possible to make a search-replace query on WP programmatically without any other plugins (I already know about “Better search replace” and other ones available, but it’s not the option).

Succinctly, yes – the existence of “Better Search and Replace” is a testament to the possibility.

A search-and-replace by itself is simple – you can make the necessary SQL queries through the WPDB interface. The complexity in writing such a thing from scratch lies in whether or not that operation needs to affect fields which WordPress serializes, as performing a replacement in serialized data without unserializing and reserializing the string or otherwise updating the serialization will invalidate the data.

If using a pre-made plugin is not an option, studying such a plugin’s code to see how they accomplish that feat would be a good move.