Oracle
 sql >> база данни >  >> RDS >> Oracle

Съпоставяне на потребителски тип на Oracle UDT за не е посочено или е невалидно

Опитах просто отиване и връщане и изглежда всичко работи добре.

void Main()
{
    using (var connection = new OracleConnection("DATA SOURCE=HQ_PDB_TCP;PASSWORD=oracle;USER ID=HUSQVIK"))
    {
        connection.Open();

        using (var command = connection.CreateCommand())
        {
            command.CommandText = "DECLARE i SYS.ODCICOST := :p; BEGIN :p := SYS.ODCICOST(i.CPUCOST + 1, i.IOCOST + 1, i.NETWORKCOST + 1, i.INDEXCOSTINFO || 'Dummy'); END;";
            command.BindByName = true;

            var parameter = command.CreateParameter();
            parameter.Direction = ParameterDirection.InputOutput;
            parameter.ParameterName = "p";
            parameter.OracleDbType = OracleDbType.Object;
            parameter.UdtTypeName = "SYS.ODCICOST";
            parameter.Value = new OdciCost { CPUCOST = 123, INDEXCOSTINFO = "DUMMY", IOCOST = 456, NETWORKCOST = 789 };
            command.Parameters.Add(parameter);

            command.ExecuteNonQuery();

            var odciCost = (OdciCost)parameter.Value;
            Console.WriteLine($"CPUCOST={odciCost.CPUCOST}; IOCOST={odciCost.IOCOST}; NETWORKCOST={odciCost.NETWORKCOST}; INDEXCOSTINFO={odciCost.INDEXCOSTINFO}");
        }
    }
}

[OracleCustomTypeMapping("SYS.ODCICOST")]
public class OdciCost : IOracleCustomType, IOracleCustomTypeFactory, INullable
{
    private bool _isNull;
    [OracleObjectMapping("CPUCOST")]
    public decimal CPUCOST;
    [OracleObjectMapping("INDEXCOSTINFO")]
    public string INDEXCOSTINFO;
    [OracleObjectMapping("IOCOST")]
    public decimal IOCOST;
    [OracleObjectMapping("NETWORKCOST")]
    public decimal NETWORKCOST;

    public IOracleCustomType CreateObject()
    {
        return new OdciCost();
    }

    public void FromCustomObject(OracleConnection connection, IntPtr pointerUdt)
    {
        OracleUdt.SetValue(connection, pointerUdt, "CPUCOST", CPUCOST);
        OracleUdt.SetValue(connection, pointerUdt, "IOCOST", IOCOST);
        OracleUdt.SetValue(connection, pointerUdt, "NETWORKCOST", NETWORKCOST);
        OracleUdt.SetValue(connection, pointerUdt, "INDEXCOSTINFO", INDEXCOSTINFO);
    }

    public void ToCustomObject(OracleConnection connection, IntPtr pointerUdt)
    {
        CPUCOST = (decimal)OracleUdt.GetValue(connection, pointerUdt, "CPUCOST");
        IOCOST = (decimal)OracleUdt.GetValue(connection, pointerUdt, "IOCOST");
        NETWORKCOST = (decimal)OracleUdt.GetValue(connection, pointerUdt, "NETWORKCOST");
        INDEXCOSTINFO = (string)OracleUdt.GetValue(connection, pointerUdt, "INDEXCOSTINFO");
    }

    public bool IsNull
    {
        get { return this._isNull; }
    }

    public static OdciCost Null
    {
        get { return new OdciCost { _isNull = true }; }
    }
}



  1. Database
  2.   
  3. Mysql
  4.   
  5. Oracle
  6.   
  7. Sqlserver
  8.   
  9. PostgreSQL
  10.   
  11. Access
  12.   
  13. SQLite
  14.   
  15. MariaDB
  1. C# Грешка ORA 00907:Липсваща дясна скоба

  2. Oracle JDBC DriverManager.getConnection() увисва

  3. Динамична кръстосана заявка в Oracle

  4. Oracle 12c Топ нови функции

  5. Как да поправя повреден файл за експортиране на Oracle (.dmp)?