Skip to main content

To V or not to V...

Earlier today, I tweeted the following:
After this morning, I don't think I will 
ever use the "v" function again. #orclapex
I wanted to qualify what I meant by that, since sometimes you only see one side of the conversation on Twitter. Also, it's been a while since my last post, so this give me the opportunity to remedy that as well. The APEX "v" function works, and works quite well. For those who have not used it, the "v" function is an APEX-specific function that when you pass an APEX item to it, it will return the value of that item for a specific user session. What's cool about it is that it also works from named PL/SQL program units, as long as they were initiated from an APEX session. Thus, you can write a PL/SQL package that takes in few, if any parameters and still can refer to items that are set in the APEX session state via the "v" function:
PROCEDURE foo
IS
  l_customer_name   VARCHAR2(255) := v('P1_CUSTOMER_NAME');
BEGIN
...
END;
/
The specific issue that I had was that I did used the "v" function in quite a few places across a suite of PL/SQL packages. It cut down on what I needed to pass from package to package, and even allowed me to omit some procedures from the package specification. It worked magnificently. That is, until I tried to call one of the packages from SQL*Plus. Since there is no APEX session context set in SQL*Plus - and even if there was, which you can do, the items that I required to be set would not be - my package failed spectacularly. Thus, I had to go back through several packages and retro-fit them to be APEX-agnostic and remove all traces of the "v" function in favor of parameters. The lesson to learn from this is simple: take some time to consider whether or not you think a block of code will ever be called from outside of APEX. Even if there is a remote chance that it will, it may pay off big time later if you choose to make that code APEX-agnostic and rely on parameters instead.

Comments

dmcghan said…
Hi Scott,

There's another really good reason to use parameters over the v function. If you change the name of an item in the application, the v function will reference the wrong item name until the offending code is found and updated. But how do you find the code that needs to be fixed?

Using parameter passing from APEX to a package leaves little "artifacts" in your application and the APEX Advisor can pick up on these artifacts and tell you to fix them.

Regards,
Dan
Scott said…
Very true - there's lot of reasons for parameters vs. the "v" function. But you have to admit that the "v" function is the quickest & easiest way to do things - as limiting in the long term as it may be...

- Scott -
Ronald Hollak said…
Hi Scott,

Another place where I had to use the V function in a stored procedure was in my generic errorhandler.
You want your errorhandling functions to have some application-context, so what I did was wrapping the V (and NV) function:

create function apex_V(p_item_name in varchar2)
return varchar2
is
e_no_apex exception;
pragma exception_init (e_no_apex, -904);
l_return varchar2(255); begin
execute immediate 'select v(:P_ITEM_NAME) from dual' into l_return using p_item_name;
return l_return;
exception
when e_no_apex then
return null;
end apex_V;

In this case I return null when not in Apex, but you get the idea.

Gr.
Ronald
Shahana said…
Here in your example what is V function doing?

Popular posts from this blog

Whose Deck is it Anyways?

This year at KScope, we're going to try something new.  And fun.  And funny to watch - we hope.  It's called "Whose Deck is it Anyways?", and will occur on Sunday at 8:30pm.  It's only 30 minutes, but it will likely be the best 30 minutes of the conference.  Or at least the most embarrassing.

Here's what we're going to do: the will be four 5-minute presentations - one on each of the following: BI, EPM, Database & APEX.

Sound interesting?  Probably not.  We get that, too.  So here's what we did.

Each 5-minute session will be presented by a non-expert.  For example, it's highly likely that I'll be presenting on BI or EPM.

To make it even better, each slide deck will be prepared by the corresponding expert.  So again, it's highly likely that my slide deck's creator will be either Stewart Bryson or Edward Roske.  If nothing else, this session will be a crash course in how not to make cohesive, easy to read slides.

Interested now?  Ya,…

Spaced Out

A while back, I wrote about how to give the Universal Theme a face lift.  If you follow the steps in that post, the base font for an APEX application with the Universal Theme can easily be changed.

While that's all well and good, sometimes you only want to change the font for a report, not the entire page.  One of the applications that I'm building contains a number of IRs based mostly on log data.  Thus, having that data in a monospaced font would make it a whole lot easier to read.

You can search Google Fonts for monospaced fonts by selecting only that option on the right-side menubar.  You can also opt for the standard yet kinda boring Courier and achieve the same thing.

To implement this in your application, follow the steps in my other post, but stop shy of the final step.  Instead of pasting in the text that I specify, paste in the following to the Custom CSS field in Theme Roller, using the name of the font you selected for the font-family:

.a-IRR-table tr td { font-fam…

#fakecode

Unless you've managed to somehow filter out everything about US politics over the last few months (and if you have, please let me know your secret), then you've likely heard about "fake news".  From a high level, my basic understanding of "fake news" is that it refers to stories or websites that are fabricated to advance the political beliefs and/or ideologies of one site or the other.  Your definition may differ.

So what is fake code?  That, I can at least try to explain in a bit more detail.

The other day, I saw this image posted on Kris Rice's twitter feed:



I thought it was a joke, but it's actually a real book. That made me laugh.  Then cry.  Then I read the book, mainly since it's only 4 pages.  Believe it or not,  there's actually some really good content packed in there.  Let me summarize:

If you choose to copy code from Stack Overflow, the OTN forum, or anywhere, really, there's a few things to keep in mind:


Who owns the code.  It…