sqlplus Setting the exit code of a script
Try it like this:

var retCode number
exec :retCode := 30;
exit :retCode


(See http://www.orafaq.com/forum/mv/msg/80574/233106/0/#msg_233106)

Bottom line is that retCode must be a variable defined in SQL*PLUS's scope. Your DECLARE is inside a code block, and SQL*PLUS can't see into it.