Is it possible to use the same column name as a parameter name on a cursor?

Asked

Viewed 235 times

0

I have the following cursor:

-- CÓDIGO OMITIDO
    DECLARE
      CURSOR CUR_AULAS(IDTURMA NUMBER) IS
      SELECT ID, IDCLIENTE
        FROM AULAS
      WHERE
        ATIVO = 1 
        AND IDTURMA = IDTURMA;

It will always return true because it thinks I am filtering the column itself (IDTURMA) and not by the parameter, if I change the parameter name works correctly but it is possible to use the same name type a thisjava?

  • why not use P_IDTURMA in the parameter name for better reading of the code?

  • I know I can use it, but my question is whether it is possible to have the same name.

  • 1

    It is not a good practice the ideal is always identify the object , use a prefix "P_" for help parameters is much reading code.

1 answer

1


It is not possible because according to oracle documentation for PL/SQL, when column e (parameters or variables) has the same name, column takes precedence.

If a SQL statement References a name that belongs to Both a column and either a local variable or formal Parameter, then the column name takes precedence.

If an SQL code references a name belonging to a column and a local variable or parameter, then the column will take precedence.

  • So it’s not possible?

  • no, since it will treat as table field and not as parameter

  • Good, thank you André! =)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.