Optional Arguments/Cursors in DML Programs

I am trying to write a DML program which needs to have optional arguments. I am having issues when executing a SQL based on whether the argument is supplied or not.
My program is defined as below:
VARIABLE v_ARG TEXT
if ARG(1) ne ''
then do
SQL DECLARE a_cur CURSOR FOR select ARG(1) from dual
doend
else do
SQL DECLARE a_cur CURSOR FOR select '1275' from dual
doend
SQL OPEN a_cur
SQL IMPORT a_cur INTO :v_ARG
SQL CLOSE a_cur
SQL CLEANUP
show joinchars('Value set is ', v_ARG)
The output of the program without and with arguement is as follows:
->call TEST_PRG
Value set is 1275
->call TEST_PRG(111)
ORA-35572: (SQLOUT09) SQL cursor 'A_CUR' is not open.
->call TEST_PRG('111')
ORA-35572: (SQLOUT09) SQL cursor 'A_CUR' is not open.
I have two questions. How to solve the above problem with cursors being not open? Also, Is there a preferred way to deal with optional arguments or the above approach is fine?
Any help is greatly appreciated.
Thanks
Swapan.

First, the issue was not multiple SQL DECLARE commands. Sorry.
The program is that the MD engine wants any program that includes SQL DECLARE (and maybe other SQL commands) to be compiled before it is run. So, if you need to generate the SELECT dynamically you should generate a program and then run that program. Here's an example.
The TEST program is a driver.
DEFINE TEST PROGRAM
PROGRAM
VRB _result text
" Call the program that generates the program with SQL commands. This program
" creates a function named SELECTPRG
call GENERATE_SELECT_PROGRAM(ARG(1))
" Assign the result of the _SELECT_PRG function into _RESULT
_result = _select_prg
" Show the result.
show _result
Here's the GENERATE_SELECT_PROGRAM:
DEFINE GENERATE_SELECT_PROGRAM PROGRAM
PROGRAM
vrb _select text
vrb _prg    text
vrb _result text
" Check of the program exists. If not, create it.
if exists('_select_prg') eq NO
then define _select_prg program text
" Construct the SQL DECLARE command
if ARG(1) eq ''
THEN select = joinchars('SQL DECLARE acur CURSOR FOR SELECT \'ABCDEFG\' FROM DUAL')
ELSE select = joinchars('SQL DECLARE acur CURSOR FOR SELECT ' , '\'' , ARG(1) , '\'' , ' FROM DUAL')
" Generate text of a program with the SQL commands
_prg = 'vrb _result text'
_prg = joinlines(_prg , _select)
_prg = joinlines(_prg , 'SQL OPEN a_cur')
_prg = joinlines(_prg , 'SQL IMPORT a_cur INTO :_result')
_prg = joinlines(_prg , 'SQL CLOSE a_cur')
_prg = joinlines(_prg , 'SQL CLEANUP')
_prg = joinlines(_prg , 'RETURN _result')
" Assign the program text to the program
consider selectprg
program _prg
END
It produces a program like this:
DEFINE SELECTPRG PROGRAM TEXT
PROGRAM
vrb _result text
SQL DECLARE a_cur CURSOR FOR SELECT 'ABCDEFG' FROM DUAL
SQL OPEN a_cur
SQL IMPORT a_cur INTO :_result
SQL CLOSE a_cur
SQL CLEANUP
RETURN _result
END
So, if I run test I get:
-> test
ABCDEFG
->test 'Hello Swapan, I hope this helps'
Hello Swapan, I hope this helps

Similar Messages

  • How do I view data from OLAP DML program or statement?

    Hi
    I'm struggling to find any information on this topic anywhere on the net:
    How to view data produced by an Oracle OLAP DML program or statement.
    Background :
    I am using the latest AWM to create and maintain dimensions, cubes and measures. However, I've noticed that AWM, Discoverer OLAP, BI Beans, Excel Plug-In et al only provide a fixed set of formula and expressions.
    For example, I wanted to created a Standard Deviation (STDEV) on measure. After much searching I learnt that I could do this by creating a custom measure in AWM by importing a measure defined in an XML dcoument as it's not provided by AWM. The output in Discoverer OLAP on the surface seems to give the correct results, however when drilling from high level to lower level of time time dimension hierarchy Discoverer includes the parent value in the calculation and renders the values incorrect.
    My alternative is to use OLAP DML, as it provides a richer range of formuale and calculations possibilities and I was hoping to use this functionality to do create the measures. I have the distinct impression, however, that OLAP Worksheet is the only interface out there to do this.
    It seems very primitive and limited with regards to data output, almost like SQL*Plus in many ways.
    The burning questions I have are :
    1) Do I need to write DML programs to perform these custom measure calculations and add them to cubes or do I import the custom measures via AWM and XML?
    2) If the answer to question 1 is DML programming, is there a way of viewing the OLAP data output through a GUI interface without embedding the statements in SQL.
    3) Has anyone experienced or noticed the same problem with Discoverer OLAP, AWM Viewer that I mentioned above? i,e, statistical functions performed on whole dimension hierarchy rather than lower levels.
    I'm hoping someone out there knows what I am trying to do or get at. Keith, any ideas or suggestions?
    Thanks
    Kind Regards
    Greg

    Hi Greg,
    There are two ways to achieve what you want. Both require the use of custom calculations which cannot be created via the calculation wizard within AWM. To do this the easiest way is step outside of AWM and use the Excel Calculation utility that is on the OLAP OTN home page:
    Creating OLAP Calculations using Excel
    http://download.oracle.com/otn/java/olap/SpreadsheetCalcs_10203.zip
    Readme
    http://www.oracle.com/technology/products/bi/olap/OLAP_SpreadsheetCalcs.html
    (Oracle OLAP DML Reference contains a list of all the OLAP functions that can be used to create a custom calculation. http://www.oracle.com/technology/products/bi/olap/OLAP_DML_10.2.zip)
    The Excel tool lets you assign your own formula to a measure and then uploads that measure definition into your AW. It is possible to import a custom calculation template into AWM using the menu option on the Calculated Measure node of each cube, but it is safer to use the Excel Worksheet as this directly uses the public XML API and is always best to use a public API rather than hacking XML templates.
    There are two types of custom calculation:
    1) Formula: using a formula you can directly call any of the OLAP functions. For example to create a measure that returns the standard deviation for a measure then you would enter the following as the formula for your calculated measure:
    stddev(sales_revenue, time)
    The easiest way to test if the measure is working as expected is to use the data viewer within AWM.
    2) Programs - if the function you need is not provided or you want to do special processing to return a result you can create an OLAP DML program which can return a result. To do this use OLAP Worksheet to define the program and add a datatype to the DEFINE statement, such as :
    DEFINE PRG_SD_SALES PROGRAM DECIMAL
    In the program return the value you have calculated within your program. Within the program you can do just about anything but be aware that your program is going to fire for every cell within your virtual cube so it must be efficient and fast to execute. For a measure then you would enter the following as the formula for your calculated measure:
    prg_sd_sales(time, products, geographies, channels).
    The actual program code would look something like this:
    DEFINE PRG_SD_REVENUE PROGRAM DECIMAL
    PROGRAM
    argument T_TIME TIME
    argument T_PRODUCT PRODUCTS
    argument T_GEOGRAPHY GEOGRAPHIES
    argument T_CHANNEL CHANNELS
    variable D_RETURN decimal
    TEMPSTAT TIME, PRODUCTS, GEOGRAPHIES, CHANNELS
    do
    limit PRODUCTS to T_PRODUCT
    limit CHANNELS to T_CHANNEL
    limit GEOGRAPHIES to T_GEOGRAPHY
    limit TIME to T_TIME
    limit TIME add descendants using TIME_PARENTREL
    limit TIME keep TIME_LEVELREL 'CAL_MONTH'
    D_RETURN = stddev(SALES_REVENUE)
    doend
    return D_RETURN
    END
    This code computes a standard deviation the all months within the specified time range, at year level for all 12 months, at quarter level for the three months within the quarter ans returns NA at the month level.
    As the code executes within a implicit loop you can only change the status fo dimensions that for part of that implicit by using the TEMPSTAT command. To test the program at the command line use the OLAP Worksheet and the SHOW command to just return one cell of data, DO NOT SIMPLY USE THE RPR COMMAND because you will have to wait for the whole cube to be returned. If you want to use the RPR command make sure you limit your base dimensions first! You can use PRGTRACE to debug your program code it is not working as expected. Again, the easiest way to test if the measure is working as expected is to use the data viewer within AWM, although this will not return debug information so send all your debug output to a file to capture any errors and/or trace the execution flow.
    Hope this helps
    Keith Laker
    Oracle EMEA Consulting
    BI Blog: http://oraclebi.blogspot.com/
    DM Blog: http://oracledmt.blogspot.com/
    BI on Oracle: http://www.oracle.com/bi/
    BI on OTN: http://www.oracle.com/technology/products/bi/
    BI Samples: http://www.oracle.com/technology/products/bi/samples/

  • OLAP DML Program Help

    Greetings,
    I am trying to write a DML program to read data from each active cell displayed in a crosstab, and parse through various information. For each cell, I want to capture the value of the measure, and the level and value of each dimension, apply some logic, apply a value to another measure related to the original, and then persist that new value into that cell for the second measure.
    There are a couple of problems that I am running into. First of all, I am performing some testing to fully understand the logic, but it seems that via the OLAP Worksheet, DML programs do not like to accept command-line parameters. This is necessary as I will have a few different programs that communicate via parameters rather than global variables. Secondly, within my DML programs, I have had no problem whatsoever creating and selecting data from a sql cursor when my where clause contains static data. However I will need the flexibility to determine at runtime the status of a dimension, and select via sql depending upon that value. This is not currently possible as any variable substitution within the where clause of a sql declare cursor statement generates an error. If anyone has a suggestion or an idea of what I am doing wrong, please reply.

    Is it the usage of the host variable syntax within the sql define cursor statement which did the trick ... ":_objecttype" instead of "_objecttype".
    I've used the following syntax in olap dml programs in 10gR2 (only 1 filter in the sql statement though)...
    "where pr.user_id = :_appuser" ... _appuser is a text variable (not argument) defined locally in the program.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • OLAP DML program 10g Help!!

    I have a OLAP DML program that I am invoking as follows
    call pmtdim_user_sec(_aw 'MG_OU' 'OPERATING_UNIT')
    The intent is to use the OPERATING_UNIT or parameter in 3rd place as a condition for cursor in the program.
    e.g. below for the sql for cursor.
    select PF_OBJ_ID from ps_cgf_ac_security@act_link -
    where OPRID =USER and PF_OBJECT_TYPE = 'OPERATING_UNIT'
    However when I use it in the program as below I get a failure during opening of cursor. The same thing when hardcoded per this SQL works fine? Am I doing anything incorrect. I tried using objtype and objecttype variables below in the where condition without any luck.
    Program below:
    " pmtdim_user_sec -PROGRAMS
    arg _aw text "fully qualified AW name e.g. AWADMFDL.FDL
    arg dimname   text  "Dimension ID on which PERMITREAD needs to be set
    arg _objtype   text  "Object type for row level security
    vrb _dim1      text
    vrb _dimlist   text
    vrb _used      text
    vrb _usedlist  text
    vrb _finallist text
    vrb _uservalue text
    vrb _userlist  text
    vrb _objecttype text
    show 'beginning of the program'
    show _dimname
    show _objtype
    trap on failure
    badline = y
    "multi aw and object fetching
    _dim1 = joinchars(_aw '!' _dimname)
    _used = joinchars(_aw '!' _dimname '_USED_IS_IT')
    _objecttype = joinchars('\'' _objtype '\'')
    show ' objecttype :'
    show _objecttype
    show 'before cursors'
    sql declare c2 cursor for -
    select PF_OBJ_ID from ps_cgf_ac_security@act_link -
    where OPRID =USER and PF_OBJECT_TYPE = _objecttype
    push &_dim1
    "Initializing
    _dimlist = na
    _usedlist = na
    _finallist = na
    _userlist = na
    show 'before opening of cursor'
    sql open c2
    show 'opening cursor'
    if sqlcode ne 0
    then goto failure
    show 'before while'
    while sqlcode eq 0
    do
    show 'before fetch'
    sql fetch c2 into :_uservalue
    show 'after fetch'
    if exists (_uservalue)
    then
    if isvalue(&_dim1 joinchars(_uservalue))
    then dimlist = joinlines(dimlist _uservalue)
    else goto failure
    doend "while
    sql close c2
    show 'end of opening of a cursor'
    _finallist = joinlines(_dimlist)
    _finallist = uniquelines(_finallist)
    show 'Final List '
    show _finallist
    if _finallist ne na
    then do
    lmt &_dim1 to _finallist
    &joinchars('lmt ' _dim1 ' add descendants using ' _dim1 '_parentrel')
    "&joinchars('lmt ' dim1 ' add ancestors using ' dim1 '_parentrel')
    &joinchars('consider ' _dim1)
    &joinchars('permit read when instat('_dim1 ' ' _dim1 ')')
    doend
    pop &_dim1
    return
    failure:
    pop &_dim1
    signal errorname errortext
    return errortext

    Is it the usage of the host variable syntax within the sql define cursor statement which did the trick ... ":_objecttype" instead of "_objecttype".
    I've used the following syntax in olap dml programs in 10gR2 (only 1 filter in the sql statement though)...
    "where pr.user_id = :_appuser" ... _appuser is a text variable (not argument) defined locally in the program.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Logs from OLAP DML Programs

    Is there any way to get a continuous stream of logs when an OLAP DML program is running ( eg. A Loop ). I am on 9.2.0.5 currently. The logs are being dumped only after the program has finished execution but not when it is running. Can this behavior be changed ?
    Any help is appreciated.
    Thanks
    Swapan.

    This can be done very easliy. Here is what I did.
    1. Create a table called OLAP_LOG - with columns OLAP_DATE, OLAP_MESSAGE, OLAP_PROGRAM. Note that this is along the same lines as olapsys.XML_LOAD_LOG table.
    2. In OLAP create a function (lets call is OLAP_LOG_MSG) which will take two arguments which are text values (one for a message, second one for program name).
    3. Within OLAP_LOG_MSG olap program you will do an INSERT statement into OLAP_LOG table. In the OLAP_DATE column you can put in SYSDATE, the next two columns will be populated by the two arguments.
    4. In all your olap programs, wherever you are doing a SHOW statement at the same place also do a call to OLAP_LOG_MSG with the arguments. I put it in all my olap programs, including the error section.
    It has worked out very very very well....
    Enjoy!!!
    - Nasar
    .

  • OLAP DML Programs

    Hi,
    I am very much new in OLAP. My question is that in the OLAP Analytics workspace, there is a node "OLAP DML Programs ".
    Could you please tell me when it is used ? Can this DML program use for calculating program ?
    Can we say , it is the language to replace general ETL process for populating the FACT & Aggregrate table ? Is it possible by writing the DML language , we can populate the FACT & Aggregrate table ? If it is then please give an example and if not then clarify when it is used ?
    Many Thanks,
    Pallab Mandal

    This can be done very easliy. Here is what I did.
    1. Create a table called OLAP_LOG - with columns OLAP_DATE, OLAP_MESSAGE, OLAP_PROGRAM. Note that this is along the same lines as olapsys.XML_LOAD_LOG table.
    2. In OLAP create a function (lets call is OLAP_LOG_MSG) which will take two arguments which are text values (one for a message, second one for program name).
    3. Within OLAP_LOG_MSG olap program you will do an INSERT statement into OLAP_LOG table. In the OLAP_DATE column you can put in SYSDATE, the next two columns will be populated by the two arguments.
    4. In all your olap programs, wherever you are doing a SHOW statement at the same place also do a call to OLAP_LOG_MSG with the arguments. I put it in all my olap programs, including the error section.
    It has worked out very very very well....
    Enjoy!!!
    - Nasar
    .

  • How to Retrieve Data From Web Service with Optional Arguments

    This should be a simple one. I have a web service that
    returns a list of books. There are 3 optional arguments that can be
    passed to this (ex. book type, author, id) to filter this list. Do
    I still need to use the <mx:request> tags if I am not going
    to pass any parameters to the web service?
    When I look at the services browser in Flex, it says "unable
    to get meta data for CFC". However, if I remove the arguments from
    the CFC and then call the service again, all my data now appears.
    What's the best way to appoach this?
    Thanks in advance

    I have a similar application. What I have done is create one
    argument in my CFC, with a type of "struct". Then, in the Flex
    Application, I create an Object (Associative Array), and pass this
    to the CFC as that one argument.
    Here is the ActionScript:
    // Create the variable to be passed to the WebService
    [Bindable]
    private var object:Object = new Object();
    Then in another function, you create the Object, based on
    specified values - perhaps from ComboBox selections:
    object.bookType = comboBox1.selectedItem["bookType"];
    object.author = comboBox2.selectedItem["author"];
    object.id = comboBox3.selectedItem["id"];
    Then you pass that one argument in your <mx:request>:
    <mx:WebService id="getBooks" wsdl"
    http://server.com/service.wsdl"
    showBusyCursor="true"
    fault="alert(event.fault.faultstring)">
    <mx:operation name="sBooks">
    <mx:request>
    <args>{object}</args>
    </mx:request>
    </mx:operation>
    </mx:WebService>
    Your CFC might look like this:
    <cfcomponent>
    <cffunction method="sBooks">
    <cfargument name="args" type="struct">
    </cffunction>
    </cfcomponent>
    Then you can worry about validating the values passed to the
    CFC in the CFC function. That way, you could send an empty struct
    if you wanted, and the CFC would not throw an exception.
    Hope that helps.

  • How to identify the arguments of a concurrent program?

    Hi,
    I am new to 11i.
    I need to submit a concurrent request using fnd_request.submit_request.
    I was wondering if there is documentation specifying the list of arguments for each concurrent program.
    In this case I need the arguments for INCOIN, but it would be great if someone can point me to a doc listing all the conc programs or atleast the fnd_ table which might be storing this map (I might be horribly mistaken here) .
    Thanks,
    Vinay
    I figured out that
    fnd_concurrent_programs, fnd_concurrent_programs_tl, fnd_executables, fnd_application, fnd_application_tl
    these tables can give some info about the program but not the arguments
    Message was edited by:
    Vinay A

    check this tables FND_DESCR_FLEX_COLUMN_USAGES.
    descriptive_flexfield_name is $SRS$.[fnd_concurrent_programs.concurrent_program_name]

  • Photoshop CS6 randomly crashing, "photoshop has stopped working" - options to debug or close program

    Anyone know why photoshop would just crash in the middle of working or using tool or making a selection.  happened like half dozen times now.  It just stops and has an option to debug or close program and loses what you worked on since the last save and you have to restart the program.

    We need to know a lot more to help you. Please provide answers to the questions listed here: "FAQ: What information should I provide when asking a question on this forum?"
    You may also want to check this page:  How to increase performance

  • DML Program not visible in AWM

    I have created a DML program with return type none in Analytic Workspace Manager. The program contains a Consider statement to assign an equation to a formula. The program compiles successfully however, the next time I log into AWM the program is no longer visible through the gui and the return type has been changed to dimension. If I execute an Edit program command through OLAP worksheet I can see the contents of the program. Why can I not see programs with Consider statements through my gui?
    Kristine

    I figured it out! This is an odd one. In my program I have statements similar to below:
    CNS ...
    LD ...
    EQ ...
    If I place a space infront of LD like below I am able to expand the programs list in AWM which was my 2nd issue I had mentioned in my last post:
    CNS
    +(single space)+ LD
    EQ
    Now if I place a space infront of EQ like below I am able to see my program through the GUI:
    CNS
    +(single space)+ LD
    +(single space)+ EQ
    It appears that both LD and EQ need at least one space before them, in other words they cannot be left justified against the program window. They do not necessarily need to be indented in respect to the CNS statement, for example the below format should work fine as long as there is a space before LD and EQ.
    +(single space)+ CNS
    +(single space)+ LD
    +(single space)+ EQ
    Kristine
    Edited by: Kristine W on Feb 4, 2009 12:55 PM

  • How to pass arguments to a java program.

    I want to pass a file name to java program while it is going to execute.
    ex: c:\>java <.class> <filename>
    so that i have to take that filename into a string. Is it possible? If it is possible please help me.
    and how can i check whether the filename argument is given or not through command line argument?

    public class Program{
    public static void main(String[] args){
    filename = args[0];
    static String filename;
    this code is working. But if I did not give filename, and I only give like this
    java Program
    Then how can i now whether the argument (args[0]) is passed or not?

  • How to Migrate custom DML Programs to a new AW

    Hi,
    I created a custom DML Program using AWM and OLAP Worksheet.
    I'm migrating the AW metadata to another file usin XML template which doesn't migrate the custom DML Programs.
    Can you please let me know how can I migrate the custom DML Programs?
    We don't want to use EIF import and export as part of our migration.
    Thanks,
    Rajesh

    Hi Rajesh,
    You can also do it like this.
    run dsc <program name> => Copy the output to a .txt file and in the end of this txt file after "END" insert a enter.
    upload this file to physical location of a oracle directory(ensure that the user has access to this directory).
    Now from olap worksheet run
    infile <txt file name>;upd;commit;
    Thanks
    Brijesh

  • DML Programs and CVS

    Is there any preferred way of storing olap dml programs in a repository (aka CVS) ? Are there any easy integration tools available (Jdev?) ?
    Swapan.

    Satellite C655D-S5139 
    Maybe these help.
       Optimize Windows 7 for better performance
       Why is my Internet connection so slow?
    -Jerry

  • Problem with accepting the Ref Cursor in c# program

    I am passing an argument as OUT Ref Cursor in a stored procedure. and calling the procedure from my c# program.
    I can connect the database successfully but am getting the error on calling the procedure.
    I am using the ODBC connection
    My procedure's signatures are like:
    CREATE OR REPLACE PACKAGE BODY packageName
    IS
    PROCEDURE GetOutput(returnCursor OUT Sys_RefCursor)
    AS
    BEGIN
    OPEN returnCursor FOR
    <<my select statement>>
    END GetOutput;
    END packageName;
    My function call is like:
    CString Extract::ExtractScript() const
         CString script;
         script.Format("{Call %s.%s()}", packageName,GetOutput);
         return script;
    I can compile the procedure successfully on Toad but while calling the procedure from the C# program it gives following error
    Connection Successful
    Problem executing SQL {Call packageName.GetOutput()}...
    ORA-06550: line 1, column 7:
    PLS-00306: wrong number or types of arguments in call to 'GetOutput'
    ORA-06550: line 1, column 7:
    PL/SQL: Statement ignored
    Message was edited by:
    user653288

    Hi Aga,
    Thanks for your response.
    I figured out the problem.
    I was using the ODBC connection which wasnt updated for Oracle 10g.
    I have updated that. Now its working fine.
    Thanks again
    Regards

  • Change cursor in entire program?

    I use setCursor() on my main class to change the cursor to a certain image. This will work for the JDesktopPane, but the cursor will be back to default on my JInternalFrames etc.
    isn't there a way to change it for the entire program?

    you can put a Glasspane over your DesktopPane and set the cursor there. This will cover JInternalFrames as well. You can optionally use this technique to intercept Key- and MouseEvents as well.

Maybe you are looking for

  • Billing plan in BAPI

    Hi, Am creating Sales orders through my program using the Function Module "BAPI_SALESORDER_CREATEFROMDAT2". For every sales order i have to create an invoice of billing type F1. To create this billing type F1 invoice i must maintain billing plan in m

  • Error when deploy cocoon war file to sun one app server 7

    when i deploy cocoon war to sun one app server 7. i allways get a exception about this: Type: Exception Report Message: Internal Server Error Exception javax.servlet.ServletException: Servlet.init() for servlet Cocoon2 threw exception at org.apache.c

  • [problem]Error "sfntread library error (83::4)" when you start After Effects CS3 (Windows)

    Hello, I am experiencing the above stated problem in the subject. I downloaded the trial version off the website. But when starting the program, i got the error: Error "sfntread library error (83::4)" when I start After Effects CS3 I tried looking at

  • Packages..CLASSPATH ?!!

    HI, I'm quite a newbie to Java.Could anyone give me any link to a web page that gives me a detailed explanation on Packages and the Classpath environment variable. I'm getting some compile-time errors while working with Packages (probably because the

  • Subcription of Services.

    Hi Experts, Can we disable the Subscription feature in Discussions ?  If so, how can we disable , is there any privision like giving permissions ? Thanks Suresh