我们有一个Oracle存储过程,它接受表值参数
在包装说明中:
create or replace
PACKAGE CRUD_FIELDS IS
TYPE tableParam IS TABLE OF "owner".tablename.columnname%TYPE index by pls_integer;
TYPE Param_Array is table OF VARCHAR2(400) index by binary_integer;
PROCEDURE USP_GET_BULK_FIELDS ( pi_table_param tableParam, po_out_param out sys_refcursor);
包裹体:
PROCEDURE USP_GET_BULK_FIELDS ( pi_table_param tableParam, po_out_param
out sys_refcursor ) AS
Fields_Arr Param_Array;
trRec recFieldType;
trRecTable FieldRecTable := FieldRecTable();
n integer := 1;
arrIdx integer := 1;
BEGIN
for rul in 1..pi_table_param.count loop
for fld in (select ruleid, addlid, code from "owner"."T_FIELDS" where ruleid = pi_table_param(rul))
loop
trRecTable.extend;
trRec := recFieldType(fld.rule_id, fld.ADDL_ID, fld.field_code);
trRecTable(n):=trRec;
Fields_Arr(arrIdx):=fld.rule_id || ',' || fld.ADDL_ID|| ',' ||fld.field_code;
arrIdx := arrIdx + 1;
n := n + 1;
DBMS_OUTPUT.put_line (fld.rule_id || ',' || fld.ADDL_ID|| ',' ||fld.field_code );
end loop;
end loop;
FOR i IN trRecTable.FIRST .. trRecTable.LAST
LOOP
open po_out_param for
SELECT trRecTable(i).rule_id|| ',' || trRecTable(i).ADDL_ID|| ',' ||trRecTable(i).field_code FROM Table (Cast(trRecTable As FieldRecTable));
END LOOP;
DECLARE
CURSOR c1 IS select * from Table (Cast(trRecTable As FieldRecTable));
begin
FOR item IN c1
LOOP
DBMS_OUTPUT.PUT_LINE
('rule_id = ' || item.rule_id || ', ADDL_ID = ' || item.ADDL_ID || ', field_code = ' || item.field_code);
END LOOP;
end;
END USP_GET_BULK_FIELDS;
当我在Sql开发人员中执行此操作时,我得到了一个正确的结果: 我以这种方式执行
DECLARE
pi_table_param owner.CRUD_FIELDS.tableParam;
po_out_param sys_refcursor;
BEGIN
pi_table_param(1) := 154;
pi_table_param(2) := 153;
CRUD_FIELDS.USP_GET_BULK_FIELDS(
pi_table_param => pi_table_param,
po_out_param => po_out_param
);
END;
我得到的结果如下:
154,3,ABCD
154,4,TRS
154,5,EDR
155,34,TRE
155,5,EW
155,34,红
rule_id = 154,ADDL_ID = 3,field_code = ABCD
rule_id = 154,ADDL_ID = 4,field_code = TRS
rule_id = 154,ADDL_ID = 5,field_code = EDR
rule_id = 155,ADDL_ID = 34,field_code = TRE
rule_id = 155,ADDL_ID = 5,field_code = EW
rule_id = 155,ADDL_ID = 34,field_code = RED
我用C#编写了一个程序来获取值,但是我得到了一个奇怪的输出。
获取值的C#代码:
public void GetFieldsfoRules()
{
string connSt = ConfigurationManager.ConnectionStrings["QuickStarts Instance"].ConnectionString;
Oracle.DataAccess.Client.OracleConnection oraconnection = new Oracle.DataAccess.Client.OracleConnection(connSt);
oraconnection.Open();
Oracle.DataAccess.Client.OracleCommand cmd = oraconnection.CreateCommand();
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "CRUD_FIELDS.USP_GET_BULK_FIELDS";
Oracle.DataAccess.Client.OracleParameter oraparam = new Oracle.DataAccess.Client.OracleParameter();
Oracle.DataAccess.Client.OracleParameter oraParamOut = new Oracle.DataAccess.Client.OracleParameter();
oraparam.CollectionType = OracleCollectionType.PLSQLAssociativeArray;
oraparam.Size = 35;
oraparam.ParameterName = "pi_table_param";
oraparam.OracleDbType = OracleDbType.Int32;
oraparam.Value = new int[2] { 154, 155 };
oraparam.Direction = ParameterDirection.Input;
oraParamOut.ParameterName = "po_out_param";
oraParamOut.OracleDbType = OracleDbType.RefCursor;
oraParamOut.Value = 0;
oraParamOut.Direction = ParameterDirection.Output;
cmd.Parameters.Add(oraparam);
cmd.Parameters.Add(oraParamOut);
Oracle.DataAccess.Client.OracleDataAdapter oraadap = new Oracle.DataAccess.Client.OracleDataAdapter(cmd);
DataTable dt_getRules = new DataTable();
oraadap.Fill(dt_getRules);
dt_getRules.Load(dr);
cmd.Dispose();
oraconnection.Close();
}
数据表中填充了值:
155,34,红
155,34,红
155,34,红
155,34,红
155,34,红
155,34,RED
最后一行是覆盖其他值。这有什么不对?
答案 0 :(得分:0)
修正了它,实际上循环中的Select语句正在创建问题,因此修改了SP,如
FOR i IN trRecTable.FIRST .. trRecTable.LAST
LOOP
open po_out_param for
SELECT trRecTable(i).rule_id|| ',' || trRecTable(i).ADDL_ID|| ',' ||trRecTable(i).field_code FROM Table (Cast(trRecTable As FieldRecTable));
END LOOP;
注释掉了这一部分,并添加了以上一行:
uniform mat4 u_MVPMatrix[64];