Skip to content
Advertisement

Is there anyway to test the function in SQL?

I have following problem. I’ve made an function which checks dates, warehouse if it’s full, etc..

Here is the code and I’ve added comments so it is more clear and understanble:

So basically if I run only the function I don’t get any error. But when I run it with the test date I get following error:

I’ve tried to debbug it and also input different test dates but still, same error.

Advertisement

Answer

After you compile the procedure either run:

or (assuming you are compiling it as the owning user and not as a DBA user; if you are not the owning user then use ALL_ERRORS):

Either will give you a list of the errors in the procedure and you can then debug it and fix the errors so the procedure works.


Update

From the comment:

Could it be because of my variables? They start with underscore

From the Database Object Names and Qualifiers documentation:

Database Object Naming Rules

Every database object has a name. In a SQL statement, you represent the name of an object with a quoted identifier or a nonquoted identifier.

  • A quoted identifier begins and ends with double quotation marks (“). If you name a schema object using a quoted identifier, then you must use the double quotation marks whenever you refer to that object.
  • A nonquoted identifier is not surrounded by any punctuation.

  1. Nonquoted identifiers must begin with an alphabetic character from your database character set. Quoted identifiers can begin with any character.

You have many identifiers for variables that begins with an underscore. This tells you that the solution is to change the variable names to start with an alphabetic character (or to use a quoted identifier and surround the identifier with double quotes; but don’t use quoted identifier, just use a letter as a prefix before the underscore):

Also, don’t use:

As it may generate duplicate values if the procedure is called twice at the same time.

Instead, create a sequence for the column and get the next value from the sequence.

(Start with whatever is 1 more than your current maximum value.)

Then in your procedure use:

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