code: func ConvertDatumToDecimal(sc *stmtctx.StatementContext, d Datum) (*MyDecimal, error) {
  	dec := new(MyDecimal)
  	var err error
  	switch d.Kind() {
  	case KindInt64:
  		dec.FromInt(d.GetInt64())
  	case KindUint64:
  		dec.FromUint(d.GetUint64())
  	case KindFloat32:
  		err = dec.FromFloat64(float64(d.GetFloat32()))
  	case KindFloat64:
  		err = dec.FromFloat64(d.GetFloat64())
  	case KindString:
  		err = sc.HandleTruncate(dec.FromString(d.GetBytes()))
  	case KindMysqlDecimal:
  		*dec = *d.GetMysqlDecimal()
  	case KindMysqlEnum:
  		dec.FromUint(d.GetMysqlEnum().Value)
  	case KindMysqlSet:
  		dec.FromUint(d.GetMysqlSet().Value)
  	case KindBinaryLiteral, KindMysqlBit:
  		val, err1 := d.GetBinaryLiteral().ToInt(sc)
  		dec.FromUint(val)
  		err = err1
  	case KindMysqlJSON:
  		f, err1 := ConvertJSONToFloat(sc, d.GetMysqlJSON())
  		if err1 != nil {
  			return nil, errors.Trace(err1)
  		}
  		err = dec.FromFloat64(f)
  	default:
  		err = fmt.Errorf("can't convert %v to decimal", d.GetValue())
  	}
  	return dec, errors.Trace(err)
  }
docs: // ConvertDatumToDecimal converts datum to decimal.