The Schrieffer-Wolff transformation aims to solve degenerate perturbation problems and give an effective Hamiltonian that describes the low-energy dynamics of the exact Hamiltonian in the low-energy subspace of unperturbed Hamiltonian. This unitary transformation decoupling the low-energy and high-energy subspaces for the transformed Hamiltonian can be realized by quantum circuits. We give a fully quantum algorithm for realizing the SW transformation. We also propose a hybrid quantum-classical algorithm for finding the effective Hamiltonian on NISQ hardware, where a general cost function is used to indicate the decoupling degree. Numerical simulations without or with noise and experiments on quantum computer ibmq_manila are implemented for a Heisenberg chain model. Our results verify the algorithm and show its validity on near-term quantum computers.