You can do that via MyO2.
Info below from https://www.o2.co.uk/help/device-and-sim-support/how-to-keep-your-mobile-number#how-do-i-use-my-pac-code
Swapping your O2 sim
If you’re just changing or replacing your sim and want to move your mobile number across to your new sim, you can do this in My O2.
If you’re an O2 Business customer, please sign in to My O2 Business to swap your sim.
If you haven’t already got a replacement sim, you can request one by calling us on 202, starting a webchat, or visiting an O2 store.
How long does it take to swap?
Sim swaps can take up to 24 hours to complete.
Once you lose signal with your original sim, turn your device off and turn it back on. If you’re using a plastic sim, pop it in your device. Wait till you see your network appearing on your device.