pass array to oracle procedure

前端 未结 6 1380
孤街浪徒
孤街浪徒 2020-11-27 17:36

I want to send two arrays form java to oracle stored procedures. The first Array is array of strings and the second is array of chars how can I make this??

6条回答
  •  野趣味
    野趣味 (楼主)
    2020-11-27 18:06

    PeudoCode for the same how I achieved.

        # 1.You will require a structDescriptor object for an object equivalent in pl sql like :
    
        StructDescriptor structDes= new StructDescriptor(".", connectionObject);
    
        # 2. You will need to pass one object values such name, class, id to an object array in order and accordance to 'sql_object_name' object. 
    
        For exmaple:
        STRUCT[] structArray=new STRUCT[.size()];
        int index=0;
        for (a in ListObj){
    
        Object[] object=new Object[]{a.getName(),a.getId()};
        STRUCT struct=new STRUCT(structDes ,connectionObject,object);
                   structArray[index]=struct;
                   index++;
    
        }
    
        ArrayDescriptor arrayDes=ArrayDescriptor.createDescriptor(
            ".", connectionObject);
    
        ARRAY array=new ARRAY(arrayDes,connectionObject, structArray);
    
       then pass it to proc 
    
       .declareParameters(
       new SqlInOutParameter("",OracleTypes.ARRAY,"
       ."))
    
       like 
       Hashmap map= new HashMap<>();
       map.put("",array);
       psStatement.execute(map);
    
    
    

    Hope it helps. This sequence may vary as per requirement and type of sql database used, but base is same.

    I have copied this answer from one of my other answers.

    Pass array as input parameter to an oracle stored procedure using simple jdbc call

    提交回复
    热议问题