PL/SQL Local Variable in Javascript

I want to pass a PL/SQL local variable called F_NAME into the Javascript.
The first question is, how do you display it inside of the Javascript?
The second question is, how do you assign F_NAME to the field on the form?
Please see the codes below. Please help, thank -Patty
==================================================================================
declare
f_name varchar2(15);
begin
select emp_first_name
into f_name
from emp_profile
where e_mail_id = portal30.wwctx_api.get_user;
htp.p('<script language="Javascript1.3">
//==============================
//This is the first question
alert('||f_name||');
//==============================
var fname = new String("CDRH_TR_INSERT_MORE_RECORDS.MASTER_BLOCK.EMP_FIRST_NAME.01");
//=========================================================================
//This is the second question
document.forms[0].elements[eval(fname)].value = "'||f_name||'";
//==========================================================================
</script>');
END;

Just like how you did it with the <script language="Javascript1.3"> . You use htp.p().
So for example, htp.p('alert(''||f_name||'');
OR
htp.p('var fname = new String(''CDRH_TR_INSERT_MORE_RECORDS.MASTER_BLOCK.EMP_FIRST_NAME.01'');');

Similar Messages

  • How to declare local variables in PL/SQL stored programs

    Where do I declare local variables in a PL/SQL stored program?
    I get compiler errors with either of the options below:
    FUNCTION GET_PRINCIPAL_BALANCE (CUT_OFF_DATE IN DATE, TITLE_SN IN DATE, TOTAL_BALANCE OUT NUMBER) RETURN NUMBER IS
    TOTAL_BALANCE NUMBER;
    BEGIN
    RETURN TOTAL_BALANCE;
    END;
    FUNCTION GET_PRINCIPAL_BALANCE (CUT_OFF_DATE IN DATE, TITLE_SN IN DATE, TOTAL_BALANCE OUT NUMBER) RETURN NUMBER IS
    BEGIN
    TOTAL_BALANCE NUMBER;
    RETURN TOTAL_BALANCE;
    END;

    Your local variable cannot have the same name as the formal out parameter. This is a procedure example, but since functions should not have out parameters anyway ...
    session2> CREATE PROCEDURE p (p_id IN NUMBER, p_did OUT NUMBER) AS
      2     p_did NUMBER;
      3  BEGIN
      4     p_did := p_id * 2;
      5  END;
      6  /
    Warning: Procedure created with compilation errors.
    session2> show error
    Errors for PROCEDURE P:
    LINE/COL ERROR
    0/0      PL/SQL: Compilation unit analysis terminated
    1/1      PLS-00410: duplicate fields in RECORD,TABLE or argument list are
             not permittedThe proper way to create a function would be something like:
    CREATE FUNCTION f (p_id IN NUMBER) RETURN NUMBER AS
       l_did NUMBER;
    BEGIN
      l_did := p_id * 2;
      RETURN l_did;
    END;You should really assign a value to the variable before you return it.
    John

  • How to bind local variables in complex query in PL/SQL

    Hi
    I have long complex query with local varibales; when I run in Dynamic SQL I get an error. Not sure which is the easiest way to bind local variables.
    L_QUERY := q'[select m.segment1 col1,
          '1' col2,
          '13' col3,
          l.operand col4,
          0 col5,
           'Y' col8,
          'N' col9,
          'N' col10,
       decode(h.name,'09_UKOR_*','EOS Credit','10_UKOR_*','TopUp','11_UKOR_*','Main') col18
    from qp_list_headers_v h,
          qp_list_lines_v l,
          mtl_system_items m
    where h.name in ('09_UKOR_*','10_UKOR_*','11_UKOR_*')
    and h.list_header_id = l.list_header_id
    and m.inventory_item_id = l.product_attr_value
    and m.organization_id  = 84
    UNION all
    SELECT qs.PRODUCT_ATTR_VALUE col1,
           hca.account_number col2,
           decode (su.site_use_code,'BILL_TO','21','SHIP_TO','18') col3,
           0 col4,
           qs.operand col5,
           null col6,
           null col7,
           'N' col8,
           'Y' col9,
           'N' col10,     
    --Local variables
          (case when (trunc(nvl(qq.start_date_active,sysdate)) between l_cur_year_from  and l_cur_year_to) and  
                      ( trunc(nvl(qq.end_date_active,l_cur_year_to)) >= trunc(l_cur_year_to) )  then    'TopUp'
                when (trunc(qq.start_date_active) between l_next_year_from  and l_next_year_to) and  
                      ( trunc(nvl(qq.end_date_active,l_next_year_to)) >= l_next_year_to)  then   'Main'              
                when (trunc(qq.start_date_active) between l_last_year_from  and l_last_year_to) and  
                      ( trunc(nvl(qq.end_date_active,l_last_year_to)) >= l_last_year_to )  then  'EOS Return'
           end )col18,
    --Local variables
           (case   when (trunc(qq.start_date_active) between l_next_year_from  and l_next_year_to) and  
                      ( trunc(nvl(qq.end_date_active,l_next_year_to)) >= l_cur_year_to )  then   'N'
              else
                    'Y'  end ) col21
       FROM qp.qp_list_headers_b qlhb,
            qp.qp_list_headers_tl qlht,
            qp.qp_qualifiers qq,
            qp_modifier_summary_v qs,
            hz_cust_site_uses_all su,
            hz_cust_acct_sites_all  sa,
            hz_cust_accounts hca
    WHERE 1=1
          and qlhb.LIST_TYPE_CODE       = 'DLT'
          and nvl(qlhb.active_flag,'Y') = 'Y'
          and qlhb.list_header_id       = qlht.list_header_id
          AND qq.list_header_id         = qlhb.list_header_id
          and qq.list_type_code         = qlhb.LIST_TYPE_CODE
          and qq.QUALIFIER_CONTEXT      = 'CUSTOMER'
          and qs.list_header_id         = qlhb.list_header_id
          and qs.LIST_LINE_TYPE_CODE    = 'DIS'
          and su.site_use_id            = qq.qualifier_attr_value --1064
          AND  su.cust_acct_site_id     = sa.cust_acct_site_id
          AND  sa.cust_account_id       = hca.cust_account_id ]';
    --call Dynamic SQL function
    l_cursor := DBMS_SQL.OPEN_CURSOR;
    DBMS_SQL.PARSE(l_cursor, p_QUERY , DBMS_SQL.NATIVE);
    l_rows := DBMS_SQL.EXECUTE(l_cursor);
    Any help will be much appreciated.
    iI guess I should use DBMS_SQL.BIND_VARIABLE to bind all variables seperately so not to mess with query

    1) What is the error you get?
    2) If you use bind variables inside a query, you should prefix them with colons, so use :l_cur_year_from etc.
    3) Why are you using dbms_sql instead of native dynamic sql and/or ref-cursors?
    Toon

  • SQL environment variable into a local variable in stored procedure ?

    How do i set a SQL environment variable in a session ? How can i read an SQL environment variable into a local variable declared in my stored procedure ? Does any exceptions occur in the process ?
    I need this very urgently, can anyone help ?
    thanks
    srini

    You can use a pipelined table function to return it, which is covered here:
    http://blog.mclaughlinsoftware.com/plsql-programming/pipelined-functions-plsql-tables/
    Alternatively, you can use a SQL Object type wrapped by a collection of that SQL object type inside a TABLE call. I've blogged on that too, here:
    http://blog.mclaughlinsoftware.com/2009/03/23/object-record-collections/
    If you need something more, leave a comment on the blog. I'm not here on the forum too frequently. Hope that helped.

  • Log the local variables (string type) to the database (SQL Server)

    i have a customized PreUUT callback so that my own VI gets the information from barcode. it contains serial number as well as other information. i am collecting the information into local variables of the PreUUT callback.
    Now i want to log the local variables (string type) to the database (SQL Server).
    i have a successful connection to the database and i am using a generic recordset schema.
    can anyone help me how to do it?
    also shall i have to create the corrosponding fields (columns) in the database? or is there any option in TestStand4.0 to do it?

    Hello i like original,
    After re-reading your original message, I think I might have a better understanding of what you would like to do.  I have included a few links to Knowledge Base and Developer Zone articles that should be very useful for you.  I have included these links below:
    Logging a New UUT Property to a Database in TestStand
    Logging a New Step Property to a Database in TestStand
    Creating a TestStand Database Schema from Scratch
    Thanks,
    Jonathan C
    Staff Application Engineering Specialist | CTD | CLA
    National Instruments

  • In this way you can access pl/sql variables in javascript

    Because nobody seems to know the answer (because of no reply) to my post a few days ago and in the meanwhile I found it out myself, I will give the solution:
    Create or Replace PROCEDURE KOEN.PROC_GET_FIELD
    (OBJ_NAME IN VARCHAR2, OBJ_VALUE OUT VARCHAR2)
    pl/sql procedure (with embedded javascript) to get the value of a form field by passing the name of that field (in the same way you can write such a procedure to set the value of a form field by passing the field's name and value
    as
    v_obj_name VARCHAR2(255);
    begin
    v_obj_name := '.' || OBJ_NAME || '.';
    htp.htmlOpen; htp.headOpen;
    htp.p('<script language = "JavaScript1.2">');
    htp.p('for (i=0; i < document.forms[0].length; i++)');
    htp.p('{');
    htp.p('var v_name = document.forms[0].elements.name');
    htp.p('if (v_name.indexOf("' || v_obj_name || '") != -1)');
    htp.p('OBJ_VALUE = document.forms[0].elements[i].value;');
    htp.p('}');
    htp.p('</script>');
    htp.headClose; htp.htmlClose;
    exception
    when others then
    null;
    end;
    regards,
    Koen

    i have written a getField to get the value of a form field procedure but how can I write a setField procedure??
    Create or Replace PROCEDURE KOEN.PROC_SET_FIELD
    (OBJ_NAME IN VARCHAR2, OBJ_VALUE IN VARCHAR2)
    pl/sql procedure Koen V. (with embedded javascript) to get the value of a form field by passing the name of that field (in the same way you can write such a procedure to set the value of a form field by passing the field's name and value
    as
    v_obj_name VARCHAR2(255);
    begin
    v_obj_name := '.' || OBJ_NAME || '.';
    htp.htmlOpen; htp.headOpen;
    htp.p('<script language = "JavaScript1.2">');
    htp.p('for (i=0; i < document.forms[0].length; i++)');
    htp.p('{');
    htp.p('var v_name = document.forms[0].elements.name');
    htp.p('if (v_name.indexOf("' || v_obj_name || '") != -1)');
    htp.p('document.forms[0].elements[i].value = "' || OBJ_VALUE || '";');
    htp.p('}');
    htp.p('</script>');
    htp.headClose; htp.htmlClose;
    exception
    when others then
    null;
    end;
    greets,
    Koen

  • How to create a local variable in bpel?

    Hi,
    In my bpel flow I need to call service based upon a pl/sql procedure multiple times. The procedure returns the results of a query in chunks and contains a boolean as an output parameter that tells me whether there are any more records that need to be fetched based upon which I will be calling the service again. I want to achieve this using a while loop. So for the while loop condition I am thinking of creating a local variable in the bpel process and assign it an initial value of false(). Then once the service is called I will set the value of this variable to the output boolean parameter returned by the procedure. So while the boolean is true the service will be called again.
    My question is how can I create a local variable in bpel and assign it an initial value of false. Or is there any other way that this can be achieved?
    Thanks!!

    Hello! thanks for yr response.
    I tried creating a new variable by defining a scope. But in the create variable window I cannot define a standalone variable of boolean type I need to pick up the type from an lov that brings up a list of all existing variable! so basically u are just mapping to an existing variable which in my case will not work because I will need to map to one of the elements of the output of the pl/sql procedure based service -- also this element itself is not exposed in the lov only the name "inputParameters" is displayed as the element --all the contents are not exposed.
    Any suggestions?
    Thanks!

  • How do i declare a user defined table type sproc parameter as a local variable?

    I have a procedure that uses a user defined table type.
    I am trying to redeclare the @accountList parameter into a local variable but it's not working and says that i must declare the scalar variable @accountList.this is the line that is having the issue: must declare the scalar variable @accountListSET @local_accountList = @accountListALTER PROCEDURE [dbo].[sp_DynamicNumberVisits] @accountList AS integer_list_tbltype READONLY
    ,@startDate NVARCHAR(50)
    ,@endDate NVARCHAR(50)
    AS
    BEGIN
    DECLARE @local_accountList AS integer_list_tbltype
    DECLARE @local_startDate AS NVARCHAR(50)
    DECLARE @local_endDate AS NVARCHAR(50)
    SET @local_accountList = @accountList
    SET @local_startDate = @startDate
    SET @local_endDate = @endDate
    CREATE TYPE [dbo].[integer_list_tbltype] AS TABLE(
    [n] [int] NOT NULL,
    PRIMARY KEY CLUSTERED
    [n] ASC
    )WITH (IGNORE_DUP_KEY = OFF)
    GO

    Why are you asking how to be an awful SQL programmer??  Your whole approach to SQL is wrong.
    We have a DATE data type so your insanely long NVARCHAR(50) of Chinese Unicode strings is absurd. Perhaps you can post your careful research on this? Can you post one example of a fifty character date in any language? 
    The use of the "sp_" prefix has special meaning in T-SQL dialect. Good SQL programmers do not use CREATE TYPE for anything. It is dialect and useless. It is how OO programmers fake it in SQL. 
    The design flaw of using a "tbl-" prefix on town names is called "tibbling" and we laugh at it. 
    There are no lists in RDBMS; all values are shown as scalar values. First Normal Form (1NF)? This looks like a set, which would have a name. 
    In any -- repeat any -- declarative programming language, we do not use local variables. You have done nothing right at any level. You need more help than forum kludges. 
    --CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
    in Sets / Trees and Hierarchies in SQL

  • Can OSD handle MSSQL local variables?

    DECLARE @ERR_MSG VARCHAR(255);
    SET @ERR_MSG = '(FOC1406) SQL OPEN CURSOR ERROR.';
    SELECT *
    FROM Rcaster05dev.Dbo.Botlog2
    WHERE STAT_BT_NAME = 'J170547s5tlu'
    AND MESSAGE like @ERR_MSG
    Yields:
    SELECT *
    FROM Rcaster05dev.Dbo.Botlog2
    WHERE STAT_BT_NAME = 'J170547s5tlu'
    AND MESSAGE = @ERR_MSG
    Error report:
    Invalid JDBC escape syntax at line position 23 '=' character expected.
    This seems like the OSD interface is getting tripped up by some of the code it's trying to pass through? Or does OSD not support local variables in MSSQL?

    Hello,
    I believe that SQL Developer is not faulty here. The error message seems to come from JTDS.
    As a quick test, can you write a very little Java program and send the same query to your SQL Server database, using the same JTDS version that you are using in SQL Developer? If that returns with the same error message then sourceforge.net should be your next address.
    Regards
    Wolfgang

  • Is This a Global Versus Local Variable Problem?

    I intend to use a variable (myselector) with a text value (e.g. roses, Big Sur, Pacific Grove, night, etc.) for the sort criteria of my photography list.  Selection of a tab from a Tabbed Panel will appropriately define the variable and the selected thumbnails will display in the Content Panel.
    The variable "myselector" is defined in the head section; a function for each tab of the Tabbed Panel will redefine the variable per the selected tab.  Within the function, I am not using "var" to call the variable.  Though the variable "myselector" should be global, the changes to its value are discarded when the function closes.  This indicates that it is functioning like a local variable in the function.  After a bit of reading, I've not found the cause of the global/local discrepancy or a fix for it.
    Diagnosis History - I generated a simplified code.  Variable "myselector" is defined as "abcd"; function "myfilter" is called by onclick of the text "button" and changes "myselector" to "efgh".  At the end of the file, I used "document.write (myselector) to output the "myselector" value.  The script follows.
    The end value of "myselector" does not change.  However, when I add "document.write (myselector)" to the function, then the changed value is displayed.
    I ask someone to explain what I am doing incorrectly or, at least, guide me to a solution.  I thank you for your assistance.
    Scott
    <script type="text/javascript">
    var myselector="abcd";
    function MM_callJS(jsStr) { //v2.0
      return eval(jsStr)
    </script>
    </head>
    <body>
    <div id=text>
    <p onclick="MM_callJS('myfilter();')">Button</p>
    <script type="text/javascript">
    function myfilter() {myselector="efgh"; }
    </script>
    <script type="text/javascript">
    document.write (myselector);
    </script>
    </div>

    Dear Ben:
    I thank youfor your patience.  This includes the script using Insert - Syntax Highlighting - Java.
    The coding needs a lot of clean up but I want it to work, first.
    Scott
    <script src="SpryAssets/xpath.js" type="text/javascript"></script>
    <script src="SpryAssets/SpryData.js" type="text/javascript"></script>
    <script src="SpryAssets/SpryTabbedPanels.js" type="text/javascript"></script>
    <script type="text/javascript">
    var dsphotodata = new Spry.Data.XMLDataSet("EM_photo.xml", "/gallery");
    </script>
    <script  type = "text/javascript">
    function MM_callJS(jsStr) { //v2.0
      return eval(jsStr)
    </script>
    <script type="text/javascript">
    var dsphoto = new Spry.Data.XMLDataSet("EM_photo.xml", "/gallery/photos/photo");
    dsphoto.filter(subjectfilter);
    var myselector;
    </script>
    <link href="SpryAssets/SpryTabbedPanels.css" rel="stylesheet" type="text/css" />
    </head>
    <body>
    This is a test of Scott's efforts to program his website.
    <br />
    <br />
    <div id="TabbedPanels1" class="TabbedPanels">
      <ul class="TabbedPanelsTabGroup">
        <li class="TabbedPanelsTab" tabindex="0" onclick="MM_callJS('{myselector=\'animal\'}; subjectfilter(); dsphoto.filter(subjectfilter); ')">Tab 1</li>
        <li class="TabbedPanelsTab" tabindex="0" onfocus="MM_callJS('myselector=\&quot;pgbeach\&quot; subjectfilter(); dsphoto.filter(subjectfilter); ')">Tab 2</li>
        <li class="TabbedPanelsTab" tabindex="0">Blank</li>
    </ul>
      <div class="TabbedPanelsContentGroup">
        <div class="TabbedPanelsContent" >Content 1
          <br />
    <br />
    <script> {document.write (myselector)} </script>
          <br />
          <div spry:region="dsphoto dsphotodata"> <img src="{dsphotodata::thumbnail/@base}{@thumbpath}" width = {@thumbwidth}px height = {@thumbheight}px spry:repeat="dsphoto" onclick="dsphoto.setCurrentRow('{ds_RowID}');" /></div>
        </div>
        <div class="TabbedPanelsContent">Content 2
          <script> {document.write (myselector)} </script>
          <br />
          <div spry:region="dsphoto dsphotodata"> <img src="{dsphotodata::thumbnail/@base}{@thumbpath}" width = {@thumbwidth}px height = {@thumbheight}px spry:repeat="dsphoto" onclick="dsphoto.setCurrentRow('{ds_RowID}');" /></div>
        </div>
        <div class="TabbedPanelsContent">Content 3  <script> {document.write (myselector)} </script><br />
    <div spry:region="dsphoto dsphotodata"> <img src="{dsphotodata::thumbnail/@base}{@thumbpath}" width = {@thumbwidth}px height = {@thumbheight}px spry:repeat="dsphoto" onclick="dsphoto.setCurrentRow('{ds_RowID}');" /></div>
    </div>
    </div>
    </div>
    <div id="Selected_Photo" spry:detailregion = "dsphoto dsphotodata"  >
    <img src="Photo-Thumbnails/{@thumbpath}" width = {@thumbwidth}px height = {@thumbheight}px /><br />
    <img src="Photo-Email/{@path}" width = {@width}px height = {@height}px />
    </div>
    <script type="text/javascript">
    var subjectfilter = function(dataSet, row, rowNumber, criteria) { if (row["@subject"].search (myselector) != -1) return row; return null; };
    <!--
    var TabbedPanels1 = new Spry.Widget.TabbedPanels("TabbedPanels1", {defaultTab:2});
    //-->
    </script>

  • PL/SQL dynamic variable

    hi
    i have a problem what i am trying to do use to reference a variable in my PL/SQL procedure
    and the name of the variable comes from a table:
    EXECUTE IMMEDIATE 'SELECT ' || deskbank_ref_rows(row_index).JUSTI FICATION || '(' || deskbank_ref_rows(row_index).FIELD VALUE ||
    ',' || deskbank_ref_rows(row_index).FIELD SIZE || ',' || deskbank_ref_rows(row_index).PADDI NGCHAR || ')' || ' FROM DUAL'
    INTO v_result_set;
    deskbank_ref_rows(row_index).FIELD VALUE contains the variable name from a table
    i want the string literal returned by deskbank_ref_rows(row_index).FIELD VALUE to reference the variable with the same name as the string literal in my procedure
    is this possible?

    Nope, determining a variable name at run-time and then accessing that variable is in my opinion not possible.
    What I meant was, may be you can use an associative array in stead of using local variables. Thus, instead of having something like this:
    declare
       string_var1 varchar2 := 'text1';
       string_var2 varchar2 := 'text2';
    begin
    endYou could perhaps use an associative array like this:
    declare
       type StrTabType is table of varchar2(255) index by varchar2(30);
       strTab StrTabType;
    begin
       strTab('string_var1') := 'text1';
       strTab('string_var2') := 'text2';
       select ..., strTab(deskbank_ref_rows(row_index).FIELDVALUE), ...
       from dual
    end;

  • Error in local variable

    1 am writing this query in oracle 11g in which i have declared a local variable v_SETRESULT which will
    store maximum +1 value of VISIT_ID which is my column in table VISIT and this column
    data type is integer
    my query
    declare
    v_SETRESULT NUMBER;-----------this is declaration of local variable
    begin
    SELECT Coalesce(Max(VISIT_ID), 0)+1
    INTO v_SETRESULT
    FROM Visit--------this is my name of table;
    dbms_output.put_line(v_SETRESULT);
    end;
    when i run this gives me this error
    anonymous block completed
    what does it mean

    yes iam doing this SQL Developer iam new to oracle 11g but i have previously worked in SQL Server 2005
    and if you run this query in SQL Server 2005 i get my result printed
    my query of SQL Server 2005
    Declare @v_SETRESULT as int
    begin
    SELECT @v_SETRESULT=Coalesce(Max(VISIT_ID), 0)+1
    FROM Visit;
    --dbms_output.put_line(v_SETRESULT);
    print @v_SETRESULT
    end;
    but when i run that above query which i posted previously this gives me this message
    rather than printing the result
    anonymous block completed
    then how to see my result printed

  • What is difference between local variable and property node ?

    What is difference between local variable and property node ?
    " 一天到晚游泳的鱼"
    [email protected]
    我的个人网站:LabVIEW——北方客栈 http://www.labview365.com
    欢迎加入《LabVIEW编程思想》组——http://decibel.ni.com/content/groups/thinking-in-labview

    To make things clear, here are two small examples that show how nasty locals and value properties can be to the naive programmer.
    - Open the diagram of the race condition.vi before running it and try to predict what will be the values of the two counters after the third run.
    - Use the Compare Locals Properties and Wires.vi to find out how slow locals and value properties can be (times 1000+).
    This being demonstrated, I must add that I use globals and value properties quite often, because they are often very convenient
    Chilly Charly    (aka CC)
             E-List Master - Kudos glutton - Press the yellow button on the left...        
    Attachments:
    Race condition.vi ‏9 KB
    Compare Locals Properties and Wires.vi ‏18 KB

  • How to use local variable in member formula?

    Hi Expert,
    We would like to use a {local variable} in a member formula, so that it can pick up the prompt from webform upon save. Would like to know if it is possible to do? If so, what is the correct syntax?
    We attempted to use brace {scenario}, blacket [scenario], blacket with quote ["scenario"]. None of these work.
    We are using 11.1.2.1 version, EPMA, Hyperion Planning.
    Thanks in advance for your help!

    One other pointer. Where did you define your variable? Hopefully you went into Calc Manager and selected <Tools>, <Variables>. From there, navigate to your application or database. Right-click on your application or database and select "New". In the bottom panel, you'll need to select your Variable Type. Make sure you select "Member", and not "Members". You cannot pass "Members" (plural) to a web input form. Also, if you want to define a variable for a custom dimension, you'll need to do it at the database level. Standard dimension member variables can be defined at the app level. (Not sure why this is the case, especially when my custom dimension exists in all plan types . . . . )
    Anyway, hope this helps,
    - Jake

  • Default initialisation of member variables and local variables

    I don't understand why member variables are initialized with default values by Java.
    Objects are initialized with "null" and primitives with "0", except boolean, which is initialized with "false".
    If these variables are used locally they are not initialized. The compiler requires them to be initialized by the programer, for example "String s = null".
    Why? What is the use of that difference?
    And why are arrays always initialized with default values, no matter if they are member variables or local variables? For example String[] s = new String[10]; s[0] to s[9] are initialized with "null", no matter if "s" is a local or member variable.
    Can someone please explain that strange difference, why it is used? To me it has no sense.

    Most of the time I have to initialize a local variable
    with "String s = null" in order to use it because
    otherwise the compile would complain. This is a cheap
    little trick, but I think everyone uses it.
    I wouldn't agree with "most of the time". The only cases where it is almost necessary to do that is when the variable should be initialized in a loop or a try-catch statement, and that doesn't happen too often.
    If local variables were initiliazed automatically without a warning it would be a Bad Thing: the compiler could tell when there is a possibility that a variable hasn't been assigned to and prevent manymanymany NullPointerExceptions on run time.
    And you didn't answer me why this principle is not
    used with arrays if it is so useful as you think.
    Possibly it is much more difficult to analyse the situation in the case of arrays; what if values are assigned to the elements in an order that depends on run time properties such as values returned from a random number generator.
    The more special rules one has to remember, the more
    likely one makes errors.I agree, but what is the rule to remember in this case?

Maybe you are looking for

  • Vertical text alignment in iPhoto calendar is jacked

    I am creating a calendar in iPhoto '11 (9.4.2) and have added many events (birthdays, anniversaries, etc.) on individual dates. On several of these events I am unable to set the vertical alignment to the bottom of the box. I can edit the text for a c

  • Convert data in the text file to table in DBL

    Hi guys I wanted to convert data in text file which are in multiple rows and columns in DBL format to a table to b seen in labview as DBL format. I had tried looking and working at the example but in vain , i just cant produce anything pls help. or w

  • How to integrate Java SSO with Oracle Weblogic

    Hi, I am new to Oracle weblogic, but i want to do something like below. I want to use Oracle weblogic as application server and want to integrate Java SSO into it. I think we can do it using Oracle access manager but since OAM itself is massive drop

  • Problem with NotificationService

    I am using BPEL 10.1.2.0.0 (fresh install) and created a simple User Task to test out email notification. This bpel instance uses LDAP / OID for authentication, and I have modified the ns_emails.xml to add the correct EmailAccount information for Out

  • WM : Manual Transfer Order

    Hi Gurus, Can any one explain me the process of generating Transfer Requirement when goods receipt is done using MB31 transaction and mvoement type 101 with reference to order? When we create Transfer Order for that Transfer Requirement, system picks