Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3800516
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T13:54:18+00:00 2026-05-19T13:54:18+00:00

I have written this package CREATE OR REPLACE PACKAGE CURVES AS type t_forecast_values is

  • 0

I have written this package

CREATE OR REPLACE 
PACKAGE CURVES AS 
  type t_forecast_values is table of test.column2%TYPE index by varchar(20);
  assoc_array t_forecast_values;
  procedure sp_insert (param1 in varchar2, param2 in number);
END CURVES;

create or replace
package body curves as
  procedure sp_insert (param1 in varchar2, param2 in number) as
  begin
    assoc_array(param1) := param2;
    DECLARE primarykey NUMBER(10);
    BEGIN
      FOR i IN 1..2
      LOOP
        SELECT seq_curves.nextval INTO primarykey FROM dual;
        INSERT INTO TEST (column1, column2, column3)
        VALUES (primarykey, param1, assoc_array(param1));

        INSERT INTO TEST2 (column1, column2)
        VALUES (primarykey, 'default');
      END LOOP ;
    END;
  end sp_insert;
end curves;

I call the procdedure through this c# code:

class Program
    {
        private static string connString = @"User Id=User; Password=root; Data Source=SOURCE";

        private static List<string> forecast_types = new List<string> { "a", "b" };
        private static List<double> forecast_values = new List<double> { .1, .2 };

        static void Main(string[] args)
        {
            using (var con = new OracleConnection(connString))
            {
                string query = "BEGIN curves.sp_insert(:forecast_types, :forecast_values); END;";

                try
                {
                    con.Open();

                    using (OracleCommand cmd = con.CreateCommand())
                    {
                        cmd.CommandText = query;
                        cmd.CommandType = CommandType.Text;
                        cmd.BindByName = true;

                        cmd.Parameters.Add(new OracleParameter
                            {
                                ParameterName = ":forecast_types",
                                OracleDbType = OracleDbType.Varchar2,
                                Value = forecast_types.ToArray(),
                                Direction = ParameterDirection.Input,
                                CollectionType = OracleCollectionType.PLSQLAssociativeArray
                            }
                        );
                        cmd.Parameters.Add(new OracleParameter
                        {
                            ParameterName = ":forecast_values",
                            OracleDbType = OracleDbType.Double,
                            Value = forecast_values.ToArray(),
                            Direction = ParameterDirection.Input,
                            CollectionType = OracleCollectionType.PLSQLAssociativeArray
                        }
                        );

                        cmd.ExecuteNonQuery();
                    }
                }
                catch (System.Exception ex)
                {
                    System.Console.WriteLine(ex);
                }
                finally
                {
                    con.Close();
                }
            }
        }
    }

i get the following error:

Oracle.DataAccess.Client.OracleException ORA-06550: line 1, column 7: 
PLS-00306: wrong number or types of arguments in call to 'SP_INSERT'
ORA-06550: line 1, column 7:
PLS-00306: wrong number or types of arguments in call to 'SP_INSERT'
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored at     Oracle.DataAccess.Client.OracleException.HandleErrorHelper(Int32 errCode, OracleConnection conn, IntPtr opsErrCtx, OpoSqlValCtx* pOpoSqlValCtx, Object src, String procedure, Boolean bCheck)
   at Oracle.DataAccess.Client.OracleException.HandleError(Int32 errCode, OracleConnection conn, String procedure, IntPtr opsErrCtx, OpoSqlValCtx* pOpoSqlValCtx, Object src, Boolean bCheck)
   at Oracle.DataAccess.Client.OracleCommand.ExecuteNonQuery()
   at OracleTest.Program.Main(String[] args) in \\comp\user$\Visual Studio 2010\Projects\OracleTest\OracleTest\Program.cs:line 57

I have no idea to resolve the problem, yet. Any help is appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T13:54:19+00:00Added an answer on May 19, 2026 at 1:54 pm

    Your package is not accepting a PLSQL Associative array, but rather single elements. What you are trying to do, I believe, is do an array insert (which is pretty much packaging up in C# your code X times and bulk sending it to the database to do the work)

    this link directly describes what you want to do:
    http://www.oracle.com/technology/sample_code/tech/windows/odpnet/howto/arraybind/index.html

    (I made a few changes to your code, namely

    1. removed the pl/sql assoc. array para type
    2. added ArrayBindCount
    3. You were using an anonymous block, changed this to a stored procedure call

    1 & 2 should fix your problem, while #3 is more of syntactic sugar

    however, this code is untested but out to work

    class Program
        {
            private static string connString = @"User Id=User; Password=root; Data Source=SOURCE";
    
            private static List<string> forecast_types = new List<string> { "a", "b" };
            private static List<double> forecast_values = new List<double> { .1, .2 };
    
            static void Main(string[] args)
            {
                using (var con = new OracleConnection(connString))
                {
                    //string query = "BEGIN curves.sp_insert(:forecast_types, :forecast_values); END;";
                    string query = "curves.sp_insert";
    
                    try
                    {
                        con.Open();
    
                        using (OracleCommand cmd = con.CreateCommand())
                        {
                            cmd.CommandText = query;
                            cmd.CommandType = CommandType.StoredProcedure; // CommandType.Text; //you can change this to a stored procedure and not utilize the anonymous block
    
                            cmd.ArrayBindCount = 2; //use ArrayBindCount
    
                            cmd.BindByName = true;
    
                         cmd.Parameters.Add(new OracleParameter
                            {
                                ParameterName = ":forecast_types",
                                OracleDbType = OracleDbType.Varchar2,
                                Value = forecast_types.ToArray(),
                                Direction = ParameterDirection.Input,
                                //CollectionType = OracleCollectionType.PLSQLAssociativeArray //this is not needed
                            }
                        );
                        cmd.Parameters.Add(new OracleParameter
                        {
                            ParameterName = ":forecast_values",
                            OracleDbType = OracleDbType.Double,
                            Value = forecast_values.ToArray(),
                            Direction = ParameterDirection.Input,
                            //CollectionType = OracleCollectionType.PLSQLAssociativeArray  //this is not needed
                        }
                            );
    
                            cmd.ExecuteNonQuery();
                        }
                    }
                    catch (System.Exception ex)
                    {
                        System.Console.WriteLine(ex);
                    }
                    finally
                    {
                        con.Close();
                    }
                }
            }
        }
    

    EDIT


    I did notice that you did try to pass in an associative array (I see the creation of the type of the looping within the procedure).

    This is not too difficult to do either.
    On that note you are on the correct track.

    you’ll need to change the package to have assoc. arrays passed in via params
    CREATE OR REPLACE
    PACKAGE CURVES AS
    type t_forecast_values is table of test.column2%TYPE index by varchar(20);
    assoc_array t_forecast_values;

      --need to create an assoc.array for numbers
      type t_numbera_values is table of test.column2%TYPE index by number(10);
    
      --changed to accept the assoc.array to varchar and numbers
      procedure sp_insert (param1 in t_forecast_values, param2 in t_numbera_values);
    END CURVES;
    
    create or replace
    PACKAGE BODY CURVES AS
      --changed to accept the assoc.array to varchar and numbers
      PROCEDURE SP_INSERT (PARAM1 IN T_FORECAST_VALUES, PARAM2 IN T_NUMBERA_VALUES) AS
      BEGIN
        --assoc_array(param1) := param2; /*not sure what the intent of this was...*/
        DECLARE PRIMARYKEY NUMBER(10);
        BEGIN
          FOR i IN PARAM1.first .. PARAM1.last
          LOOP
            SELECT seq_curves.nextval INTO primarykey FROM dual;
            INSERT INTO TEST (COLUMN1, COLUMN2, COLUMN3)
            VALUES (primarykey, PARAM1(i), PARAM2(i));
    
            INSERT INTO TEST2 (column1, column2)
            VALUES (PRIMARYKEY, 'default');
          END LOOP ;
          --assuming you are going to add error handling here
        END;
      end sp_insert;
    END CURVES;
    

    and you will need to add a size param to the param list as such

    class Program
        {
            private static string connString = @"User Id=User; Password=root; Data Source=SOURCE";
    
            private static List<string> forecast_types = new List<string> { "a", "b" };
            private static List<double> forecast_values = new List<double> { .1, .2 };
    
            static void Main(string[] args)
            {
                using (var con = new OracleConnection(connString))
                {
                    string query = "curves.sp_insert";
    
                    try
                    {
                        con.Open();
    
                        using (OracleCommand cmd = con.CreateCommand())
                        {
                            cmd.CommandText = query;
                            cmd.CommandType = CommandType.StoredProcedure;
                            cmd.BindByName = true;
    
                            cmd.Parameters.Add(new OracleParameter
                                {
                                    ParameterName = "param1",
                                    OracleDbType = OracleDbType.Varchar2,
                                    Value = forecast_types.ToArray(),
                                    Direction = ParameterDirection.Input,
                                    CollectionType = OracleCollectionType.PLSQLAssociativeArray,
                                    Size = 2
                                }
                            );
                            cmd.Parameters.Add(new OracleParameter
                            {
                                ParameterName = "param2",
                                OracleDbType = OracleDbType.Double,
                                Value = forecast_values.ToArray(),
                                Direction = ParameterDirection.Input,
                                CollectionType = OracleCollectionType.PLSQLAssociativeArray,
                                Size = 2                            
                            }
                            );
    
                            cmd.ExecuteNonQuery();
                        }
                    }
                    catch (System.Exception ex)
                    {
                        System.Console.WriteLine(ex);
                    }
                    finally
                    {
                        con.Close();
                    }
                }
            }
        }
    

    to get a great example of this goto
    ORACLE_HOME\odp.net\samples\2.x\AssocArray\AssocArray.cs
    it does exactly what you like

    all of the above code is untested but should get you on the correct track, either from array binding (first example) or passing in the pl/sql array (second example)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.