Statistical mechanics for the assembly of the flux lines is developed for oxide superconductors with many crystal imperfections. For perfect crystals we provide a phase diagram where molten flux phase appears but does not occupy large regions in the H-T plane. We find new phase which we call the spontaneous flux phase. For imperfect crystals, we adopt the replica technique. It is concluded that the intrinsic pinning can possibly exist.