Assigning value to a variable.

i have one doubt.
we can assign value to a variable either in declaration section or in exectuion section.
so please explain when and wherer should we assign value to a variable.
thank you very much.

I think the best way to look at it is...
If you don't want your variable(s) to have default values that are NULL, assign a value in the declaration section, otherwise assign it where you feel like.
If you take an example of:
declare
  v_sum number := 0; -- default variable to 0
  cursor cur_test is
begin
  for i in cur_test
  loop
    v_sum := 0; -- set variable to 0 before the loop
    loop
      exit when .. some condition ..
      v_sum := v_sum + ..
    end loop;
  end loop;
end;
/.. we have a need to set the variable v_sum to 0 before each iteration of the internal loop, so there's little point in having it defaulted to 0 in the declaration section, hence I wouldn't typically default it there and would typically have the code as..
declare
  v_sum number; -- no point in defaulting it
  cursor cur_test is
begin
  for i in cur_test
  loop
    v_sum := 0; -- set variable to 0 before the loop
    loop
      exit when .. some condition ..
      v_sum := v_sum + ..
    end loop;
  end loop;
end;
/It all depends on what you're doing and what seems the most logical or preferred option.
Defaulting values in the declaration section can let you see clearly what the starting values are for things, but only if you really need to do it.

Similar Messages

  • Can we assign value to a variable in PL/SQL Loop

    Hi
    Can we assign value to a variable in PL/SQL Loops?
    DECLARE
    V_Num NUMBER;
    BEGIN
    LOOP
    V_Num := 10;
    DBMS_OUTPUT.put_line(V_num);
    V_Num := V_Num - 1;
    EXIT WHEN V_Num = 0;
    END LOOP;
    END;
    In the above program, Can we assign V_num with a value 10????????
    Thanks & Regards,
    Hari Babu
    Edited by: 1004977 on Jun 5, 2013 2:40 AM

    Hi,
    1004977 wrote:
    Hi
    Can we assign value to a variable in PL/SQL Loops?
    DECLARE
    V_Num NUMBER;
    BEGIN
    LOOP
    V_Num := 10;
    DBMS_OUTPUT.put_line(V_num);
    V_Num := V_Num - 1;
    EXIT WHEN V_Num = 0;
    END LOOP;
    END;
    In the above program, Can we assign V_num with a value 10????????Yes; the example you posted does that.
    When the loop starts, the value 10 is assigned to v_num. You should see that value displayed by the put_line statement.
    After that, v_num is set to 10 - 1 = 9.
    Next, the EXIT condition is evaluated. At this point, v_num is 9, not 0, so the loop runs again. V_num is set to 10 again, and the loop continues forever (or, in some versions, until the dbms_output buffer is filled and an error occurs.)

  • Assign value to ODI variable from Jython

    Hello Experts,
    I have a procedure where I'm using Jython code. I want to assign a value to an ODI project variable from a Jython function:
    Example:
    #COUNTER = len(v_jythonList) ---> being #COUNTER the ODI project variable and len() the jython function
    Now, i noticed that using ODI variables adds # sign which is use for comments in Jython code. Is there a way to assign values to ODI variables from Jython script?
    Please help!.
    Thanks.
    Pablo.

    Hi,
    Does this post help you :- How to assign value for a ODI variable from Jython Script
    Doc id 424579.1 on metalink should help.
    Cheers
    John
    http://john-goodwin.blogspot.com/

  • Cannot assign value to a Variable of Complex Type beyond index 1

    Hello:
    I have a variable defined as a complex type as followed. I tried to assign a value to each of the two elements but it only allows me to assign to the 'element#1.
    This statement that tries to assign a value into element#2 will not work, if I assign with '[1]' for the first element it will work:
    <copy> <---- THIS WORKS
    <from expression="'John'"/>
    <to variable="My_Variable"
    part="My_Collection"
    query="/ns9:My_Collection/ns9:Collection/ns9:Collection_Item[1]/ns9:pname"/>
    </copy>
    <copy> <---- THIS DOES NOT WORK
    <from expression="'John'"/>
    <to variable="My_Variable"
    part="My_Collection"
    query="/ns9:My_Collection/ns9:Collection/ns9:Collection_Item[2]/ns9:pname"/>
    </copy>
    Is there something wrong with my definition below that allows only element#1 to be refererenced but not element#2???? Am I missing some kind of initialization that is needed to initialize both elements????
    Here are my message and Complex Type definitions:
    <variable name="My_Variable" messageType="ns8:args_out_msg"/>
    <message name="args_out_msg">
    <part name="My_Collection" element="db:My_Collection"/>
    </message>
    <element name="My_Collection">
    <complexType>
    <sequence>
    <element name="Collection" type="db:Collection_Type" db:index="2" db:type="Array" minOccurs="0" nillable="true"/>
    <element name="Ret" type="string" db:index="3" db:type="VARCHAR2" minOccurs="0" nillable="true"/>
    </sequence>
    </complexType>
    </element>
    <complexType name="Collection_Type">
    <sequence>
    <element name="Collection_Item" type="db:Collection_Type_Struct" db:type="Struct" minOccurs="0" maxOccurs="unbounded" nillable="true"/>
    </sequence>
    </complexType>
    <complexType name="Collection_Type_Struct">
    <sequence>
    <element name="pname" db:type="VARCHAR2" minOccurs="0" nillable="true">
    <simpleType>
    <restriction base="string">
    <maxLength value="25"/>
    </restriction>
    </simpleType>
    </element>
    </sequence>
    </complexType>
    The error msg it gives me is as followed:
    [2010/09/04 00:47:59] Error in <assign> expression: <to> value is empty at line "254". The XPath expression : "" returns zero node, when applied to document shown below:less
    oracle.xml.parser.v2.XMLElement@1fa7874
    [2010/09/04 00:47:59] "{http://schemas.xmlsoap.org/ws/2003/03/business-process/}selectionFailure" has been thrown.less
    -<selectionFailure xmlns="http://schemas.xmlsoap.org/ws/2003/03/business-process/">
    -<part name="summary">
    <summary>
    XPath query string returns zero node.
    According to BPEL4WS spec 1.1 section 14.3, The assign activity &lt;to&gt; part query should not return zero node.
    Please check the BPEL source at line number "254" and verify the &lt;to&gt; part xpath query.
    </summary>
    </part>
    </selectionFailure>
    Thanks
    Newbie

    Hello:
    Base on the suggestion to use 'append' instead of 'copy', I tried to define a 'singleNode' which is of type 'Collection_Type_Struct' so I can append this individual 'struct' into my array (i.e. as the 2nd. element of my array "/ns9:My_Collection/ns9:Collection/ns9:Collection_Item"), but I am getting an error in defining this variable as:
    <variable name="singleNode" element="Collection_Type_Struct"/> <--- error
    Can someone tell me how should I define "singleNode" so I can put a value in it and then append this 'singleNode' into the array:
    <variable name="singleNode" element=" how to define this????"/>
    <assign>
    <copy>
    <frem expression="'Element2Value'"/>
    <to variable="singleNode"
    part="My_Collection"
    query="/ns9:My_Collection/ns9:Collection/ns9:Collection_Item/ns9:pname"/>
    </copy>
    </assign>
    <bpelx:assign>
    <bpelx:append>
    <from variable="singleNode" query="/ns9:My_Collection/ns9:Collection/ns9:Collection_Item"/>
    <to variable="My_Variable"
    "part="My_Collection"
    query="/ns9:My_Collection/ns9:Collection"/>
    </bpelx:append>
    </bpelx:assign>
    Again here is my definition in my .xsd file:
    <element name="My_Collection">
    <complexType>
    <sequence>
    <element name="Collection" type="db:Collection_Type" db:index="2" db:type="Array" minOccurs="0" nillable="true"/>
    <element name="Ret" type="string" db:index="3" db:type="VARCHAR2" minOccurs="0" nillable="true"/>
    </sequence>
    </complexType>
    </element>
    <complexType name="Collection_Type">
    <sequence>
    <element name="Collection_Item" type="db:Collection_Type_Struct" db:type="Struct" minOccurs="0" maxOccurs="unbounded" nillable="true"/>
    </sequence>
    </complexType>
    <complexType name="Collection_Type_Struct">
    <sequence>
    <element name="pname" db:type="VARCHAR2" minOccurs="0" nillable="true">
    <simpleType>
    <restriction base="string">
    <maxLength value="25"/>
    </restriction>
    </simpleType>
    </element>
    </sequence>
    </complexType>
    Thanks for any help!!!!

  • Dynamically assign value to bind variable in a view object before pageload

    I found that it is extreamely hard to find an example to assign the bind variable in View object at runtime using a data attribute defined in Human task activity. Most of the available samples use a Literal value to do the assignment. In my case, I want to dynamically display the content by assigning the data attribute in Human task to the bind variable in view object before a pageload.
    I do not want to bind the view object to some command component to click a button or link in order to make it work (Unnecessary components in my page).
    The issue is how to access the data attribute in Human task in the java code of client interface in AppModule? or is there a way that I can access the data attribute in Groovy script expression of the bind variable? or if I can access the process data object defined in my BPM process to do the assignment at runtime?
    Really need help on the issue, and I cannot believe that it is so hard to accomplish.
    Thank you very much,

    chk this
    Passing default value to bind variable on page load.
    http://adfcodebits.blogspot.com/2010/03/bit-2-setting-bind-variable-value.html

  • Error in assigning value to local variable

    i am writing a stored procedure in which i have pass parameter if parameter value is zero then i assign a previously declared variable null else that value
    syntax is this
    create or replace
    PROCEDURE usp_Add_Update_Insurance
    p_CityID IN NUMBER DEFAULT NULL
    as
    v_CityID number(10,0);
    begin
    IF p_CityID = 0 THEN
    BEGIN
    v_CityID := NULL;-----giving error in this line
    else
    v_CityID:=p_CityID;
    END;
    END IF;
    end
    begin
    ///some query
    end
    please help someone

    I think there is no added value by putting those Begin/End.
    The simplest solution is just remove them
    Create Or Replace
    Procedure Usp_Add_Update_Insurance (
         P_Cityid In Number Default Null
    ) As
         V_Cityid Number(10,0);
    Begin
         If P_Cityid = 0 Then    
              V_Cityid := Null;
         Else
              V_Cityid:=P_Cityid;
         End If;
         -- do something with V_Cityid    
    End; The only reason for having Begin/End is if you want to catch some exceptions or perform some strange local variable declarations. But it does not seems to be case here.
    MJ

  • Assigning value to a variable in Script Component.

    I'm pretty new to SSIS development and need to figure out a problem with assigning a value to a user defined variable. I created a pretty simple package. It reads a flat file, extracts date from a header record and subsequently uses derived column component
    to reformat data to the desired output format. One of the columns (FileRunDate,
    string, length 8) in the derived component is defined as a string and in the expression I'm assigning it to a variable I set earlier in the script component -
    @[User::vRunTimeDate]. When the process runs, the output file gets generated, however FileRunDate reflects
    originally set varible's value. It seems that the variable assignment in the script task does not work, even though in the debug mode, I do see how the value is being set. The variable has an attribute of ReadWrite. Is it due to the fact that the value is
    being set in the same workflow?
    Any feedback is greatly appriciated.

    Unfortunately I'm unable to add a screenshot of the process, for some reason I get an error message when I try to do that. In a nutshell the entire workflow consist of flat file source component, following by a script component (this is where I read and
    assign the variable) 
        public override void PostExecute()
            IDTSVariables100 vars;
            base.PostExecute();
            // Set run date
            if (strRunDate != null)
                VariableDispenser variableDispenser = (VariableDispenser)this.VariableDispenser;
                variableDispenser.LockForWrite("User::vRunTimeDate");
                variableDispenser.GetVariables(out vars);
                // Set the variable
                vars["User::vRunTimeDate"].Value = strRunDate;
                //Unlock the variable 
                vars.Unlock();
                //Variables.vRunTimeDate = strRunDate;
    then goes conditional split ( filtering out unwanted records), which is connected to a derived column component (this is where one of the columns get assigned a variable's value), one more script component (this where I identify
    specific data element and do a replace command) and finally flat file destination.
    BTW, the article in the provided URL clearly states that variable won't reflect assigned value till the entire workflow has finished. If that's the case, then I think I know my
    answer. Is there is such a thing as putting execution of different steps in a different step, so anything executed subsequently will see that value?

  • Urgent - Assign Value To Bounded Variables

    In My Application Module I Create View With Bound Variables in The Where Condition, I Create Manual JSP To List The Data From The View As Reports Done.
    Pls. Tell Me How & Where I Can Assign Value To The Bounded Values At Run Time
    Regards
    ABG

    If your datasource tag introduces a scripteable vairiable named 'ds' you can use a scriptlet as follows:
    <%
    ds.getRowSet().setWhereClauseParam(int index, Object value);
    %>
    the index is the parameter index, the value is the value of tha parameter. Please look at the BC4J runtime Javadoc for more information.

  • Execute SQL Task: Cannot assign value to the variable

    DECLARE
    @PartitionDate varchar(8),
    @Date int
    SELECT
    @PartitionDate = MAX(PartitionDate)
    FROM PartitionLog (NOLOCK)
    SELECT
    @Date = MIN(DateKey)
    FROM DimDate WHERE CAST(DateKey as varchar(8)) > @PartitionDate
    IF NOT CONVERT(varchar(8),GETDATE(),112) = @PartitionDate
    SELECT @PartitionDate = CAST(DateKey as varchar(8))
    FROM DimDate (NOLOCK)
    WHERE DateKey = @Date
    SELECT @PartitionDate AS PartitionDate ,
    'IISDW_' + @PartitionDate AS PartitionName
    GO
    I have the above SQL stmt in the excute SQL task and declared 2 variable "PartitionDate" and "PartitionName" in the Package, the RESULT SET I hav given as "Single Row" and when I run the ETL I get the error as 
    [Execute SQL Task] Error: An error occurred while assigning a value to variable "PartitionDate": "Exception from HRESULT: 0xC0015005".

    Does your package variable datatype match the datatype of your parameter?
    Is your Package variable assigned to the parameter in the task editor?
    And does the parameter name in the task editor match the parameter names in your stored procedure?

  • Is an assigned value to an variable in the domain of the data element

    Hi
    how can I check if the value, which I want to assign to an variable is in the domain of the data element of that variable.
    Example:
    I defined a data element myDataElement. The Elementary Type of myDataElement is the Domain myDomain.
    myDomain has the Format: Char with Length 1 and the fixed values 'A' and 'B'.
    The following code works, but IMHO should not:
    DATA testVar TYPE myDomain.
    testVar = 'Foo'.
    The value of testVar is now: 'F' .
    As 'F' is not in the fixed values, this is a behaviour which I don't want. How can I prevent this from not happening (without using a bunch of IFs)?
    In such a case, it were nice if an exception were raised.
    Regards
    Gilles

    Thanks Gungor.
    I tried it with DDUT_DOMVALUES_GET. Works so far. I think I will write some FMs on my own, like this one:
    FUNCTION z_valueisindomain.
    *"*"Local Interface:
    *"  IMPORTING
    *"     REFERENCE(IV_DOMAINNAME) TYPE  DDOBJNAME
    *"     REFERENCE(IV_EVALUATING_VALUE) TYPE  ANY
    *"  EXPORTING
    *"     REFERENCE(EV_DESTINATION) TYPE  ANY
    *"  EXCEPTIONS
    *"      ILLEGAL_INPUT
    *"      NOT_IN_DOMAIN
      DATA domainvalues TYPE TABLE OF dd07v.
      CALL FUNCTION 'DDUT_DOMVALUES_GET'
        EXPORTING
          name          = iv_domainname
        TABLES
          dd07v_tab     = domainvalues
        EXCEPTIONS
          illegal_input = 1
          OTHERS        = 2.
      IF sy-subrc <> 0.
        RAISE illegal_input.
      ENDIF.
      DATA oneline TYPE dd07v.
      LOOP AT domainvalues INTO oneline.
        IF oneline-domvalue_l EQ iv_evaluating_value.
          ev_destination = iv_evaluating_value.
          EXIT.
        ENDIF.
      ENDLOOP.
      IF ev_destination IS INITIAL.
        RAISE not_in_domain.
      ENDIF.
    ENDFUNCTION.
    I'm pretty new to ABAP, so this FM might not be very elegant.
    Regards
    Gilles

  • Assigning variable value to another variable

    I want to assign value from one variable with type DATETIME to another variable which has type STRING.
    E.G: I need to convert this variable P_CreatedDate of type DATETIME to STRING variable CreatedDate.
    Can someone help me in C# script. Im using SSIS script task.
    Thanks in advance.
    ZK

    I have a requirement where I need to convert following datetime variable value into the string vaiable format.
    Here is the example: 
    7/23/2014 11:24 PM
    I need above datetime to be converted into following string format
    2014-01-01 03:15:01.470
    yyyyMMdd HHmmssFFF
    Thanks in advance.
    ZK

  • Assigning Value to Variable in Sapscript

    Hi,
    To initialized value of the variable when I tried to assign 0 to variable (like in the following statement) it comes up with error 'Command Expected'.
    &RF140-ZALBT&= '0'.
    Please let me know where and what I am doing wrong in assigning value to a variable?
    Regards,
    Shabbar

    Hi,
    Still its not working. The statement I am writing is
    /: &NET& = &RF140-WRSHB& - &RF140-MSATZ&
    but the system gives error on that.
    NET is the local variable declared with Define statement and both the others are defined in print program.
    Even I tried
    /: &RF140-ZALBT& = &RF140-WRSHB& - &RF140-MSATZ&
    but still the same error.
    Any comments?
    Regards,
    Shabbar

  • How to assign a value to ODI Variable using ODI Procedure

    Hi ,
    Is it possible to assign a value to a ODI Variable using ODI Procedure ?
    If it is possible how we can do that.
    BEGIN
    IF #Counter=1
    Then
    #Next_Increment:=#Counter+1;
    End if;
    END;
    In my example I have 2 ODI Variables #counter and #Next_increment.
    I am trying to assign VALUE TO A ODI VARIABLE #next_increment from another ODI Variable #counter.
    thanks
    prasanna

    Prasanna,
    I have a similar requirement where I need to assign values to ODI variables within a procedure. How do we make use of an ODI package to accomplish this ?
    Actually, I have a sequence of ODI steps, and there is a call to a procedure 'LOG ERROR' from every step which gets called in case error occurs in any step. I just need to identify from which step the error came.
    Please help.

  • How can we give values to the variable

    Oracle Forms6i
    Hai All
    I am generating an daily attendance regarding shift basis.In that i have written an ifelse condition it work successfull and but it fetches only 350 row out of 800.
    I have declared a variable and i need to know how to assign values to the variable Pls tell the steps to do.I have done correctly but there is an logic error in my coding.Let give me some steps to solve the problem
    My coding is
    declare
    t_in varchar2(25);
    t_out varchar2(25);
    cursor cur_test is
    select * from dail_att where intime=t_in and outtime =t_out;
    --into t_in,t_out from dail_att; 
    begin
    loop
    go_block('TEST_SRI');
    FIRST_RECORD;
    if :bartime between 0145 and 0630 then
         update dail_att set outtime = :bartime where barcode= :barcode
    and ATTEND_DATE = :bardate-1 and intime is null and outtime is not null;
    elsif :bartime between 0630 and 0900 or :bartime between 1130 and 1230 or
    :bartime between 1700 and 1800 and t_in is null then
    insert into dail_att(barcode,intime,attend_date)
    values(:barcode,:bartime,:bardate);
         elsif :bartime > 1645 and t_in is not null and t_out is null then
    update dail_att set outtime = :bartime where barcode= :barcode
    and ATTEND_DATE = :BARDATE and intime is not null and outtime is null;
    end if;
    EXIT WHEN :SYSTEM.LAST_RECORD = 'TRUE' OR :BARCODE IS NULL;
    NEXT_RECORD;
    END LOOP;
    forms_ddl('commit');
    exception
    when others then
    forms_ddl('rollback');
    message(sqlerrm||dbms_error_Text);
    message(sqlerrm||dbms_error_Text);
    end;
    Regards
    Srikkanth.M

    Hai man
    I have generated a daily attendance roll in oracle forms and it executed correctly but while fetching it fetch some of the records. So i have declared a variable in a block and in my coding.
    For those variable i need to pass values from select statement or using cursor.According to that i can use in my ifelse statement.
    If It is clear Or else see the coding
    declare
    bar_code varchar2(25);
    in_time varchar2(25);-------------------------- these are the variable i going to use in select statement to pass values
    out_time varchar2(25); so that i can use in if else statement.
    begin
    loop
    go_block('TEST_SRI');
    FIRST_RECORD;
    select BARCODE,INTIME,OUTTIME into bar_code,in_time,out_time from dail_att where BARCODE= :Barcode
    and ATTEND_DATE = :bardate;
    if :bartime between 0100 and 0630 then
    update dail_att set outtime = :bartime where barcode= :barcode
    and ATTEND_DATE = :bardate-1 and in_time is null and out_time is not null;
    elsif :bartime between 0630 and 0900 or :bartime between 1130 and 1230 or
    :bartime between 1700 and 1800 and in_time is null then
    insert into dail_att(barcode,intime,attend_date)
    values(:barcode,:bartime,:bardate);
         elsif :bartime > 1645 then
    update dail_att set outtime = :bartime where barcode= :barcode
    and ATTEND_DATE = :BARDATE and in_time is not null and out_time is null;
    end if;
    EXIT WHEN :SYSTEM.LAST_RECORD = 'TRUE' OR :BARCODE IS NULL;
    NEXT_RECORD;
    message(:barcode);
    END LOOP;

  • How to make the assignment of a AW variable perminent(Java API+DMLcommands)

    hi,
    i want to modify the analytical workspace.
    i called the dml commmands from java AW api.
    the program is working fine.but i can not see the result.
    i assigned a AW variable with some data by useing DML command
    but after closing the program i unable to get the assigned value from the variable
    i checked by using AW WORK SHEET.
    any one can help me how to make that assignment perminent
    my code is like this
    AWconnection.executeCommand("v_variable=value");

    Hi,
    I have just rephrased the question to make it clear.
    I am working with Jdeveloper and BI beans. We are using Java Analytical workspace API for connecting and saving the user input as Analytical workspace Variable (which will be later used for running the AW Programs). The part of the code looks like below.
    awConn.executeCommand("V_NII_SIM=50");
    awConn.executeCommand("update");
    awConn.executeCommand("commit");
    Despite doing the UPDATE and COMMIT to the analytic workspace, the change is not getting appplied to the AW. i.e After the execution of this program, when I checked the value of the variable V_NII_SIM in the OLAP worksheet (of AWM), then it is not reflecting the new value (50).
    OLAP> show V_NII_SIM
    100.0
    The above command in OLAP worksheet returns the old value of 100 but not the one set by my program.
    Would appreciate your help on this.

Maybe you are looking for

  • Error while adding a second template to the same data definition

    Hi, I am quite new to XML Publisher. I am developing a report using XML Publisher. I have added one template to the Data Definition. When I tried to add another Template(with different name as previous, to the same concurrent program and application)

  • APP Store error 100

    This is quite annoying and seems like I am not alone. Am waiting on a Support call. I upgraded to Lion through App Store and iWork '09 and PhotoShop Elements stopped working. Then I used App store to purchased Pages. I was happy as a clam that all wa

  • HT3939 i can't on my iphone 3G. it suddenly off. even phone not charged when i plug to power.  kasun

    hello.. i can't on my i phone 3G. it 's suddenly off.and now it want to on. even phone not charging when i connected to power. pls hepl me.

  • Styling Rules, can anyone explain to me why this will not work?

    I am creating a Custom Theme, for some reason Mapviewer generates the first two rules of this and then ignore the last two rules. It does not matter if the 2nd rules is any of the last 3, it will generate the markers associates with the query, but af

  • Content status

    I have a content rule on a CSS 11501 running version 07.40.1.03 that has two services assigned to it. If both of these services are down the content rule still shows as alive on the css. What I would like the ability to do is to either use snmp to mo