Executing a oracle function with parameters ...

Hi All,
I'm trying to execute this part of the code:
<cfdirectory action="list"
directory="#getDirectoryFromPath(sharedPath)#"
name="currentDir">
<cfoutput query="currentDir">
<cfset filename = sharedPath & name>
<cfif find(".csv",name)>
<cfexecute name = "#Application.c_script_dropfileupload_path#main_dropfileupload.sh"
arguments = """#name#"" ""#sharedPath#"""
variable = "Variables.upload_progress"
timeout = "500">
</cfexecute>
<tr>
<td colspan="3" class="text">
<cfquery name="getvalcount"
datasource="#Application.c_dsn#"
dbtype="ODBC"
password="#Session.Password#"
username="#Session.UserID#">
SELECT pk_cpv_drop_file_upload.sf_drop_validate_and_count(replace(#name#,".csv","")) FROM dual
</cfquery>
<cfoutput> #getvalcount.sf_drop_validate_and_count# </cfoutput>
</td>
</tr>
but I'm receiving the error from oracle telling: illegal zero-length identifier
My question is...
IS there a way to pass the parameter #name# to this function sf_drop_validate_and_count ? or should I work with parameters to a stored procedure?
Thanks in advance
Regards
Alex

Hi ALL,
Just to inform you that I've found a solution when you need to apply variables as a parameter:
preserveSingleQuotes(vFileName)
preserveSingleQuotes function will keep the string like this 'dadsadsad' and so, you can use it inside your functions, procedures, etc..
Thanks for all the reponses I've received.
Best regards
Alex

Similar Messages

  • I can't execute oracle functions with c#.  i'm using oracle 9i version.

    i have a problem trying to execute an oracle function with c#.net. The Oracle version i'm using is Oracle 9i.
    This is the function definition: (it's defined and working right because i have tryed it with SQLWorksheet)
    CREATE OR REPLACE Function NRegistros return integer is
    Numero integer(4);
    begin
    select count(*) into Numero from singles;
    return Numero;
    END NRegistros;
    But with c#.Net i can't acces it because i get an error: "this is not a procedure or is not defined". And i think the code is right. In fact in the same code you can see that i'm using an stored procedure and i have not problems. But with the function i have problems. Is it possible that "OracleClient" can't work with Oracle9i functions??. This is the code:
    OracleParameter Parametro = new OracleParameter("Name", OracleType.VarChar,10);
    OracleParameter ParametroFuncion = new OracleParameter("Retorno", OracleType.Int32, 4);
    Parametro.Direction = ParameterDirection.Output;
    ParametroFuncion.Direction = ParameterDirection.ReturnValue;
    OracleConnection Conexion = new OracleConnection("Data Source=DISCOS;User Id=SYSTEM;Password=a0000;");
    Conexion.Open();
    OracleCommand Todos = new OracleCommand();
    OracleCommand Procedimiento = new OracleCommand();
    OracleCommand Funcion = new OracleCommand();
    Todos.Connection = Conexion;
    Todos.CommandType = CommandType.Text;
    Todos.CommandText="select * from singles";
    Procedimiento.Connection = Conexion;
    Procedimiento.CommandType = CommandType.StoredProcedure;
    Procedimiento.CommandText = "Procedimiento";
    Procedimiento.Parameters.Add(Parametro);
    Funcion.Connection = Conexion;
    Funcion.CommandType = CommandType.StoredProcedure;
    Funcion.CommandText = "NRegistros";
    OracleDataReader Lector = Todos.ExecuteReader();
    BindingSource Discos = new BindingSource();
    Discos.DataSource = Lector;
    dgvSingles.DataSource = Discos;
    Procedimiento.ExecuteNonQuery();
    Funcion.ExecuteNonQuery();
    lblRegistroProcedimiento.Text = Procedimiento.Parameters["Name"].Value.ToString();
    lblNregistros.Text=Funcion.Parameters["Retorno"].Value.ToString();
    Conexion.Close();
    Edited by: user11921281 on 22-nov-2009 20:32

    thank you very much. It was a stupid error, sorry. There was one line left :
    OracleParameter Parametro = new OracleParameter("Name", OracleType.VarChar,10);
    OracleParameter ParametroFuncion = new OracleParameter("Retorno", OracleType.Int32, 4);
    Parametro.Direction = ParameterDirection.Output;
    ParametroFuncion.Direction = ParameterDirection.ReturnValue;
    OracleConnection Conexion = new OracleConnection("Data Source=DISCOS;User Id=SYSTEM;Password=a0000;");
    Conexion.Open();
    OracleCommand Todos = new OracleCommand();
    OracleCommand Procedimiento = new OracleCommand();
    OracleCommand Funcion = new OracleCommand();
    Todos.Connection = Conexion;
    Todos.CommandType = CommandType.Text;
    Todos.CommandText="select * from singles";
    Procedimiento.Connection = Conexion;
    Procedimiento.CommandType = CommandType.StoredProcedure;
    Procedimiento.CommandText = "Procedimiento";
    Procedimiento.Parameters.Add(Parametro);
    Funcion.Connection = Conexion;
    Funcion.CommandType = CommandType.StoredProcedure;
    Funcion.CommandText = "NRegistros";
    Funcion.Parameters.Add(ParametroFuncion); //<--------------------- That one !!! (yes it was a stupid error jeje)
    OracleDataReader Lector = Todos.ExecuteReader();
    BindingSource Discos = new BindingSource();
    Discos.DataSource = Lector;
    dgvSingles.DataSource = Discos;
    Procedimiento.ExecuteNonQuery();
    Funcion.ExecuteNonQuery();
    lblRegistroProcedimiento.Text = Procedimiento.Parameters["Name"].Value.ToString();
    lblNregistros.Text=Funcion.Parameters["Retorno"].Value.ToString();
    Conexion.Close();

  • Debug an oracle function with toad 7.4, oracle 9i

    Hello,
    i wanna debug an oracle function with toad 7.4
    so i wanna give param to this function and fix breakpoint and verfy some variables values ... etc
    could you show me how debug it?
    Thanks
    Regards
    Elyes

    Do you have the Toad Debugger? Thats the extra cost option which you get for free in OracleSqlDeveloper.
    If you have the ToadDebugger, Read the Manual
    If not , download OracleSqlDeveloper and use it. It's free, and written by Oracle.

  • Oracle Function with out parameters

    Hi, I'm trying to access a stored function on an oracle server with 2 out parameters, 2 in parameters and an out ref cursor.
    PL/SQL looks like this
    nStatusCode OUT INTEGER,
    sStatusMsg OUT VARCHAR2,
    sUsrNr           IN VARCHAR2,
    sPassword           IN VARCHAR2,
    crsReturn OUT pck_cursor.retRecordSet
    I drag the function onto dataset designer and it successfully maps the results to the datatable, it maps datatypes for first out parameters to decimal and string.
    the method genearated for fill by looks like (out decimal?,out string,string, string, out object)
    problem is, everytime i try to call this function it gives me casting exceptions for the first 2 out parameters, for the decimal it's not specified in more detail. for the other one it says there was an exception casting from OracleString to string. If I change the PL/SQL function to leave the first 2 out parameters away it works fine. Do I manually need to change the TableAdapter definitions??

    Hi,
    I think I found the problem but not a good solution. It seems to be a problem with auto code generation for TableAdapters in the Dataset wizard. In the Parameter Definition for the Command I set DbType.Decimal and DbType.Sting for the SqlDbtype Property of the out params. The GetData and Fill Method is generated with Fill(out decimal? out1, out string out2). When I look in the generated code ith first sets the SqlDbtype as written but after this also the OracleDbtype to OracleDbType.Decimal and OracleDbType.Varchar2. The casting these types before returning the throws the exception. Any idea how to change this behavior?

  • Oracle functions with PowerPivot

    Hi All,
    I have a requirement of building reports using Oracle functions in PowerPivot.
    I have tried using Table Import Wizard and Command Type=StoredProcedure in th ePowerPivot.
    Any help will be appreciated.
    Thanks and Regards,
    SS

    Hello,
    I don't think we can use Oracle functions/stored procedures in PowerPivot, please see the similar thread below:
    http://social.technet.microsoft.com/Forums/en-US/22e67f7f-0753-4f21-bae2-1812d2daf03e/powerpivot-oracle-stored-procedure-err-the-sql-statement-is-not-valid-there-are-no-columns?forum=sqlkjpowerpivotforexcel
    I would suggest you elaborate your requirement with more detail.  
    Regards,
    Elvis Long
    TechNet Community Support

  • Passing databse functions with parameters as custom parameters from comand

    Hi,
    I have a database function get_id(ichar varchar2) which will return a number which I am trying to pass to a mapping as custom inout parameter using the following command:
    @SQLplus_exec_template.sql RTUSER RTLOC PLSQL mapname "," "INPUT_ID=sample_pkg.get_id('I')"
    and I get the following error
    ------ start----------
    Session altered.
    Role set.
    override_custom_input_params(l_audit_execution_id, 'IN_FROM_DATE=1999/01/0108:00,IN_TO_DATE=2003/12/3108:00,BL_LOAD_ID=bl_job_control.get_bl_load_id('I')');
    ERROR at line 215:
    ORA-06550: line 215, column 155:
    PLS-00103: Encountered the symbol "I" when expecting one of the following:
    . ( ) , * @ % & | = - + < / > at in is mod not range rem =>
    .. <an exponent (**)> <> or != or ~= >= <= <> and or like
    between ||
    The symbol ". was inserted before "I" to continue.
    ------ end ----------
    However, the command line with NO parameter to the function like the following command works perfect:
    @SQLplus_exec_template.sql RTUSER RTLOC PLSQL mapname "," "INPUT_ID=sample_pkg.get_id"
    Will OWB commandline not accept function call with parameters? Please treat this as urgent and advice ASAP.
    Thanks.

    Thanks, Mark. It works.However facing another issue. I try to pass to_char(sysdate\,''yyyy/mm/ddhh:mi:ss'') as one of the custom parameters to the mapping as
    @SQLplus_exec_template.sql RTUSER RTLOC PLSQL mapname "," "INPUT_STDT=2002/10/2010:10:03,INPUT_enddt=to_char(sysdate\,''yyyy/mm/ddhh:mi:ss'')"
    and it erros out as
    ------ start ------
    ORA-01841: (full) year must be between -4713 and +9999, and not be 0 ORA-06512: at line 1
    ------ end ------
    Questions:
    1. Why does a simple to_char(sysdate\,'yyyy/mm/ddhh:mi:ss') as an input parameter fail?
    2.what is the date format that OWB expects when we pass date as an input parameter.Can the format be modified?
    OWB seems to accept the format yyyy/dd/mm only. If I pass as different format, it errors with ORA 1861 Text: literal does not match format string.
    3. Where can I change the format in OWB if it can be changed.
    NOTE: OWB complains only about INPUT_ENDDT and not INPUT_STDT because, if I hardcode INPUT_ENDDT like 2003/11/178:00 it works.
    example:
    @SQLplus_exec_template.sql RTUSER RTLOC PLSQL mapname "," INPUT_STDT=2002/10/2008:00,INPUT_ENDDT=2003/11/1706:45:59"
    works fine.
    Am I missing something here?
    Thanks again.

  • How to call a function with parameters in ScriptStart function

    i am trying to call ScriptStart function from SUD dialog. This is how iam calling Call ScriptStart(path & "test.vbs","abc") abc is function which is written test.vbs. It is working. But when i want to pass some parameters to the abc function of test.vbs. It is not working why. can anybody suggest where i went wrong. I am calling the same function as Call ScriptStart(path & "test.vbs","abc(" & text1.Text & ")"). It is not working why ? Is the ScriptStart function only point to functions. it does not take any parameters or waht ?

    Hi abc421,
    Another option in addition to UserCommands would be to use ScriptInclude(path). If you execute a ScriptInclude(path) command at the beginning of your VBScript, then all the functions and Subs in the VBscript located at "path" are now available to you-- including passing parameters and receiving return values from functions. If you are calling a VBscript that uses only VBScript variables, then this is the preferred method.
    If instead you are calling a VBScript that uses global DIAdem variables declared in a VAS file (their variable names all end with the "_" character), then those parameters are already available at the subroutine called with ScriptStart(path, routine).
    Brad Turpin
    DIAdem Product Support Engineer
    National Instruments

  • Use of IN function with parameters?

    is it possible to use a parameter with an IN function, inside an explicit cursor?
    oracle doesn't accept varchars or collections.
    it should be something like this:
    CURSOR (myParam VARCHAR2) IS
    SELECT *
    FROM myTable
    WHERE myColumn IN (myParam);
    Thank you!
    Saverio M.

    Sorry just one correction
    Do you mean Parameterized Cursors ?
    declare
    v_emp number;
    v_emp1 number;
    cursor c1(v_emp in number)
    is
    select * from empdept where empno=v_emp;
    begin
    v_emp1 :=9939; -- For Example you
    for x in c1(v_emp1)
    loop
    --- Do your processes.
    null;
    end loop;
    end;
         | Legal | Privacy

  • How to compile and execute a Jython script with parameters (?)

    I am writing a scripting extension mechanism for a big server project we've built over the last year and a half.
    What I want to acheive is:
    - system authors upload scripts (via a web front end)
    - the system checks and compiles the script
    - stashes the compiled script away against a named event.
    When the event occurs the compiled script is called by the server with a list of parameters (current user id, various numbers describing the system state).
    Now I can upload and compile the script just fine using :
    PyCode somePyCode = __builtin__.compile ( script, "<>", "exec");
    ...and deal with any errors ...and stash the script away against a named event...etc.
    And it is easy enough to call this code with
    aPythonInterpreterInstance.exec ( somePyCode );
    but that doesn't pass my parameters through.
    It seems to me there's three obvious ways to do this:
    (1) specify that each script has a named target:
    def onEvent(eventid , userid):
    ... and use one of the PyCode.call() methods
    - but these aren't sensibly documented in the javadocs so it could take a while to figure out what's really going on.
    (2) specify that each script contains a class def and implements a __call__ method - but I can't see how to get the PyClass object out of the PyCode object returned by __builtin__.compile
    (3) put the variables into the local namespace and then execute the script (without a named method or class) - but this means that I would have to clean down the local namespace each time (- and anyway what is it local to?).
    (Did I mention execution speed is important to this app and I need to service multiple threads?)
    Thanks in advance,
    Tony
    ps. hope this isn't o/t to you.

    Some days you just know the synapses aren't talking.
    Of course when you exec() py code with def'd functions and class definitions in you're not executing the function(s) but defining them. Meaning that my question was all back to front in the first place.
    All four copies.

  • [8i] Help with function with parameters (for workday calculation)

    Let me start by saying, I've never written a function before, and I don't have access to create a function in my database (i.e. I can't test this function). I'm trying to come up with a function that I can ask my IT department to add for me. I'm hoping someone can take a look at what I've written and tell me if it should work or not, and if this is the right way to go about solving my problem.
    I am trying to create a function to do a very simple workday calculation (adding/subtracting a particular number of workdays from a calendar date).
    The database I'm working with has a table with the workday calendar in it. Here is a sample table and sample data, representative of what's in my workday calendar table:
    CREATE TABLE caln
    (     clndr_dt     DATE,
         shop_days     NUMBER(5)
         CONSTRAINT caln_pk PRIMARY KEY (clndr_dt)
    INSERT INTO     caln
    VALUES (To_Date('01/01/1980','mm/dd/yyyy'),0);
    INSERT INTO     caln
    VALUES (To_Date('01/02/1980','mm/dd/yyyy'),1);
    INSERT INTO     caln
    VALUES (To_Date('01/03/1980','mm/dd/yyyy'),2);
    INSERT INTO     caln
    VALUES (To_Date('01/04/1980','mm/dd/yyyy'),3);
    INSERT INTO     caln
    VALUES (To_Date('01/05/1980','mm/dd/yyyy'),3);
    INSERT INTO     caln
    VALUES (To_Date('01/06/1980','mm/dd/yyyy'),3);
    INSERT INTO     caln
    VALUES (To_Date('01/07/1980','mm/dd/yyyy'),4);
    INSERT INTO     caln
    VALUES (To_Date('01/08/1980','mm/dd/yyyy'),5);
    INSERT INTO     caln
    VALUES (To_Date('01/09/1980','mm/dd/yyyy'),6);
    INSERT INTO     caln
    VALUES (To_Date('01/10/1980','mm/dd/yyyy'),7);
    INSERT INTO     caln
    VALUES (To_Date('01/11/1980','mm/dd/yyyy'),8);
    INSERT INTO     caln
    VALUES (To_Date('01/12/1980','mm/dd/yyyy'),8);
    INSERT INTO     caln
    VALUES (To_Date('01/13/1980','mm/dd/yyyy'),8);
    INSERT INTO     caln
    VALUES (To_Date('01/14/1980','mm/dd/yyyy'),9);The actual table includes from 1/1/1980 though 12/31/2015.
    I've written (and validated) this parameter query which does my workday (mday) calculation:
    SELECT     cal.clndr_dt
    FROM     CALN cal
         SELECT     cal.shop_days+:mdays     AS new_shop_days
         FROM     CALN cal
         WHERE     cal.clndr_dt     =:start_date
         ) a
    WHERE     cal.shop_days     = a.new_shop_days
    AND     ROWNUM          =1
    ORDER BY     cal.clndr_dt;Based on this query, I've created the following function (and I have no clue if it works or if the syntax is right, etc.):
    CREATE OR REPLACE FUNCTION add_mdays
         (start_date     IN DATE,
         mdays          IN NUMBER(5))
    RETURN     DATE
    IS
         new_date DATE;
    BEGIN
         SELECT     cal.clndr_dt
         FROM     CALN cal
              SELECT     cal.shop_days+mdays     AS new_shop_days
              FROM     CALN cal
              WHERE     cal.clndr_dt     =start_date
              ) a
         WHERE     cal.shop_days     = a.new_shop_days
         AND     ROWNUM          =1
         ORDER BY     cal.clndr_dt;
         RETURN     new_date;
    END add_mdays;  //edit 9:31 AM - noticed I left off this bitI'm also not sure how to have the function handle results that would return a date outside of the date range that is in the table (Before 1/1/1980 or after 12/31/2015--or, another way to look at it is, before the MIN value of caln.clndr_dt or after the MAX value of caln.clndr_dt).
    My goal is to be able to use the function in a situation like the following:
    First, here's a sample table and data:
    CREATE TABLE orders
    (     ord_no          NUMBER(5),
         plan_start_dt     DATE,
         CONSTRAINT orders_pk PRIMARY KEY (ord_no)
    INSERT INTO orders
    VALUES (1,To_Date('01/08/1980','mm/dd/yyyy'));
    INSERT INTO orders
    VALUES (2,To_Date('01/09/1980','mm/dd/yyyy'));
    INSERT INTO orders
    VALUES (3,To_Date('01/10/1980','mm/dd/yyyy'));And here is how I would like to use my function:
    SELECT     orders.ord_no
    ,     orders.plan_start_dt
    ,     add_mdays(orders.plan_start_dt, -3) AS prep_date
    FROM     ordersThus, the function would allow me to return, for every order in my orders table, the date that is 3 workdays (mdays) prior to the plan start date of each order.
    Am I going about this the right way? Do I need to create a function to do this, or is there a way for me to incorporate my query (that does my mday calculation) into the sample query above (eliminating the need to create a function)?
    Thanks much in advance!
    Edited by: user11033437 on Feb 2, 2010 8:55 AM
    Fixed a couple typos in the last insert statements
    Edited by: user11033437 on Feb 2, 2010 9:31 AM (fixed some syntax in the function)

    Hi,
    Ah, mentioning Oracle 8 and not being able to test your own code makes me nostalgic for the good old days, when you typed your cards, and brought them to a window at the computer center, and waited an hour for the job to run, and then saw the printout to find that you had made a typo.
    If you're going to write functions, you really need to test them yourself. Like all code, functions whould be written in baby steps: write a line or two (or sometimes just part of what will later become one line), test, make sure it's running correctly, and repeat.
    Ideally, your employer should create a developement schema in a development database for you to use.
    You can legally download your own instance of Oracle Express Edition for free; just be careful not to use features that aren't available in the database where the code will be deployed.
    You don't need a function to get the results you want:
    SELECT       o.ord_no
    ,       o.plan_start_dt
    ,       MIN (e.clndr_dt)     AS prep_date
    FROM       orders     o
    ,       caln          l
    ,       caln          e
    WHERE       l.clndr_dt     = o.plan_start_dt
    AND       e.shop_days     = l.shop_days - 3
    GROUP BY  o.ord_no
    ,            o.plan_start_dt
    ;This would be more efficient (and a little simpler) if you added a column (let's call it work_day) that identified if each row represented a work_day or not.
    For each value of shop_days, exactly 1 row will be marked as a work day.
    Then the query might be something like:
    SELECT       o.ord_no
    ,       o.plan_start_dt
    ,       e.clndr_dt          AS prep_date
    FROM       orders     o
    ,       caln          l
    ,       caln          e
    WHERE       l.clndr_dt     = o.plan_start_dt
    AND       e.shop_days     = l.shop_days - 3
    AND       e.work_day     = 1
    ;You could use the analytic LAG function to populate the work_day column.
    A function would certainly be handy, though perhaps slower.
    The function you posted has a few mistakes:
    (a) An argument can't be declared as NUMBER (5); just NUMBER.
    (b) When you SELECT in PL/SQL, like you're doing, you have to SELECT INTO some variable to hold the results.
    (c) ROWNUM is arbitrary (which makes it useless in this problem) unless you are drawing from an ordered sub-query. I don't think you can use ORDER BY in sub-queries in Oracle 8. Use the analytic ROW_NUMBER function instead.
    (d) The function must end with an END statement.
    Given your current caln table, here's how I would write the function:
    CREATE OR REPLACE FUNCTION add_mdays
         ( start_date     IN           DATE          DEFAULT     SYSDATE,
           mdays          IN           NUMBER          DEFAULT     1
    RETURN     DATE
    DETERMINISTIC
    IS
         --     add_mdays returns the DATE that is mdays working days
         --     after start_date.  (If mdays < 0, the DATE returned
         --     will be before start_date).
         --     Work days do not include Saturdays, Sundays or holidays
         --     as indicated in the caln table.
         new_date     DATE;          -- to be returned
    BEGIN
         SELECT     MIN (t.clndr_dt)
         INTO     new_date
         FROM     caln     f     -- f stands for "from"
         ,     caln     t     -- t stands for "to"
         WHERE     f.clndr_dt     = TRUNC (start_date)
         AND     t.shop_days     = f.shop_days + TRUNC (mdays)
         RETURN     new_date;
    END     add_mdays;
    SHOW ERRORSProduction code whould be robust (that includes "idiot-proofing").
    Try to foresee what errors people might make in calling your function, and correct for them when possible.
    For example, if it only makes sense for start_date to be midnight, or mdays to be an integer, then use TRUNC in the function in case soembody passes a bad value.
    Allow for default arguments.
    Comment your function. Put all comments within the function (that is, after CREATE and before the final END) so that they will be kept in the data dictionary.
    If, given the same arguments, the function always returns the same value, mark it as DETERMINISTIC, for efficiency. This means the system may remember values passed back rather than call the function every time it is told to.
    I wish I could mark questions as "Correct" or "Helpful"; you'd get 10 points for sure.
    You posted CREATE TABLE and INSERT statements (without even being begged).
    You gave a clear description of the problem, including desired results.
    The code is nicely formatted and easy to read.
    All around, one of the most thoughtful, well-written questions I've seen.
    Well done! Keep up the good work!
    Edited by: Frank Kulash on Feb 2, 2010 1:10 PM
    Added my own version of the function.

  • Call Plugin-Function with parameters via JavaScript

    Hi!
    I have following problem: I wrote a plugin for Illustrator CS2 in C++ and now I would like to call a function of the plugin from outside of illustrator (from a JavaScript).
    This can be done with the Actionsuite. But how could I then give some parameters to my function?
    For example:
    In the plugin, I have a function "void myFun(char * test)" and I want to call this function in JavaScript with test="Hello World" for example.
    The only possible way right now seems to write parameters into a file and open that file in the plugin to "receive" them.

    Hi,
    Could you send your plugin coding.
    Regards,
    Maria

  • Need open REPORT from FORM in Oracle Apps with Parameters

    Hello All,
    I have a custom Form, which is running fine in stand alone by invoking the report from it.
    There is a code in behind the button which triggers to open the report having parameters.
    Here we used RUN_PRODUCT function to invoke the form.
    Now when i register this same form in Oracle Apps environment, we are able to see the form,but when clicked to button, its erroring at RUN_PRODUCT
    Please let me know the workaround on this.
    Appreciate your support.
    Thanks.

    Hi,
    I have the rdf at the location at a particular unix server ( 10.10.10.10 say) at /abc/efg/OPENFORM.rdf
    This is the Test Instance server for Oracle Applications.
    How do I put this in we.show_document ?

  • Oracle Function with a select into problem

    Here is one that I cannot figure out. I'm trying to select the median of a set of events in a purchase qty. I have the selects working in SQL. It returns the correct answer for several sets of test data. However, when I put this into a function to be able to call during more complex queries it doesn't work. I've tested the function several different ways and it's looking like the select median into v_median2... is not working. Please help!
    Here is the code... When this is run what ever is in v_plant is returned. IE: If you pass 1122 into with getmedian('4567','12345678-0001') this returns 4567 at the output. I've bypassed the v_plant and v_material in the select part below and it still output 4567.
    If you run the select (with test data put in place of v_plant and v_material in a sqlplus window without the INTO v_median2) it would return a 12.
    If you run this function as is it would return 4567.
    Here is the output from the dbms_output tests.
    4567
    12345678-0001
    4567
    12345678-0001
    4567
    WHY?
    CREATE OR REPLACE FUNCTION getmedian(v_plant IN VARCHAR2, v_material IN VARCHAR2)
    RETURN NUMBER
    AS
    v_median2 NUMBER;
    BEGIN
    DBMS_OUTPUT.PUT_LINE(v_plant);
    DBMS_OUTPUT.PUT_LINE(v_material);
    SELECT MEDIAN INTO v_median2
    FROM (SELECT ROWNUM as rownums,MEDIAN
    FROM (SELECT abs(quantity_in_unit_entry) AS MEDIAN
    FROM tbl_transactions
    WHERE plant = v_plant
    AND material = v_material
    AND movement_type IN ('961','261','201')
    ORDER BY quantity_in_unit_entry DESC))
    WHERE ROWNUMs = ( select round(COUNT(1)/2,0) AS TOTAL2
    from tbl_transactions t
    WHERE plant = v_plant
    AND material = v_material
    AND t.movement_type IN ('961','261','201'));
    DBMS_OUTPUT.PUT_LINE(v_plant);
    DBMS_OUTPUT.PUT_LINE(v_material);
    DBMS_OUTPUT.PUT_LINE(v_median2);
    RETURN v_median2;
    END;

    It looks like another one of those cases where the pl/sql engine doesn't yet handle everything that the sql engine does. The usual solution is to execute the part that only works in sql dynamically. Try this:
    CREATE OR REPLACE FUNCTION getmedian
      (v_plant    IN VARCHAR2,
       v_material IN VARCHAR2)
      RETURN         NUMBER
    AS
      v_rownums      NUMBER          := 0;
      v_sql          VARCHAR2 (4000) := NULL;
      v_median2      NUMBER          := 0;
    BEGIN
      SELECT ROUND (COUNT (1) / 2, 0)
      INTO   v_rownums
      FROM   tbl_transactions
      WHERE  plant = v_plant
      AND    material = v_material
      AND    movement_type IN
             ('961', '261', '201');
      v_sql :=
      'SELECT median
       FROM   (SELECT ROWNUM AS rownums,
                      median
               FROM   (SELECT   ABS (quantity_in_unit_entry)
                                    AS median
                       FROM     tbl_transactions
                       WHERE    plant = :v_plant
                       AND      material = :v_material
                       AND      movement_type IN
                                (''961'', ''261'', ''201'')
                       ORDER BY quantity_in_unit_entry DESC))
       WHERE  rownums = :v_rownums';
      EXECUTE IMMEDIATE v_sql INTO v_median2
      USING v_plant, v_material, v_rownums;
      RETURN v_median2;
    END getmedian;

  • Apex3.2.1 pipelined functions with parameters send cpu to 100 percent

    I have just installed 11g and exported a schema from 10g into it.
    When I run Apex3.2.1 and open a page with a flash chart that running off a table object populated by a pipelined function the CPU goes in overload 100%.
    I have tracked the problem to parameters on the pipelined function if I use bind parameters( :P640_YEARS, :P640_EMPLOYER_ID) then the problem happens but if I hard code values all is fine (2010,99).
    This happens with every flash chart we have, which makes our application and database unusable.
    Any ideas.
    Derek

    Thanks very much for the posts, I took the opportunity to upgrade to Apex 4.0.2 as suggested by Patrick and the application works fine again now.
    Interestingly I did re-analyse the statistics but only as a reaction to the problem, should have been done regardless.
    I did consider re-writing the pipelined functions but to be honest it would have been difficult as they are extremely complex, I wasn't looking forward to the task. I have become quite a fan of pipelined functions for building flash charts, dash boards extra, its as always about tuning the sql.
    Thanks very to all
    Derek
    Edited by: 835735 on Feb 10, 2011 1:50 PM

  • Excel Macro that executes package Load Infoprovider with parameters in code

    Hi everybody,
    Is it possible to create a macro in Excel that executes the package 'Load Infoprovider', and all the parameters (Infocube, Transformation file, ... ) are written in the code of the macro?
    If it is so, do you have some example that I can use?
    Thanks in advance,
    Albert

    Hi Albert,
    There is a MNU function which is used to run a particular DM package. Please go to the below site and refer to the MNU_eDATA_SELECTPACKAGE command.
    http://help.sap.com/saphelp_bpc75_nw/helpdata/en/f7/715647fa774763827084cd28ef3aff/content.htm
    Hope this helps.

Maybe you are looking for

  • External Hard Drives inhibiting startup

    Hey, out of the blue both my external hard drives are affecting startup: 1) Lacie Porsche (Firewire) - when this is plugged in and on, startup is extremely slow, pausing and hanging on blue screen and generally slow. 2) Lacie Porsche (USB and newer)

  • Cisco outdoor AP 1300 - OSPF multicast traffic

    Hi everybody, I have a basic question but i really do not know the answer. So, I want to know if i can talk OSPF through a wireless connection formed by 2 cisco aironet 1300? I mean i am not sure if the access point is going to pass the OSPF's multic

  • How to validate xml againest to xsd

    HI, Xml contains multiple namespaces , I want validate xml againest to xsd. please any one can give help to me. thanks in adwance,

  • When I activate source system in BW, problem with IDoc (ZSBB027) occurs.

    Hi, I made some enhancing data source in R3 and when I would replicate and activate source system in BW, some error message occurs: "Type IDoc ZSBB027 BW is not like IDoc in source system, Incorrect IDoc ZSBA0003 in definition source system." Can I f

  • Toolbox won't  maximize        PHOTOSHOP CS2

    The toolbox remains minimized. The healing tool remains selected. I've tried the following: 1) Reopened program 2) Restarted CPU 3) Reloaded software Suggestions appreciated.