# Continuous and discrete basis of Hilbert Space [duplicate]

Any state in Hilbert space $|\phi\rangle$ can be expressed in terms of a complete basis $\{| v_i\rangle, i=1,2,...\}$ as $$|\phi\rangle=\sum|v_i\rangle \langle v_i |\phi\rangle .$$ Now, if I understand this correctly, Hilbert space has the dimensionality of the complete basis. In other words, if any state can be expressed as a linear combination of, for example, three orthonormal vectors, then Hilbert space has dimension $d=3$.
Now, in many examples of QM the wavefunction can be expresed in terms of a discrete basis (like the energy eigenstates): $$|\phi\rangle=\sum_i|E_i\rangle \langle E_i |\phi\rangle ,$$ or in terms of a continuous basis (like the momentum eigenstates): $$|\phi\rangle=\int|p\rangle \langle p |\phi\rangle dp .$$ Is this correct? How can any state in Hilbert space be expressed in terms of a discrete sum and an integral? What is the dimension of Hilbert space then?
Also, the $\{|p\rangle\}$ doesn't behave like the discrete basis because the state $|\phi\rangle$ can't just be any linear combination of this basis.