0

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'
1
  • I have rolled back the edit because it fundamentally changes the nature of the question. It is not that you should not ask that question but that you should ask a new question if you have a follow-up question. I would also suggest that you tag the new question with [sonarqube] because the new question is how to get sonarqube to stop flagging substitution variables as an issue rather than necessarily how to use constants. Commented Jul 12, 2024 at 13:00

1 Answer 1

2

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".

  • DEFINE v_target_table_name = 'BUSINESS_UNIT_T'
    

    DEFINE creates a substitution variable and whenever the client sees &v_target_table_name in an SQL statement then SQL*Plus will effectively do a find-replace and substitute the variable's value before sending the statement to the database for the database to process it (the database never sees the original text of the statement).

  • VARIABLE v_value VARCHAR2(20);
    EXECUTE :v_value := 'BUSINESS_UNIT_T';
    

    VARIABLE creates a bind variable and whenever the client sees the :v_value placeholder it will send the statement as-is to the database and also send the bind variable and then the database will parse the statement and bind the value in wherever it finds placeholder. (Note: bind variable are for values and not for trying to dynamically set identifiers.)

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;
/
Sign up to request clarification or add additional context in comments.

2 Comments

I have edited the question , you can check the job code snippet once and suggest accordingly
@radha You do not want to use PL/SQL with that script as you are importing other scripts. You need to ask a new question and tag it with [sonarqube] so that someone who knows that software can answer it because you may have false positive issues being raised as I'm not convinced there is an actual security issue with the script as you do not appear to be taking any user input. However, I don't use sonarqube so I don't know exactly what it is flagging.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.