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

Similar Messages

  • How to declare a variable in form

    how to declare a variable in form?

    Hi,
       do you want to create variable in script or smartform?
    In scripts to define a variable use the following declaration statement.
    DEFINE &<VARIABLE_NAME>&
    place this statement as command. we can assign initial value for this by adding VALUE ' ' to above statement.
    If your requirement is for smartforms go to global declaration, create a variable there that will be applicable only for smartform.
    Hope this will help you,
    Regards,
    Aswini.

  • How to enter bind variables in Calender SQL statement

    Hi,
    Anyone know how to include bind variables in Calender SQL statement. Let's say in sql statement below:
    select
    EMP.HIREDATE the_date,
    EMP.ENAME the_name,
    null the_name_link,
    null the_date_link,
    null the_target
    from SCOTT.EMP
    order by EMP.HIREDATE
    thanks.

    Hi,
    Here is the sql statement
    select
    EMP.HIREDATE the_date,
    EMP.ENAME the_name,
    null the_name_link,
    null the_date_link,
    null the_target
    from SCOTT.EMP
    where deptno = :dept
    order by EMP.HIREDATE
    Thanks,
    Sharmila

  • Syntax to declare a variable in native sql

    Hi Experts,
    Please let me know the syntax to  declare a variable in Native SQL.
    Vivek Gupta

    Hello
    Check this link: http://help.sap.com/saphelp_47x200/helpdata/en/7b/0bdea252d746429420007a69bd06c7/frameset.htm
    There is example of native SQL.
    Also read this:
    http://help.sap.com/saphelp_nw04/helpdata/EN/fc/eb3b8b358411d1829f0000e829fbfe/content.htm
    http://help.sap.com/saphelp_nw04/helpdata/EN/a3/74caa1d9c411d1950e0000e8353423/content.htm

  • 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

  • How to use local variables declared in b/t the methods in other views

    Hi
    i need to use the value of the local variables declared in b/w the views in one other view,as i have manipulated the value based on some condition & want to use it in 1 more view for my req.,but that variable is not global one just for once i need to use it,and i can't again write the whole for its conditions,as its there in initialization view,which if coded again,can hit the functionality there,so is it possible to use the value of such local variables thereafter or not,if yes pls let me know,or i need to declare the global variable for this.

    hi,
    1.Declare an Attribute in Component controller.
    2. Pass the value to this Attribute in View V1.
             using :
      wd_comp_controller->Att = 'Saurav'.
    3. Now in view2 , you can access this Attribute using:
      data lv type string.
         lv = wd_comp_controller->Att .
    Here Att is my attribute of type string declared in component controller.

  • How to pass a variable for a SQL query in OLEDB source?

    Hi All,
    I am new to SSIS and working on it past few days. Can anyone please help me getting through a scenario where I need to pass a variable in the SQL statement in OLEDB source connection. Please find below for the details.
    eg:
    1) I have a SQL table with the columns SerialNumber, Name, IsValid, FileName with multiple rows.
    2) I have the file Name in a variable called Variable1.
    3) I want to read the data from my SQL table filtering based on the FileName (Variable1) within a data flow task and pull that data to the destination table.
    Question: In the data flow task, added source and destination DB connection with a script component in between to perform my validations. When trying to retrieve the data from source using the variable (i.e. SQL Query with variable), I am not able to add
    the query as the SQL statement box is disabled. How to filter the data based on the variable in the source DB ?
    Any help/suggestions would be of great help.
    Thanks,
    Sri

    Just to add with Vaibhav comment .
    SQL Command  : SQL query either with SQL variable or any condition  or simple Sql statement
    Like ;
    Select * from dimcustomer
    SQL Command using Varible :
    Sometimes we design our dynamic query in variable and directly use that variable name in oledb source.
    If you Sql query needs a condition based on SSIS variable .
    you can find a Example here :
    http://www.toadworld.com/platforms/sql-server/b/weblog/archive/2013/01/17/ssis-replace-dynamic-sql-with-variables.aspx
    http://www.select-sql.com/mssql/how-to-use-a-variable-inside-sql-in-ssis-data-flow-tasks.html
    Thanks
    Please Mark This As Answer or vote for Helpful Post if this helps you to solve your question/problem. http://techequation.com

  • How come my local variable is not updating it's value with respect to what's happening in the while loop?

    Hello,
    I am trying to extract data out of a while loop as my declarations update with respect to the iteration number. I have attempted to use both local variables and shift registers, but with no luck.
    I have also done the following example: http://www.ni.com/white-paper/7585/en and it works like a charm.
    I attached the PNG file with local variable declaration circled in red. Will attach a VI in the next respnose.
    Thanks
    Solved!
    Go to Solution.
    Attachments:
    Local Variable.png ‏366 KB

    OK, looking at the code...
    Can you explain what it is supposed to do? What's the purpose of the value property node read which only seems to update an indicator.
    The inner while loop should proably be a FOR loop, because the number of iterations is known before the loop starts.
    Your use of formula nodes seems overly complicated.
    LabVIEW Champion . Do more with less code and in less time .

  • How to declare class variable with generic parameters?

    I've got a class that declares a type parameter T. I know how to declare a static method, but this doesn't work for a static variable:
    public class Test< T >
        * Map of String to instances of T.
        * error: '(' expected (pointing to =)
        * <identifier> expected (pointing to () )
       private final static < T > Map< String, T > MAP = new HashMap< String, T >();
        * Get instance of type T associated with the given key.
       public final static < T > T getType( String key )
          return MAP.get( key );
    }Edited by: 845859 on Mar 20, 2011 11:46 AM

    jveritas wrote:
    I'm trying to create a generic polymorphic Factory class that contains boilerplate code.
    I don't want to have to rewrite the registration code every time I have a different return type and parameter.I haven't seen a case yet where that is reasonable.
    If you have hundreds of factories then something is wrong with your code, design and architecture.
    If you have a factory which requires large number of a varying input types (producing different types) then something is probably wrong with your code and design.
    A reasonable factory usage is one where you have say 20 classes to be created and you need to add a new class every 3 months. Along with additional functionality represented by the class itself and perhaps variances in usage. Thus adding about 3 lines of code to one class is trivial. Conversely if you have hundreds of classes to be created by the factory and you are adding them daily then it is likely that
    1. Something is wrong with the architecture which requires a new class every day.
    2. You should be using a dynamic mechanism for creation rather than static because you can't roll out a static update that often.
    More than that the idiom that leads to factory creation is different for each factory. A factory that creates a database connection is substantially different than the one used in dynamic rules logic processing. A generic version will not be suitable for both.
    Actualy the only case I know of where such a factory might be seem to be a 'good' idea is where someone has gotten it into their head that every class should be represented by an interface and every class created by a factory (its own factory.) And of course that is flawed.

  • How to use local variables to pass an image mask correctly

    I'm kind of new to labview but i'll try to explain the problem as best as i can: I'm trying to pass an image mask (basically an image) to the next iteration of a while loop using local variables. I think the image passes through the loop with the local variable but i can't read from it correctly for some reason. And I don't think the problem has to do with local variables because i've tried using shift registers and that didnt work either. I think the problem is that you need to do something to read the image correctly again, like using IMAQ copy or something (that didnt work tho), but i can't figure out what the problem is. Does anyone know what the problem is? I know this isnt a great explanation and if its too confusing i could send some snapshots of the program or something. Any help would be greatly appreciated though.
    Thanks,
    Will

    So i attached 2 snapshots of the program to give a better idea of the problem. The first snapshot shows an image getting written to the local variable SavedMask. The second snapshot, which is run on the next iteration of a while loop, shows the local variable SavedMask being read to other image operations. When i run the program, the SavedMask image is always displayed correctly on the front panel, but i can't read from it for whatever reason. I think the problem could be like you said, that im only passing an imaq reference, and i think theres a certain way to extract the image data. Do you know the correct way to extract the image data or how to pass the image data and not just a reference to the data.
    Attachments:
    first.jpg ‏81 KB
    second.jpg ‏68 KB

  • How to Populate  local variable values to tables like likp .

    Hi..I have taken 3 local variables date1 date2 and date3 .How to populate them in table (likp-lfdat).In date1 i have dates of lfdat between 14/05 to 21/05 and date2 from 22/05 to 28/05 and date3 one more week.In o/p how can see data between these dates range only?

    Use Where clause as:
    WHERE
    LFDAT IN DATE1
    OR LFDAT IN DATE2
    OR LFDAT IN DATE3.
    Regards,
    Anil

  • 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

  • How to use presentaion variable in the SQL statement

    Is there any special syntax to use a presentation variable in the SQL Statement?
    I am setting a presentation variable (Fscl_Qtr_Var)in the dashboard prompt.
    If i set the filter as ADD->VARIABLE->PRESENTATION, it shows the statement as 'Contract Request Fiscal Quarter is equal to / is in @{Fscl_Qtr_Var} '.
    And this works fine but when i convert this to SQL, it returns
    "Contract Request Date"."Contract Request Fiscal Quarter" = 'Fscl_Qtr_Var'
    And this does not work.It is not being set to the value in the prompt.
    I need to combine this condition with other conditions in the SQL Statement. Any help is appreciated. Thanks

    Try this: '@{Fscl_Qtr_Var}'

  • How to pass local variables between different sequence files?

    Actually i want to pass the data (local variable) from my process model file to a client file. The client file only has the callbacks and those callbacks require some parameters as input which is available in local variables of my process model sequence file. I do not want to use Station Globals.
    Please tell me any other way by which i can pass that data.

    Which Locals do you want from the model.  Every sequence has it's own Locals and there are a bunch of sequences in every process model.  Do you want the entry point's Locals?  A callback's Locals?  Just one of the sequence's Locals?  Some Models have way more entry points than others.  What if your sequence file is ran with a different entry point?
    One option is to create your own callback in the model and pass the data to it as parameters.  Then add that callback to your client sequence file and get it out of the parameters.
    If you simply want the entry point's locals and you are in your Main Sequence then you could use RunState.Caller.Locals.VariableName.  This assumes you will use the same entry point every time you run that sequence file.  Or assumes that every entry point you run has the same Local variable name.
    Maybe there is an API method that exposes what you are looking for.  What is your goal?
    Regards,
    jigg
    CTA, CLA
    teststandhelp.com
    ~Will work for kudos and/or BBQ~

  • SSIS Programming- How to declare a variable of type Object?

    Hello, I have a very specific coding question. I am trying to create a pkg using SSIS Object model. I am trying to create a variable of type Object. But I could not find any reference in KB or forums on creating variable of this data type.
    Example:
    // Create the package.
    Application a = new Application();
    Package p = new Package();
    p.Name = "MyDataExtractPkg";
    //Add Variables to the pkg
    Variables pkgVars = p.Variables;
    Variable var8 = p.Variables.Add("varHour", false, "User", (System.Int16)0);
    Variable var9 = p.Variables.Add("varHourDiff", false, "User", 0);
    Variable var10 = p.Variables.Add("varIntervalWaitInMS", false, "User", 5000);
    Variable var11 = p.Variables.Add("varJobCnt", false, "User", 0);
    Variable var12 = p.Variables.Add("varjobID", false, "User", 0);
    Variable var13 = p.Variables.Add("varJobRS", false, "User", (System.Object)0);
    Variable var14 = p.Variables.Add("varProcessDate", false, "User", "abc");
    As you can see I was able to successfully variables of Type Int16, Int32(default) & String.
    But I need to create a variable of type Object for "varJobRS" and above code is generating int. Appreciate any direction or help on how to create Object variable type.
    Thanks,
    DW Guy

    I have been continuing with my work with intention to approch MS, but I came across the solution in one of the Blog site. The solution is :
    var13.Value =
    new
    Object();
    This converts the variable of type Object.
    The link that gave this soluion is:
    http://ssisbi.com/building-ssis-packages-programmatically-part-5/
    Thanks,
    DW Guy

Maybe you are looking for

  • DVS Document Name

    Hi guys.. How can i create an DVS Document (CV01N9 and keep the Filename after Checking the document in alive? The Doc Name is only visible before Chekcing in!

  • How is an object created in a workflow ?

    Hello, When i create a task and assign an organizational business object to it along with a method. When the workflow is activated then it will call this method, but who will create the object and who will fill up the initial attributes of the object

  • What are the version differences for the Zen Mic

    I have the version that only allows you to upload songs from XP, and I have a 2000 computer. What are the differences between the version I have and the previous version and is it good or bad or downgrade my Micro?

  • Can restoring from an iTunes backup restore voicemails?

    I need to recover a voicemail that I very intentionally did NOT delete back in December 2012.  However, being as there is no way (at least that I am familiar with) to intentionally SAVE a voicemail on the iPhone, it no longer shows up on my VM list o

  • IPTComm 2008 Call for Demos

    Please find below the "Call for Demos" for the IPTComm 2008 http://iptcomm.org Heidelberg, Germany, July 1-2 2008. Please feel free to circulate this call for demos to interested colleagues, mailing lists, forums and blogs. ==========================