Forum Stats

  • 3,872,015 Users
  • 2,266,364 Discussions
  • 7,911,025 Comments

Discussions

PL/SQL: $NAMEOF() compiler directive

jnicholas330
jnicholas330 Member Posts: 92 Green Ribbon
edited Jun 28, 2016 12:52PM in Database Ideas - Ideas

Sometimes it is useful to know the name of a variable or type, especially in error handling code. For example if an incorrect input is provided to the variable l_input, it would be nice to create a message such as "Invalid input for l_input". Right now this has to be hard coded. Instead I proposed the $NAMEOF() compiler directive, which would allow the following syntax 'Invalid input for ' || $NAMEOF(l_input). $NAMEOF() would return the string value of the identifier in question.

The benefit over a string literal is two-fold:

1. The identifier is evaluated by the compiler, ensuring a typo did not occur.

2. The identifier can be refactored using a PL/SQL aware IDE. Most refactor tools are unable to detect the presence of an identifier name in a string literal.

jnicholas330KalpatarujbosmanPravin TakpiregaverillBPeaslandDBA
8 votes

Active · Last Updated