The Sample code that I have written is for sqlplus.
It will exit sqlplus on the specified condition.
The declare - begin - end part is called an anonymous block, so it will not be stored in the database. so each time you will have to write it or you will have to store the code in a .sql file and then you will have to execute the .sql file when the same code is required.
I am not sure about the exit code 0 or whatever you are looking for.
But the samplecode will definately run on sql prompt.