diff --git a/src/sql/engine/expr/ob_expr_cast.cpp b/src/sql/engine/expr/ob_expr_cast.cpp index 74bff93542..b05e9ba655 100644 --- a/src/sql/engine/expr/ob_expr_cast.cpp +++ b/src/sql/engine/expr/ob_expr_cast.cpp @@ -430,6 +430,10 @@ int ObExprCast::calc_result_type2(ObExprResType &type, ObAccuracy acc = ObAccuracy::DDL_DEFAULT_ACCURACY2[compatibility_mode][dst_type.get_type()]; type.set_accuracy(acc); type1.set_accuracy(acc); + } else if (ObYearType == dst_type.get_type()) { + ObAccuracy acc = ObAccuracy::DDL_DEFAULT_ACCURACY2[compatibility_mode][dst_type.get_type()]; + type.set_accuracy(acc); + type1.set_accuracy(acc); } else { type.set_precision(dst_type.get_precision()); } diff --git a/src/sql/resolver/expr/ob_raw_expr_printer.cpp b/src/sql/resolver/expr/ob_raw_expr_printer.cpp index 7f1fef69a1..5287d0759b 100644 --- a/src/sql/resolver/expr/ob_raw_expr_printer.cpp +++ b/src/sql/resolver/expr/ob_raw_expr_printer.cpp @@ -4006,6 +4006,15 @@ int ObRawExprPrinter::print_cast_type(ObRawExpr *expr) DATA_PRINTF("date"); break; } + case T_YEAR: { + int16_t scale = parse_node.int16_values_[OB_NODE_CAST_N_SCALE_IDX]; + if (scale >= 0) { + DATA_PRINTF("year(%d)", scale); + } else { + DATA_PRINTF("year"); + } + break; + } case T_TIME: { int16_t scale = parse_node.int16_values_[OB_NODE_CAST_N_SCALE_IDX]; if (scale >= 0) {