Skip to content
Advertisement

query inside the exception and begin block in exception

Hello I want to ask what is the best practise to do.

First example try to retrieve my data through exceptions I use this code in my main application and is working fine but I dont know if its good practise to code inside the exceptions blocks

SECOND EXAMPLE TRY TO RETRIEVE DATA WITH CASES AND SELECT WITH COUNT.

Advertisement

Answer

From personal experience…

Those nested blocks work fine and it can be useful to use code in exception blocks, but it becomes very unreadable quickly as you show in your example. If your initial code looks like this, then imagine what it will look like a couple of development cycles later.

It is cleaner to move those BEGIN SELECT INTO EXCEPTION WHEN NO_DATA_FOUND THEN... END: blocks into functions. Makes the code a lot more structured, more readable and easier to debug and maintain:

Here it’s an inline function – within packages you can use standalone functions, private if never called outside the package. Note, in your 2 examples you declare the variables in the inner block but call them in the outer block – that is something to avoid.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement