$post_content = $wpdb->get_results("select post_content from wp_posts where ID = 9969");
$content = $post_content[0]->post_content ;
$replaced_content = preg_replace_callback('/code to replace in form of regex/',
'code with which you want to replace',
$content);
$wpdb->query('UPDATE wp_posts SET post_content = "'.$wpdb->_real_escape($replaced_content).'" WHERE ID = "'.$post_id.'"');