It worked for Zhong Guo against Mongol hordes.
Then again, Mongol technology consisted of horses, silk shirts, bolt projectiles and fire. Maybe a catapult if fortunate enough to have commandeered one.
A wall would provide a filter, but not a solid defense. There is still the moral hazard problem within American capitalism which leaves incentive for the use of illegals on the table, unfettered. A defensive, economic policy needs to be applied as well if a holistic treatment of the issue is desired.
So long as the incentive is there, a wall is only an impediment, not a cure.