You'll need a temporary visa or residency permit to stay in Spain, or any other Schengen country for longer than 90 days. If you're already a citizen or resident of an EU country, you only need to get the local registration certificate—no need to apply for any visa.