No, in principle you cannot. If you only want to go to Spain, you should apply to the Spanish consulate and the Greek consulate should refuse to consider your application (see Applying for a Schengen visa in another country than my main destination). If you somehow do get a Greek visa to travel to Spain and the Spanish border guards notice it, they can annul the visa and deny entry (see Schengen visa requirements and "validation").
You can however enter Spain with a visa issued by the Greek consulate (see Should my first trip be to the country which issued my Schengen Visa?) or even travel to other Schengen countries without going through Greece at all (see Does a multiple-entry Schengen visa allow visiting other Schengen countries later, without going via the issuing country?). But that's mostly relevant if you have a legitimate reason to have a Greek visa in the first place (e.g. Greece is your main destination or you have a multiple entry circulation visa because you go to Greece regularly) and not for a single-entry visa obtained for another trip.
In practice, you could still get away with it, especially if you buy a ticket from Spain to Greece so as to make it look like Greece is your main destination. But this would obviously be a form of fraud and could have serious consequences if found out.