oraclesqlplus

How to declare a constant in Oracle SQL PLUS?


I know how to declare a variable in Oracle sql plus but not sure with the constant declaration , Pls guide with that :

An example of variable declaration :

DEFINE v_target_table_name          = 'BUSINESS_UNIT_T'

Solution

  • SQL*Plus is a client application which is used as an interface for a user to talk to the database; it is not a database and has limited capability to create "variables".

    Neither of these commands have any syntax that supports making the value a constant.


    If you want to use a constant then you could use PL/SQL (which will be evaluated by the database and is not specific to SQL*Plus):

    DECLARE
      v_target_table_name CONSTANT VARCHAR2(20) := 'BUSINESS_UNIT_T';
    BEGIN
      -- Do something with the variable
      NULL;
    END;
    /