IN PL/SQL how to declare and use ‘STATIC DATA TYPE like C’

Tags:
Oracle Application Server
Oracle Database
Oracle development
PL/SQL
Hi All, Can anybody help me to declare a variable having the similar propery of 'STATIC DATA TYPE IN C'. Means declare a variable and initialize it inside the procedure and called the procedure recursively but each time it is initializing the variable. I want any mechanism in PL/SQL that will make the variable like 'static in C'. Note:-- Static varible in C :- This type of variable will be initialized once throughout it's life time. If it is declared in a function then the life span is inside the function and till the function is not end it is retaining the value. It is initialized once. Thanks Sudhansu

Answer Wiki

Thanks. We'll let you know when a new response is added.

I think an exact match for the STATIC modifier does not exist in pl/sql (because in C it can be applied even to functions or class members and each can be affected in a different way) , but you can achieve something similar usging the ‘CONSTANT’ keyword.

Example:

<pre>v_time_constant constant varchar2(8) := to_char(sysdate,’hh24:mi:ss’);</pre>

If you place this declaration on a function that is called recursively, it will initialize with the time in which the function starts, and will retain its value till the function ends. In the next recursive call, it will initialize with some other value, at it will keep that value during the life of the current call.

Hope this helps.

Discuss This Question: 1  Reply

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • Abhijeetpatil86
    hi i think constants can be somewhat solution to the Static variables...... as this can not be changed once initialized one of the solution is using the package variables u can initialize the package variables once using default value and use it anywhere
    40 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following