Database Global Variable

Hi,

Is there a way to set up a variable that is stored and used again and again in the database (Oracle).  I want to set the financial Year to 2017.  It's used over and over again in stored procedures and views etc...  When it's changed, it should be changed in everything.

Like a global variable but where do you declare it etc...


Kind regards,
Caoimhe
Coco BeansDesignerAsked:
Who is Participating?
 
Martyn SpencerConsultantCommented:
You could create a package that contains the constant. To ensure that it can be referenced in SQL, wrap it in a function. My reason for suggesting a package is that you could call it something like "app_constants" and then place all of your constant definitions there. If you only have one constant, just create a function. Let me know if you need an example.
1
 
NorieVBA ExpertCommented:
Caoimhe

As far as I know Oracle doesn't support global variables but what you could do is create a function that returns the value you want.

Something like this perhaps.

CREATE OR REPLACE FUNCTION fin_year
RETURN NUMBER DETERMINISTIC
AS
BEGIN
    RETURN 2017
END fin_year;
1
 
Coco BeansDesignerAuthor Commented:
Perfect - thank you
0
 
Martyn SpencerConsultantCommented:
You're welcome.
1
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.