Variable number of parameters to procedure

I have a requirement to pass variable number of parameters for an attribute, to a stored procedure.
example:
procedure getSum(country_code IN varchar2, sum OUT number)
Inside the procedure, I am currently
writing SQL as
where eligible_code in (country_code).
This is ok when I pass just one code.
However I need to deal with n number of
country codes at a given time.
i.e. if I want to pass 3 country codes
as a concatinated string say "A-B-C"
where A, B, C are 3 different codes,
how do I decode them into a
meaning full
where eligible_code in ('A', 'B', 'C')
Or is there any other way of dealing
with this kind of situation.
The bottom line is I must have a stored
procedure, that takes parameter(s).
Any input/suggestion is highly appreciated.

Please try the following, substituting the appropriate table name for your_table and the appropriate column name for eligible_code, then see if you can incorporate some of it into your procedure. Please let me know if it works for you or not.
SQL> EDIT getsum
CREATE OR REPLACE PROCEDURE getsum
(country_code IN VARCHAR2,
p_sum OUT NUMBER)
AS
v_country_codes VARCHAR2 (300);
v_sum NUMBER := 0;
v_sql_statement VARCHAR2 (3000);
v_sql_syntax VARCHAR2 (30000);
cursor_name INTEGER;
ignore INTEGER;
BEGIN
v_country_codes := REPLACE (country_code, '-', ''',''');
v_sql_statement := ' SELECT COUNT (*)
INTO :v_sum
FROM your_table
WHERE eligible_code IN (''' | | v_country_codes | | ''');';
v_sql_syntax := 'BEGIN '| | v_sql_statement | |' END;';
cursor_name := DBMS_SQL.OPEN_CURSOR;
DBMS_SQL.PARSE (cursor_name, v_sql_syntax, DBMS_SQL.NATIVE);
DBMS_SQL.BIND_VARIABLE (cursor_name, ':v_sum', v_sum);
ignore := DBMS_SQL.EXECUTE (cursor_name);
DBMS_SQL.VARIABLE_VALUE (cursor_name, ':v_sum', v_sum);
DBMS_SQL.CLOSE_CURSOR (cursor_name);
p_sum := v_sum;
END getsum;
Save the file.
SQL> START getsum
Procedure created.
SQL> VARIABLE g_sum NUMBER
SQL> EXEC getsum ('A-B-C', :g_sum)
PL/SQL procedure successfully completed.
SQL> PRINT g_sum
G_SUM
3
null

Similar Messages

  • Variable number of parameters in a procedure

    Hello !
    I have a form in a procedure with dynamic inputs type "checkbox" (one checkbox by record of a table).
    The action of the form is another procedure. There is a variable number of parameters (depending on checked inputs).
    How can I do for retreiving these variable data within a single variable in my second procedure ?
    Thanks for help and sample
    null

    What u can do is use Javascript and pass all the selected checkbox Ids as a dilimited string..which u can read in second procedure and can perform appropriate action. for example if you have check box named as chk1,chk2,chk3,chk4 n so on..
    now if chk1,chk3,chk4 are checked then pass this string in the hidden field "1|3|4"which is a |(pipe) delimited string..

  • Sequence Parameters: Can I use variable number of parameters?

    Can I create a sequence that has a variable number of parameters?
    If not, Can I pass an array of objects as a paramater?
    In the sequence code:
    for (i=0; i< Parameters.Params.GetNumElements(); i++) {
    object o = Parameters.Params[i];
    // Do something with o
    In the above case, can I call the sequence by putting a "new object[] {(double(2.0)}" as the parameter value?
    For example:
    call VarParams
    Params = PropertyObject.SetPropertyObject (Engine.NewPropertyObject (valueType, asArray, typeName, options))

    Not only can you pass an array of different sizes but you can also make a parameter an empty container and fill it with any container.  The problem is you have to access it correctly within the subsequence.  I can see a practical use for the Array but not really for the container.
    Your last question regarding creating params dynamically: I would have a local variable that is in the Value for the parameter and then just change the local to what you want in the PreExpression.
    Hope this helps,
    jigg
    CTA, CLA
    teststandhelp.com
    ~Will work for kudos and/or BBQ~

  • How to pass variable number of parameters to a FORM.

    Hi,
    What is the correct syntax to pass variable number of parameters to a subroutine?
    PERFORM TEST TABLES BRETURN USING TEST_NAME CHANGING MY_OUTPUT.
    FORM TEST TABLES RETURN STRUCTURE BAPIRET2
              ITAB STRUCTURE ITABLE_LINE OPTIONAL
              USING VALUE(NAME) TYPE STRING
              CHANGING VALUE(OUTPUT) TYPE STRING.
    The above code does not work. How can we specify an optional parameter?
    Thanks and Regards,
    Sheetal
    Message was edited by: Sheetal Pisolkar

    Hi,
    I am trying to use a subroutine instead of function.A FUNCTION understands optional keyword.
    How can this work for a FORM?
    CALL FUNCTION 'TEST'
         EXPORTING
              MY_OUTPUT = 'output'
         IMPORTING
              TEST_NAME = 'mytest'.     
    FUNCTION TEST
    *     EXPORTING
    *          VALUE(OUTPUT) TYPE STRING
    *     IMPORTING
    *          VALUE(NAME) TYPE STRING
    *     TABLES
    *          RETURN STRUCTURE BAPIRET2 OPTIONAL
    *          ITAB STRUCTURE ITABLE_LINE OPTIONAL          
    ENDFUNCTION.
    PERFORM TEST USING TEST_NAME CHANGING MY_OUTPUT.
    FORM TEST TABLES RETURN STRUCTURE BAPIRET2 OPTIONAL
    ITAB STRUCTURE ITABLE_LINE OPTIONAL
    USING VALUE(NAME) TYPE STRING
    CHANGING VALUE(OUTPUT) TYPE STRING.
    ENDFORM.
    Is this be possible?
    Thanks
    Sheetal.

  • Passing Variable Number of Parameters to Cobol Stored Procedure

    Hi. I have a web front end that needs to access several different tables via Cobol stored procedures. It seems simple enough to call the stored procedures straight away (DAO Pattern perhaps?) but my boss is insistent on having an intermediate Cobol program that decides which table to access. I think he at a bigger picture than I can see.
    The problem lies in the number of parameters that need to be passed to the stored procedures; some need 3, others needs 5, a few need 4. The only two solutions that I can think of are to pass EVERYTHING (we're talking 50 parameters or so) to the intermediate stored procedure and then pulling only what is needed from that data set to access the desired table. Solution number two involves passing everything to a temp table and then pulling what is needed from it. The former solution seems a little cleaner but still involves passing a lot of parameters. If Cobol could handle some sort of dynamic memory allocation (Vector) there seems to be a possible solution there. Though, as far as I know, that isn't possible.
    Any ideas are much appreciated.
    Thanks in advance,
    Chris

    Hi Saurabh,
    The method in which stored procedures are called on form submit is something as follows.
    Let us take your scenario of a form which has multiple checkboxes and a submit button. On clicking the submit button, this form data is submitted using either get or post. The form's submit action invokes a procedure.
    The HTML form code will look something like this..
    htp.formOpen( curl => 'URL /myProcedure',
    cmethod => 'post' );
    htp.formCheckbox( cname => 'myCheckbox'
    cvalue => 'A');
    htp.formCheckbox( cname => 'myCheckbox'
    cvalue => 'B');
    htp.formCheckbox( cname => 'myCheckbox'
    cvalue => 'C');
    htp.formSubmit( cname => 'myButton',
    cvalue => 'OK');
    Now, whenever the submit button is clicked, all these form values are passed to our stored procedure 'myProcedure'.
    "myProcedure" looks something like this.
    procedure myProcedure
    myCheckbox IN sys.owa_util.vc_arr,
    myButton IN VARCHAR2
    is
    begin
    end myProcedure;
    The point to be noted here is that the name of the variable being passed in the procedure is the same as the name of the HTML element being created in the HTML form. So, there is a direct mapping between the elements in the HTML form and the procedure parameters.
    Another noteworthy point is that since you have multiple checkboxes in your HTML form, it is impractical to name all the checkboxes differently and then pass those many parameters to your procedure (Imagine a scenario where there are a hundred check-boxes in an HTML form!). So portal allows you to give the same name (cname) to all the checkboxes in your HTML form, and if multiple checkboxes are checked, it will return all the checkbox values in an array (Note the usage of "myCheckbox IN sys.owa_util.vc_arr" in myProcedure).
    You can check out this link for more information.
    Re: retrieving data from fields
    Thanks,
    Ashish.

  • Variable number of arguments in procedure PL/SQL

    Hello everyone,
    I have a "simple" question : can a procedure PL/SQL take a variable number of arguments ?
    In my case, the procedure is called by the submit button of a form, and the form has variable number of inputs...
    Thanks you !

    862447 wrote:
    I have a "simple" question : can a procedure PL/SQL take a variable number of arguments ?No. Not in the style of Pascal and C/C++. E.g. int printf( char * format, … ) in C using va_list.
    In my case, the procedure is called by the submit button of a form, and the form has variable number of inputs...There are a couple of merhods.
    Code a fixed number of parameters in the procedure signature. Assign defaults to these. The caller can now select which parameters from the fixed list to use and which not.
    Create a structure. For example, having a 100 parameters in a signature is something I will call plain stupidity. This creates usability issues, maintenance issues and even performance issues. And debugging will be a nightmare. So instead create a structure (aka record in the PL/SQL language or an object using the SQL language) - where this structure describes (in a structured and logical way) the list of parameters.
    Neither of these method however allows the caller to pass a variable number parameters - the parameter signature is fixed. It has a fixed number of defined parameters.
    So the only way to simulate a variable parameter signature is to use a collection. The collection itself is of course a single parameter passed. But it can have 0 elements. It can have a 1000 elements. And similar to a va_list in C/C++, the procedure can iterate through the data passed via the parameter by the caller.
    Simple example:
    //-- define the collection type, e.g. a collection of strings
    create or replace type TStrings is table of varchar2(4000);The procedure's signature:
    --// passing by referencing and not value should be considered
    create or replace procedure FooProc( param TStrings ) is ..And to call this procedure with variable parameters:
    --// calling it with 2 param value
    FooProc( TString('123','testing') );
    --// calling it with 5 param values
    FooProc( TString('p1','p2','p3','p4','p5') );

  • How to pass more number of parameters in procedure

    How can we send 1000 parametrs in a procedure?
    is there any other method to pass parameters without defning 1000 parametrs
    Any example really helpful

    I know it's a hint, but have you ever known it to be ignored? Can you provide a working example showing it being ignored?Well it is not hard to demonstrate it being ignored, but these restrictions, while not obvious, are relatively well documented.
    What does not appear to be documented is the behaviour when calling from 3GLs (or does this qualify as an external procedure call?) where I believe the hint is also ignored.
    http://download-uk.oracle.com/docs/cd/B19306_01/appdev.102/b14261/tuning.htm#sthref2261
    "The use of NOCOPY increases the likelihood of parameter aliasing. For more information, see "Understanding Subprogram Parameter Aliasing".
    Remember, NOCOPY is a hint, not a directive. In the following cases, the PL/SQL compiler ignores the NOCOPY hint and uses the by-value parameter-passing method; no error is generated:
    1. The actual parameter is an element of an associative array. This restriction does not apply if the parameter is an entire associative array.
    2. The actual parameter is constrained, such as by scale or NOT NULL. This restriction does not apply to size-constrained character strings. This restriction does not extend to constrained elements or attributes of composite types.
    3. The actual and formal parameters are records, one or both records were declared using %ROWTYPE or %TYPE, and constraints on corresponding fields in the records differ.
    4. The actual and formal parameters are records, the actual parameter was declared (implicitly) as the index of a cursor FOR loop, and constraints on corresponding fields in the records differ.
    5. Passing the actual parameter requires an implicit datatype conversion.
    6. The subprogram is called through a database link or as an external procedure."
    For example, consider rule #2 above and compare output of first block (with unconstrained NUMBER datatype) with second (with constrained NUMBER datatype).
    Oracle Database 10g Express Edition Release 10.2.0.1.0 - Production
    SQL> SET SERVEROUTPUT ON;
    SQL> <<anonymous_block>>
      2  DECLARE
      3     variable_name NUMBER := 0;
      4
      5     PROCEDURE procedure_name (
      6        parameter_name   IN OUT NOCOPY   NUMBER)
      7     IS
      8     BEGIN
      9        dbms_output.put_line ('#2 variable_name => ' || variable_name);
    10        parameter_name := parameter_name + 1;
    11        dbms_output.put_line ('#3 variable_name => ' || variable_name);
    12     END procedure_name;
    13  BEGIN
    14     dbms_output.put_line ('#1 variable_name => ' || variable_name);
    15     procedure_name (variable_name);
    16     dbms_output.put_line ('#4 variable_name => ' || variable_name);
    17  END anonymous_block;
    18  /
    #1 variable_name => 0
    #2 variable_name => 0
    #3 variable_name => 1
    #4 variable_name => 1
    PL/SQL procedure successfully completed.
    SQL> <<anonymous_block>>
      2  DECLARE
      3     variable_name NUMBER (10) := 0;
      4
      5     PROCEDURE procedure_name (
      6        parameter_name IN OUT NOCOPY NUMBER)
      7     IS
      8     BEGIN
      9        dbms_output.put_line ('#2 variable_name => ' || variable_name);
    10        parameter_name := parameter_name + 1;
    11        dbms_output.put_line ('#3 variable_name => ' || variable_name);
    12     END procedure_name;
    13  BEGIN
    14     dbms_output.put_line ('#1 variable_name => ' || variable_name);
    15     procedure_name (variable_name);
    16     dbms_output.put_line ('#4 variable_name => ' || variable_name);
    17  END anonymous_block;
    18  /
    #1 variable_name => 0
    #2 variable_name => 0
    #3 variable_name => 0
    #4 variable_name => 1
    PL/SQL procedure successfully completed.
    SQL>

  • Variable number of document info record parameters

    Hi guys,
    I have a question about adding additional information to document info record.
    The situation is following:
    Our customer wants us to link original purchase order (PDF file) with it's document info record in SAP. The document itself is stored in another document management system and we have succeeded in linking this object with it's document info record in SAP.
    He also wants to have some description data stored in document info record (date, description, name, etc). One odd requirement is copying information about cost centers and costs per each cost center from fields in document management system to some fields in document info record.
    The problem is that each purchase order can have various number of cost centers and costs per each cost center!
    So, is there any possibility to define some fields in document info record to which I can store variable number of parameters (for example in one case 3 fields, and maybe in another case 1 field)?
    Any kind of information will be valuable for me!
    Thanks for help!

    Hi,
    But my next question is how can I know how much cost centers will be for some document? If I need to define number of cost centers in advance, then this solution is not very flexible. The best solution would be if I could add values to classification flexibly (for example: one time 3 values and the other time 1 value).
    :-Check box additional values in values tab of char. that will allow to enter flexible number of values any time
    The other question is about values of parameters. For each cost center I need to enter two values (cost center number, and costs for that cost center). So, for each cost center I need to add 2 values. Is that possible using classification?
    :-Create classification with chara. cost center, cost center value and check box additional values as above that will allow you to add values for cost center and cost center value.
    Anirudh.

  • Variable list of parameters in PL/SQL functions

    As I know, PL/SQL decode function can be called with
    variable number of parameters:
    decode (a, b, c);
    decode (a, b, c, d, e);
    decode (a, b, c, d, e, f, g);
    How is is possible to implement a PL/SQL procedure or function like decode, which is usable with a variable list
    of arguments.
    Is there another way instead of using overloading?
    Thanks in advance
    Stefan Richter

    Implement it with the IF..ELSIF condition.

  • How to create a dynamic query in which I can vary number of parameters

    I am writing a JDBC connector. I want to write a dynamic query in that. The query should be able to proceed variable number of parameters and also in the where clause the and/or/like parameters I want to place dynamically.
    I can't write store procedures as we just have read only access to Database so I want to do it through query only.
    Please help me out in doing that as I am not able to proceed further without it ...

    Hi,
    Have a luk at :placeholder for IN condition in database adapter

  • PreparedStatement - unknown number of parameters

    Help!
    I have to use PreparedStatement to access an oracle database. This statement should be able to handle a number of values for one parameter. For example the parameter is area and there is a number of counties the user can choose...
    So i have a query statment like
    select population from populatn where area IN('BEAVER', 'CACHE'......)
    Here how do I use preparedstatement?
    Sue

    Yeah, that's always what they mean when they ask the
    question. The answer is still no.right. when you have a variable number of parameters than you don't have a prepared statement anymore.
    however if you want to get information about a prepared statement's parameters you can use getParameterMetaData method of PreparedStatement new in 1.4.

  • Passing variable number of arguments in a stored procedure

    Hi Team,
    i am facing a problem. I have a dynamic form which contains some checkboxes. The number of checkboxes are dynamically generated on querying the database. On the form submission i want to call a stored procedure that will update the values in the database. i want to know that is there any way to handle variable number of arguments in the stored procedure or can i get the variables through some session context and use it in my stored procedure.
    Any help is greatly appreciated.
    Thanks&Regards
    Saurabh Jain

    Hi Saurabh,
    The method in which stored procedures are called on form submit is something as follows.
    Let us take your scenario of a form which has multiple checkboxes and a submit button. On clicking the submit button, this form data is submitted using either get or post. The form's submit action invokes a procedure.
    The HTML form code will look something like this..
    htp.formOpen( curl => 'URL /myProcedure',
    cmethod => 'post' );
    htp.formCheckbox( cname => 'myCheckbox'
    cvalue => 'A');
    htp.formCheckbox( cname => 'myCheckbox'
    cvalue => 'B');
    htp.formCheckbox( cname => 'myCheckbox'
    cvalue => 'C');
    htp.formSubmit( cname => 'myButton',
    cvalue => 'OK');
    Now, whenever the submit button is clicked, all these form values are passed to our stored procedure 'myProcedure'.
    "myProcedure" looks something like this.
    procedure myProcedure
    myCheckbox IN sys.owa_util.vc_arr,
    myButton IN VARCHAR2
    is
    begin
    end myProcedure;
    The point to be noted here is that the name of the variable being passed in the procedure is the same as the name of the HTML element being created in the HTML form. So, there is a direct mapping between the elements in the HTML form and the procedure parameters.
    Another noteworthy point is that since you have multiple checkboxes in your HTML form, it is impractical to name all the checkboxes differently and then pass those many parameters to your procedure (Imagine a scenario where there are a hundred check-boxes in an HTML form!). So portal allows you to give the same name (cname) to all the checkboxes in your HTML form, and if multiple checkboxes are checked, it will return all the checkbox values in an array (Note the usage of "myCheckbox IN sys.owa_util.vc_arr" in myProcedure).
    You can check out this link for more information.
    Re: retrieving data from fields
    Thanks,
    Ashish.

  • Procedure with variable number of columns

    Hi, I have a procedure that looks like this:
    PROCEDURE PROC(p_cursor OUT sys_refcursor)
    And in the procedure, I build up QUERY dynamically and the number of columns varies at runtime.
    At the end I do
    OPEN p_cursor for QUERY
    Then to call this, I'm doing
    call PROC(?)
    My question is, how would I go about running the query from this procedure, then adding rows or modifying the existing results, then returning the modified data?
    What I want to do is add a new row based on some condition, so I still need to return a variable number of columns, but I need to modify the results before I return them.
    Is there any way of doing this? I need to do some calculations on the columns (the variable columns), create a new row, insert into result set, and return this new result set.

    A sys_refcursor is ideally suited to pass back to a front end gui like .NET or Java which can then use that cursor to retrieve the data.
    In PL/SQL there is no point in using a sys_refcursor unless you know, at design/compile time what the returned columns are going to be.
    If the resultant columns are dynamic, then you have no choice but to use the DBMS_SQL package, where you can parse and execute any SQL statement you like and then use the DBMS_SQL package to describe what the resultant columns are and how many there are. From that you can reference the columns by position rather than by name.
    e.g.
    CREATE OR REPLACE PROCEDURE run_query(p_sql IN VARCHAR2) IS
      v_v_val     VARCHAR2(4000);
      v_n_val     NUMBER;
      v_d_val     DATE;
      v_ret       NUMBER;
      c           NUMBER;
      d           NUMBER;
      col_cnt     INTEGER;
      f           BOOLEAN;
      rec_tab     DBMS_SQL.DESC_TAB;
      col_num     NUMBER;
      v_rowcount  NUMBER := 0;
    BEGIN
      -- create a cursor
      c := DBMS_SQL.OPEN_CURSOR;
      -- parse the SQL statement into the cursor
      DBMS_SQL.PARSE(c, p_sql, DBMS_SQL.NATIVE);
      -- execute the cursor
      d := DBMS_SQL.EXECUTE(c);
      -- Describe the columns returned by the SQL statement
      DBMS_SQL.DESCRIBE_COLUMNS(c, col_cnt, rec_tab);
      -- Bind local return variables to the various columns based on their types
      FOR j in 1..col_cnt
      LOOP
        CASE rec_tab(j).col_type
          WHEN 1 THEN DBMS_SQL.DEFINE_COLUMN(c,j,v_v_val,2000); -- Varchar2
          WHEN 2 THEN DBMS_SQL.DEFINE_COLUMN(c,j,v_n_val);      -- Number
          WHEN 12 THEN DBMS_SQL.DEFINE_COLUMN(c,j,v_d_val);     -- Date
        ELSE
          DBMS_SQL.DEFINE_COLUMN(c,j,v_v_val,2000);  -- Any other type return as varchar2
        END CASE;
      END LOOP;
      -- Display what columns are being returned...
      DBMS_OUTPUT.PUT_LINE('-- Columns --');
      FOR j in 1..col_cnt
      LOOP
        DBMS_OUTPUT.PUT_LINE(rec_tab(j).col_name||' - '||case rec_tab(j).col_type when 1 then 'VARCHAR2'
                                                                                  when 2 then 'NUMBER'
                                                                                  when 12 then 'DATE'
                                                         else 'Other' end);
      END LOOP;
      DBMS_OUTPUT.PUT_LINE('-------------');
      -- This part outputs the DATA
      LOOP
        -- Fetch a row of data through the cursor
        v_ret := DBMS_SQL.FETCH_ROWS(c);
        -- Exit when no more rows
        EXIT WHEN v_ret = 0;
        v_rowcount := v_rowcount + 1;
        DBMS_OUTPUT.PUT_LINE('Row: '||v_rowcount);
        DBMS_OUTPUT.PUT_LINE('--------------');
        -- Fetch the value of each column from the row
        FOR j in 1..col_cnt
        LOOP
          -- Fetch each column into the correct data type based on the description of the column
          CASE rec_tab(j).col_type
            WHEN 1  THEN DBMS_SQL.COLUMN_VALUE(c,j,v_v_val);
                         DBMS_OUTPUT.PUT_LINE(rec_tab(j).col_name||' : '||v_v_val);
            WHEN 2  THEN DBMS_SQL.COLUMN_VALUE(c,j,v_n_val);
                         DBMS_OUTPUT.PUT_LINE(rec_tab(j).col_name||' : '||v_n_val);
            WHEN 12 THEN DBMS_SQL.COLUMN_VALUE(c,j,v_d_val);
                         DBMS_OUTPUT.PUT_LINE(rec_tab(j).col_name||' : '||to_char(v_d_val,'DD/MM/YYYY HH24:MI:SS'));
          ELSE
            DBMS_SQL.COLUMN_VALUE(c,j,v_v_val);
            DBMS_OUTPUT.PUT_LINE(rec_tab(j).col_name||' : '||v_v_val);
          END CASE;
        END LOOP;
        DBMS_OUTPUT.PUT_LINE('--------------');
      END LOOP;
      -- Close the cursor now we have finished with it
      DBMS_SQL.CLOSE_CURSOR(c);
    END;
    SQL> exec run_query('select empno, ename, deptno, sal from emp where deptno = 10');
    -- Columns --
    EMPNO - NUMBER
    ENAME - VARCHAR2
    DEPTNO - NUMBER
    SAL - NUMBER
    Row: 1
    EMPNO : 7782
    ENAME : CLARK
    DEPTNO : 10
    SAL : 2450
    Row: 2
    EMPNO : 7839
    ENAME : KING
    DEPTNO : 10
    SAL : 5000
    Row: 3
    EMPNO : 7934
    ENAME : MILLER
    DEPTNO : 10
    SAL : 1300
    PL/SQL procedure successfully completed.
    SQL> exec run_query('select * from emp where deptno = 10');
    -- Columns --
    EMPNO - NUMBER
    ENAME - VARCHAR2
    JOB - VARCHAR2
    MGR - NUMBER
    HIREDATE - DATE
    SAL - NUMBER
    COMM - NUMBER
    DEPTNO - NUMBER
    Row: 1
    EMPNO : 7782
    ENAME : CLARK
    JOB : MANAGER
    MGR : 7839
    HIREDATE : 09/06/1981 00:00:00
    SAL : 2450
    COMM :
    DEPTNO : 10
    Row: 2
    EMPNO : 7839
    ENAME : KING
    JOB : PRESIDENT
    MGR :
    HIREDATE : 17/11/1981 00:00:00
    SAL : 5000
    COMM :
    DEPTNO : 10
    Row: 3
    EMPNO : 7934
    ENAME : MILLER
    JOB : CLERK
    MGR : 7782
    HIREDATE : 23/01/1982 00:00:00
    SAL : 1300
    COMM :
    DEPTNO : 10
    PL/SQL procedure successfully completed.
    SQL> exec run_query('select * from dept where deptno = 10');
    -- Columns --
    DEPTNO - NUMBER
    DNAME - VARCHAR2
    LOC - VARCHAR2
    Row: 1
    DEPTNO : 10
    DNAME : ACCOUNTING
    LOC : NEW YORK
    PL/SQL procedure successfully completed.
    SQL>In 11g, you can create a sys_refcursor and then the DBMS_SQL package allows you to convert that refcursor into a DBMS_SQL cursor so that you can get the description of the results and do the same. This isn't available prior to 11g though.
    However_ before any of that, you should really ask yourself if there is a real need to dynamically be creating queries. There is rarely any real need to do that and if you're finding it's common in your application then this is often a sign of poor design or poorly defined business requirements (leaving the technical side to try and be "flexible" and hence leading to unmaintainable code etc.).

  • How do I submit to procedure with a variable number of controls in portlet?

    I need to submit to a stored procedure but my portlet has a variable number of controls. How do I do this?
    In the past I have always had an input parameter for each control. In this case the number of controls vary at runtime. Is there a way to submit to a procedure that takes some type of array of controls as an input parameter.
    Don

    Another way to do this is to apply a gradient for the background of your block.
    If you place the blue at 40% and the white at the same percentage, the transition is abrupt and looks like what you need.
    Here is an exemple, where the cyan marker is hidden behind the white one in the gradient.
    Of course, if you use something like that, you must have one object style for each height as the bar will move with the frame.
    emmanuel

  • Why 'wrong number of parameters' error in this call to a stored procedure?

    A stored procedure exists that inserts a new record and returns the newly generated record ID. This stored procedure is called from a WinForms application but at the ExecuteNonQuery time an exception is thrown indicating that the wrong number of parameters
    has been supplied. If I take out the one parameter that is marked as ParameterDirection.Output then the ExecuteNonQuery does not throw an exception.
    CREATE PROCEDURE [dbo].[API_InsertIntoManu]
    @Name nvarchar(50),
    @Description nvarchar(2000)
    AS
    SET NOCOUNT ON
    INSERT INTO Manu (
    [Name],
    [Description]
    VALUES (
    @Name,
    @Description
    SELECT SCOPE_IDENTITY() As InsertedID
    END
    GO
    The C# code that calls the above SP looks like this:
    using (SqlConnection conn = new SqlConnection( "<snipped>" ))
    using (SqlCommand cmd = new SqlCommand( "[dbo].[API_InsertIntoManu]", conn ))
    cmd.CommandType = CommandType.StoredProcedure;
    cmd.Parameters.Add( Name, SqlDbType.NVarChar, 50 ).Value = "some name";
    cmd.Parameters.Add( Title, SqlDbType.NVarChar, 200 ).Value = "some title";
    // This parameter is supposed to receive the new row's ID but instead triggers a 'wrong number of args' exception.
    cmd.Parameters.Add( "InsertedID",SqlDbType.Int ).Direction = ParameterDirection.Output;
    conn.Open();
    // This is where the exception gets thrown.
    cmd.ExecuteNonQuery();
    iReturn = (int)cmd.Parameters[InsertedID].Value;
    Richard Lewis Haggard

    In you sp the size of Title var is 2000 and not 200, correct this:
    cmd.Parameters.Add( "@Title", SqlDbType.NVarChar, 200 ).Value
    Fouad Roumieh

Maybe you are looking for

  • Project Server 2013 - This webpart was unable to load

    Hi all, I am getting the following error in project server 2013 project sites: This webpart was unable to load. For more information, please contact your server administrator. <Guid> I only get this error message on 'Project Summary Web Part'. Any id

  • Arch Linux Partitions And Filesystems

    Hi everyone! I'm pretty much new to Linux having used Ubuntu about 2 years back. Recently I've been looking to get a better understanding of the system and wanted to try out a different distro. I searched around and came across Arch. I really liked t

  • FCE Won't open - crashes everytime

    I am having a dilemma with FCE and FCP. I was having issues with Quicktime 7.4.1 so I used Pacifist to overide it with quicktime 7.2. After I did that, I was unable to open FCE or FCP they crash before they open. I went back in and re-loaded Quicktim

  • Blank browser page when viewing html/swf exported from Indesign

    We've created a 'flip book' in Indesign and exported it as a swf and html docs. These docs both view correctly locally, but when uploaded into the same directory on our server and viewed via safari or chrome, they both appear as blank browser pages.

  • Airport Express shutting down by itself

    My AirPort Express is still shutting down by itself after using it for a while! I get a connection from my MacBook Pro for a while (green light), afterwards the LED is yellow and my Mac can not find the AirPort station anymore. So I restart the AirPo