In order to solve problems such as environmental pollution and pipeline blockage caused by oily wastewater after washing, N,N-dimethylcyclohexylamine (DMCHA) with CO2 response was selected as the oil phase, and an O/W microemulsion wellbore cleaning fluid with CO2 switching characteristics was successfully prepared with erucamide propyl betaine (EAB-40), sodium dodecyl benzene sulfonate (SDBS), n-butanol, silicone defoamer, and water. The water content of the microemulsion was 89.99%, and it had good stability at 40 and -5 °C. The emulsion was rapidly demulsified after being injected with CO2 in the CO2-repurification microemulsion detergent, and CO2 was removed with a N2 detergent. The emulsion was restored to its original state, which demonstrated the CO2/N2 switching properties of the emulsion. It is proven that the switching microemulsion has a good wetting transformation ability by cleaning the steel sheet and quartz sheet contaminated by oil-based slurry. The switching microemulsion system can clean the simulated wellbore contaminated by oil-based slurry, and the cleaning efficiency is above 99%. CO2 can be used at room temperature to separate oil and water from oily wastewater after cleaning.