Possible to get variable name?

Is it possible to get the name that you have used in your code of a variable?
ie.
procedure main_procedure
is
   l_var varchar2(10) := 'Hello';
begin
   dbms_output.put_line(get_var_name(l_var));
end;
function get_var_name(p_var in varchar2)
return varchar2
is
begin
   -- insert magic here
end;
-- End code; Now call the procedure
exec main_procedure;-- Needed output:
"variable passed had name l_var and value Hello"

Hi Sam,
OK, this is definitely for fun only and NOT recommended for any production database!!
With that out of the way, this has been adapted from Tom Kyte's who_called_me:
SQL> create or replace procedure get_var_name (
  2     p_var in varchar2
  3  )
  4  as
  5     call_stack   varchar2(4096) default dbms_utility.format_call_stack;
  6     n            number;
  7     found_stack  boolean default false;
  8     l_line       varchar2(255);
  9     cnt          number := 0;
10     l_owner      varchar2(255);
11     l_name       varchar2(255);
12     lineno       number;
13     caller_t     varchar2(255);
14     calling_line varchar2(4000);
15     var_name     varchar2(1000);
16  begin
17     loop
18        n := instr( call_stack, chr(10) );
19        exit when ( cnt = 3 or n is null or n = 0 );
20        l_line := substr( call_stack, 1, n-1 );
21        call_stack := substr( call_stack, n+1 );
22        if ( not found_stack ) then
23           if ( l_line like '%handle%number%name%' ) then
24              found_stack := true;
25           end if;
26        else
27           cnt := cnt + 1;
28           -- cnt = 1 is ME
29           -- cnt = 2 is MY Caller
30           -- cnt = 3 is Their Caller
31           if ( cnt = 2 ) then
32              lineno := to_number(substr( l_line, 13, 6 ));
33              l_line   := substr( l_line, 21 );
34              if ( l_line like 'pr%' ) then
35                 n := length( 'procedure ' );
36              elsif ( l_line like 'fun%' ) then
37                 n := length( 'function ' );
38              elsif ( l_line like 'package body%' ) then
39                 n := length( 'package body ' );
40              elsif ( l_line like 'pack%' ) then
41                 n := length( 'package ' );
42              elsif ( l_line like 'anonymous%' ) then
43                 n := length( 'anonymous block ' );
44              else
45                 n := null;
46              end if;
47              if ( n is not null ) then
48                 caller_t := ltrim(rtrim(upper(substr( l_line, 1, n-1 ))));
49              else
50                 caller_t := 'TRIGGER';
51              end if;
52 
53              l_line := substr( l_line, nvl(n,1) );
54              n := instr( l_line, '.' );
55              l_owner := ltrim(rtrim(substr( l_line, 1, n-1 )));
56              l_name  := ltrim(rtrim(substr( l_line, n+1 )));
57           end if;
58        end if;
59     end loop;
60     select text
61     into calling_line
62     from all_source
63     where line = lineno
64     and type = caller_t
65     and name = l_name
66     and owner = l_owner;
67     var_name := trim ( substr (
68        calling_line
69        , instr(calling_line, '(') + 1
70        , instr(calling_line, ')') - instr(calling_line, '(') - 1
71     ));
72     dbms_output.put_line('variable passed had name '||var_name||' and value '||p_var);
73  end;
74  /
Procedure created.
SQL> create or replace procedure main_procedure
  2  is
  3     l_var varchar2(10) := 'Hello';
  4  begin
  5     get_var_name(l_var);
  6  end;
  7  /
Procedure created.
SQL> exec main_procedure;
variable passed had name l_var and value Hello
PL/SQL procedure successfully completed.cheers,
Anthony

Similar Messages

  • How to get Variable name in output (Report Writer/Painter)

    Hello Experts,
    We have maintained one Repot by using Report Writer, this is the report for Cost center (periodic report), input fields are Fiscal year, Period and Cost Center. In out put system will display the selected cost center balances for individual cost element.
    Output: Excel format: in first sheet it will display balance of the total cost centers selected and from second sheet it will display individual cost center balances.
    My requirement is in the output system is displaying sheet name as CC1,CC2,CC3.......CC50, but my user want to display this as Cost Center 1, Cost Center 2, Cost Center 3...... like this. we have maintained variable name as Cost center 1, cost center 2....., but why system is displaying as CC1,CC2,.... .
    Please help me how to get the full description as sheet name in excel.
    Thanks ......Sudheer

    Hello Everybody,
    Please help me how to get variable name in Report Painter outout ( Excel format ).
    Thanks

  • Is it possible to get font names of the used vector graphics?

    Hi All,
    Is it possible to get the font names of the used vector graphics?

    Hello Learner,
    or you could try to read out the fonts from XMP metadata.
    1. Load XMP Library
    2. Read out XMP metadata from file
    e.g.
          var _numberOfFonts = _xmpData.countArrayItems(XMPConst.TYPE_PAGEDFILE,"xmpTPg:Fonts");
          if(_numberOfFonts) {
            for(i=1;i<=_numberOfFonts;i++) {
                _path = XMPUtils.composeArrayItemPath(XMPConst.TYPE_PAGEDFILE,"xmpTPg:Fonts",i);
                _fontFamily = _xmpData.getStructField(XMPConst.TYPE_PAGEDFILE,_path,XMPConst.TYPE_FONT,"fontFamily");
                _fontface = _xmpData.getStructField(XMPConst.TYPE_PAGEDFILE,_path,XMPConst.TYPE_FONT,"fontFace");
                _fontType = _xmpData.getStructField(XMPConst.TYPE_PAGEDFILE,_path,XMPConst.TYPE_FONT,"fontType");           
    Roland

  • Possible to get the name of the user filling in the pdf?

    is there a way to get the name (or user name or network name) of the user who is filling out the pdf?   We'd like to incorporate their initials in the file path for saving the document.

    Only if you install a script on the local machines of each of the users
    using the file.

  • Is it possible to get LS name from SLD when the scenario is executed

    can I create a scenario that gets the Technical system details of the Business system from SLD?
    Can I have a Soap - File scenario, in which case, once the request comes from Soap, corresponding Business system's Technical system details ( like LS name and client no ) should be taken from SLD and send as a file.
    Is this possible ??
    if yes, how?
    Regards,
    Venkat.

    Hi
    Technical system details - Not sure if that is directly possible..
    but an option would be to use a FixValue/ Valuemap function provide a Key & get the value
    to generate the Key, use a UDF, get RUNTIME constants to make a key
    check this link for constants http://help.sap.com/erp2005_ehp_04/helpdata/EN/b3/9a2aeb24dc4ab6b1855c99157529e4/frameset.htm
    e.g
    java.util.Map map;
    map = container.getTransformationParameters( );
    String const;
    Const = (String) map.get(StreamTransformationConstants.CONSTANT_NAMEfromlink);
    return const;
    if you want XI's information, then you can try this
    String sysSID = (String)System.getProperty("SAPSYSTEMNAME");
    OR
    String sysSID = (String)System.getProperty("user.name");
    Regards
    Vishnu

  • How to get the name of a field without specifying it as a string (somehow v

    Is it possible to get the name of a field (or method) somehow via the class in which it is declared?
    The reason why I ask is, that quite often the name of a field is important, because the name is the anchor for further processing, like for example when using reflection (e.g. Class.getfield(“NameOfTheField”)).
    Assume you have class FooSimple with the field “String firstName”.
    Now you would do something like this:
    Class<FooSimple> cls = FooSimple.class;
    Field f = cls.getField("firstName");
    The problem is, that the string “firstName” is kind of “hard coded”. When the name of the field in class FooSimple changes (e.g. to “theFirstName”), the invocation will not work anymore when you forget to change the string too.
    I think it would be very helpful to have access to the name of the field directly via the class by doing something like this.
    Class<FooSimple> cls = FooSimple.class;
    Field f = cls.getField(FooSimple.firstName.fieldName);
    The Java Compiler would then resolve “FooSimple.firstName.fieldName” to the string “firstName”. When later the name of the field is changed, the IDE would change the name everywhere where it is used. So if the name of the field would be changed to “theFirstName” the IDE would also change the statement to
    Class<FooSimple> cls = FooSimple.class;
    Field f = cls.getField(FooSimple.theFirstName.fieldName);
    A technique like this would be in my opinion much more safety and more generic.
    Any ideas?
    Best Regards.

    Well, I think the discussion is going in a wrong direction because the original issue was not to discuss if it is worth coding some helper classes or a framework or that like. Let me bring it back to my original point.
    Basically you can reduce my original question to this:
    Currently it is possible to use the reflection API on a class level without specifying the name of the class with a string constant.
    My issue is, that I think it would be a nice extension for Java, if the same would be possible for field variables of a Java class. Currently the only way you can do this is by specifying the field variable with a string constant.
    Let me bring some motivations which brought me to this issue.
    Assume you have an entity bean which represents a DB table and you use Java Persistence (either JPA or something like Hibernate). Then you would have a class looking like this (very simple sample to make this reply shorter).
    @Entity
    @Table(name = "PERSON")
    public class Person implements Serializable {
         @Column(name = "NAME")
         private String name;
    // … constructor, getter, setter, etc. not listed here
    }The whole issue of the design of JPA is, that such entity beans represent the mapping between the object model and the DB model, the mapping is expressed with annotations.
    Okay, now let’s assume you write a query in Query Language, e.g.
    String sql = “select p from Person p where name = :name”;“name” is the name of the field variable, “:name” is the parameter you later set with “Query.setParameter” method.
    What is not so nice is the fact, that you use the name of the class and the name of the field variables “hardcoded” to construct the query. Now you could think that basically this information is part of your entity class. First you start with the name of the class (i.e. the table name) to decouple this “hardcoding”.
    You could write instead:
    String sql = “select p from “ + Person.class.getSimpleName() + “ p where name = :name”;This is really nice, because whenever you change the name of your Person class, this change happens automatically for the sql statement as well.
    I think the next thoughts are obvious, now, since you have decoupled the “hardcoded” part of the name of the class, you would like to do the same for the names of the field variables. But now you are stuck, there is no way to do this using a similar technique like for the name of the class. Either you stay with the query as it is now, or, to make it a little bit better, you code string constants for the field variables and use them. This issue brought me to the point that I think it would be nice to have the possibility to get the name of a field variable in a similar way as you can get it for the name of the class.
    Conceptually it is just to go one level deeper, i.e.
    first level is to get the name of a class
    second level is to get the name of the field variable of a class.
    Another sample would be, if you want to code something by using reflection. You have perfectly access to the reflection API starting at the class level like Person.class.allTheNiceReflectionMethods. There is no need to specify the class first with a string constant first, you directly start with the class, you can even be generic and just work on the Class.class level and still have access to all these nice methods to get out the information you need.
    But if you need to start with a very specific field variable (like in the sample above), you must go by using a string constant like Person.class.getDeclaredField(“name”).
    So basically I think that there exist already millions of lines of Java code where a field variable is specified for further processing, especially in combination with the reflection functionality and everywhere the field variables are specified by these string constants in double quotes. I would assume, that everyone has the same problem, once changing the name of the field variable means to take care that also the content of the string which specifies the name of the field variable is changed.
    I am wondering why one of the replies commented, why the name of a field variable is changed, it sounds to me that this is something which basically never happens. I don’t know, I think that this happens actually quite often and thanks to all these nice IDEs and their “rename” feature this is usually no problem. From time to time names of classes change, name of field change, yes, they are often even completely rewritten, new field variables come in some are deleted, whatever it is. The way I currently can access the name of a class makes the code safer, because when I consequently go with Class.class.getSimpleName I always know, that when I rename the class all these statements are changed too If I delete such a class, I at least get a compile error.
    My very simple issues is, that I think it would be nice to have the same comfort not only on a class level but also on the level of field variables, nothing more, nothing less.
    To be honest, I have not browsed the forum yet if such an issue was already raised by other people (I will do this now), but somehow it is hard to imagine, that I am the first one.
    Best regards.

  • Get File name using File Adapter

    Does anyone know how to get the file name that has been picked up so it can be past to a variable so it can be used in the BPEL process.
    cheers
    James

    Hi James,
    Here the STEPS,
    Create File Adapter.
    Add File Adapter Service to Receive Activity.
    Click Receive Activity and goto Adapters Tab.
    Click "Tourch" to get variable names.
    Select Variable -> Process -> Variables and Click on "Create New Variable" icon and give name.
    Select "Message Type" and click "Tourch" icon.
    Now you select "Partner Links" -> FileAdapter WSDL -> Imported WSDL -> Message Type -> InboundHeader_msg and select OK.
    It's done.
    now you can use this Global Variable to get Filename and Directory name.
    Regards,
    Bhavesh Thaker.

  • Text Variable(Customer Exit) displays variable name instead of its value.

    Hi Gurus,
    My requirement is to display the year(from variable) as the field name i.e Year end salary 2009.
    I was using the fields name as hardcoded values like 2009 but as per my requirement i need to display it from the variable.
    I tried using Text Variable using customer exit, but I'm getting variable name(zvariable) instead of value(2009).
    Please help me out, many thanks in advance.
    Regards,
    Ankur

    Hi,
    Actually I tried to create a Text Variable with Replacement Path.
    But here the problem is that we have a Characteristic Variable (Customer Exit) which is not listing in the selection box of Replacement Path.
    Hence we tried to create another Text Variable (Customer Exit) and refering to the same Customer Exit code.
    Regards,
    Ankur

  • How to change dinamically variable name?

    Is it possible to change variable name dinamically into loop?
    loop at itab.
    move itab-item to field_x.
    endloop.
    I would copy my itab-item into field_1, field_2......field_x at each loop.
    Thanks
    Alfonso.

    You have to use the field symbol for the field giornoX not for the structure
    DATA: BEGIN OF wa_alv OCCURS 0,
            pernr            LIKE pa0001-pernr,
            persk            LIKE pa0001-persk,
            des_grado_abbrev LIKE zhr_descr_grado-des_grado_abbrev,
            vorna            LIKE pa0002-vorna,
            nachn            LIKE pa0002-nachn,
            giorno1          TYPE char12,
            giorno2          TYPE char12,
            giorno3          TYPE char12,
            giorno4          TYPE char12,
            giorno5          TYPE char12,
            giorno6          TYPE char12,
            giorno7          TYPE char12,
          END OF wa_alv.
    data tb_alv like table of wa_alv.
    field-symbols: <giorno> type any.
    data: name_giorno(13).
    LOOP AT tb_alv ASSIGNING wa_alv
      LOOP AT tb_orario.
       do 7 times.
        concatenate 'wa_alv-giorno'  sy-index into name_giorno.
         assign (name_giorno) to <giorno>.
         giorno  = tb_orario-orario.
        enddo.
        ENDLOOP.
    ENDLOOP.
    bye
    enzo

  • Get xml name

    Is it possible to get the name and path of a imported xml with javascript?
    Thanks!

    Since you are using the XQuery or XPath query you should know the exact path of the xml. Otherwise you can't utilize this new feature in SQL Server...
    There is no functions available in XQuery to fetch the XML Root element name, but you can utilize the Stringmanipulation to find what is your root..
    Code Snippet
    declare @x xml
    set @x =
     '<Chicago>
       <Area>A1</Area>
       <Group>5</Group>
       <Question>Q1</Question>
     </Chicago>'
    Select
       Substring(XML,Charindex('<', XML)+1, Charindex('>', XML) - Charindex('<', XML)-1)
    From
       Select
          Cast(@X as Varchar(max)) as XML
    ) as Data

  • Getting class names in jconsole

    Hello,
    Is it possible to get class names which are loaded in the memory using jconsole?
    I am using jdk 1.5. I have configured jmx in my Weblogic 9.2.
    I am able to find the memory usage by the application, but i dont know how to get those class names in jconsole.
    Regards,
    Sampath

    Hi,
    we ckeck all the class names in package.
    first goto se80.select package and give package name and click on display button.it will display all the structures,classes which are assigned to that particular package .in that select class it will expand and displays all the names.
    Cheers,
    vasavi.
    kindly reward if helpful.

  • Making generated variable names?

    Hey, I'm trying to make new Vector variables given some input I already have. I'm doing it as follows:
    for (int i=0; i < commandName.size()-1; i++) {
    String newVariableName = commandName.elementAt(i).toString();
    Vector newVariableName = new Vector();
    Of course, it's not working - but do you know if it is possible to generate variable names in this manner?

    Use HashMap.
    You will generally find that most languages that offer variable dereferencing are also essentially "typeless", although you can sometimes query what the type of the "value" of a variable is.
    HashMap does this exactly, with the bonus that you can double your namespace by creating two maps! :-)

  • Is it possible to get a variable if I only know the variable by it'

    Is it possible to get a variable if I only know the variable by it's string name?
    In my case I would like to call Resources.GetStringToDisplay("TEXT_0") and get the string "bla bla 0"
    public class Resources {
    public string GetStringToDisplay(String s)
    {          //how can I to return the value of one variable
    return ............;
    public static String TEXT_0="bla bla 0";
    public static String TEXT_1="bla bla 1";
    public static String TEXT_2="bla bla 2";
    public static String TEXT_3="bla bla 3";
    Thanks

    NO you can not get Variable value by camparing string value in J2ME (because J2ME is not supporting reflection package). But you can do one thing to get same functionality.
    public static String TEXT_0="TEXT_0@bla bla 0";
    public static String TEXT_1="TEXT_1@bla bla 1";
    public static String TEXT_2="TEXT_2@bla bla 2";
    public static String TEXT_3="TEXT_3@bla bla 3";
    public string GetStringToDisplay(String s)
    if(TEXT_0.startsWith(s) )
    return TEXT_0.substring (TEXT_0.indexOf('@')+1, TEXT_0.length());
    else if(TEXT_1.startsWith(s) )
    return TEXT_1.substring (TEXT_1.indexOf('@')+1, TEXT_1.length());

  • Is it possible to get the active directory user name of the person

    Is it possible to get the active directory user name of the person who is logged onto a windows computer, when they are using your coldfusion site, the same way asp pages can do that?

    SECOND TRY TO POST THIS REPLY
    You have to turn on "Windows Integrated Security" and turn off anonymous login in the IIS web server, once that condition is met the cgi.AUTH_USER variable will be popluated with the domain/username of the user logged into the cient computer.
    If the user is using a windows browser on a windows client computer this will be done silently in the background.  Otherwise they will normally be presented with a login dialog box by the browser.

  • Get hierarchy name in user-exit from variable

    Hi everybody
    I have a WebTemplate with different queris. The user can select the costcenter in the beginning. In a further query of the template I show all the orders regarding that costcenter. But with this concept I block all the orders with one user executing the template.
    So now I want to select the orders that belong to the selected costcenter in a user exit (with a variable). This works fine when the user selects a costcenter.
    But it is also possible that the user selects a higher node of the costcenter hierarchy. How can I get all the orders that are connected to a costcenter node?
    So far I thought that I have to get all costcenter nodes that have the selected node as a parent (etc..) in the hierarchy table. But how do I find out which hierarchy is used by the query? I get the Variable name loc_var_range-vnam. And I know which table the hierarchy is in. But how do I find the correct HIEID?
    or does anybody have a better suggestion to solve my problem?
    Thanks in advance.
    Christophe

    Hi Christophe,
    I've written a code for finding the name of hierarchy using the node.
    It's little bit big code, if send ur email id i can pass it to you.
    hope that helps you.
    regards
    rajesh

Maybe you are looking for

  • Unable to find a data source in RSA5 which can be seen in RSA3.

    Hi there, I am unable to find the business content data sources in RSA5, but I can find the same data sources in RSA3 (extract checker). I need these data sources to be replicated to BW and take it up further. Any light on the above issue will be of

  • Table for delivery block status

    Hi, Which table can I find the status of the delivery that is block due to legal control ? (e.g. license not found). I cannot find it in VBUP nor JEST. We want to make a report to show what deliveries are block due to legal control. Thanks!

  • Only one display resolution option for monitor

    I just installed a new SSD in my computer, and then installed SL onto the drive. I have an Asus monitor, and Display Preferences on the SL install on the older HD gave me a variety of screen resolutions to choose from. But on the SSD install I only h

  • Webfont not displaying properly in design mode or appearing in font list

    Just updated Muse and now my heading webfont (Nunito) is not displaying properly in design mode or appearing in the font list. It is, however, displaying properly in preview mode. When I try and delete the font and then add it again I get an error me

  • The date and time?

    My brother likes to turn his HP laptop off when not in use, tried everything to get online, and was showing "IE could not display this page", and The certificates you need are out dated. Called M 800 line, no help, they said they would call back, thr