diff --git a/src/share/object/ob_obj_cast.cpp b/src/share/object/ob_obj_cast.cpp index 4db6e90794..a8418d9fff 100644 --- a/src/share/object/ob_obj_cast.cpp +++ b/src/share/object/ob_obj_cast.cpp @@ -11230,7 +11230,9 @@ bool cast_supported(const ObObjType orig_type, const ObCollationType orig_cs_typ } else if (is_oracle_mode() && (clob_in || ob_is_number_tc(orig_type) || ob_is_int_tc(orig_type) || ob_is_datetime_tc(orig_type)) && blob_out) { bret = false; - } else if (is_oracle_mode() && ObTinyIntType == orig_type && ob_is_text_tc(expect_type)) { + } else if (is_oracle_mode() && + (ObTinyIntType == orig_type || ObDateTimeType == orig_type) && + ob_is_text_tc(expect_type)) { bret = false; } else { ObObjTypeClass orig_tc = ob_obj_type_class(orig_type); diff --git a/src/sql/engine/expr/ob_expr.cpp b/src/sql/engine/expr/ob_expr.cpp index 55020c764e..ab888ff57b 100644 --- a/src/sql/engine/expr/ob_expr.cpp +++ b/src/sql/engine/expr/ob_expr.cpp @@ -787,6 +787,9 @@ int eval_assign_question_mark_func(const ObExpr &expr, ObEvalCtx &ctx, ObDatum & if (ctx.exec_ctx_.get_physical_plan_ctx()->is_ignore_stmt()) { cast_mode = cast_mode | CM_WARN_ON_FAIL | CM_CHARSET_CONVERT_IGNORE_ERR; } + if ((v.is_blob() || dst_meta.is_blob()) && lib::is_oracle_mode()) { + cast_mode |= CM_ENABLE_BLOB_CAST; + } ObCastCtx cast_ctx(&allocator, &dtc_params, cast_mode, dst_meta.get_collation_type()); if (OB_FAIL(ObObjCaster::to_type(dst_meta.get_type(), cast_ctx, v, dst_obj))) { LOG_WARN("failed to cast obj to dst type", K(ret), K(v), K(dst_meta)); diff --git a/src/sql/engine/expr/ob_expr_cast.cpp b/src/sql/engine/expr/ob_expr_cast.cpp index cc53d46fb9..ff49271998 100644 --- a/src/sql/engine/expr/ob_expr_cast.cpp +++ b/src/sql/engine/expr/ob_expr_cast.cpp @@ -273,22 +273,33 @@ bool ObExprCast::check_cast_allowed(const ObObjType orig_type, bool res = true; ObObjTypeClass ori_tc = ob_obj_type_class(orig_type); ObObjTypeClass expect_tc = ob_obj_type_class(expect_type); - if (is_oracle_mode() && is_explicit_cast) { - // can't cast lob to other type except char/varchar/nchar/nvarchar2/raw. clob to raw not allowed too. - if (ObLobTC == ori_tc || ObTextTC == ori_tc) { - if (expect_tc == ObJsonTC) { - /* oracle mode, json text use lob store */ - } else if (ObStringTC == expect_tc) { - // do nothing - } else if (ObRawTC == expect_tc) { - res = CS_TYPE_BINARY == orig_cs_type; - } else { + bool is_expect_lob_tc = (ObLobTC == expect_tc || ObTextTC == expect_tc); + bool is_ori_lob_tc = (ObLobTC == ori_tc || ObTextTC == ori_tc); + if (is_oracle_mode()) { + if (is_explicit_cast) { + // can't cast lob to other type except char/varchar/nchar/nvarchar2/raw. clob to raw not allowed too. + if (is_ori_lob_tc) { + if (expect_tc == ObJsonTC) { + /* oracle mode, json text use lob store */ + } else if (ObStringTC == expect_tc) { + // do nothing + } else if (ObRawTC == expect_tc) { + res = CS_TYPE_BINARY == orig_cs_type; + } else { + res = false; + } + } + // any type to lob type not allowed. + if (is_expect_lob_tc) { res = false; } - } - // any type to lob type not allowed. - if (ObLobTC == expect_tc || ObTextTC == expect_tc) { - res = false; + } else { + // BINARY FLOAT/DOUBLE not allow cast lob whether explicit + if (is_ori_lob_tc) { + if (expect_tc == ObFloatTC || expect_tc == ObDoubleTC) { + res = false; + } + } } } return res;