zoukankan      html  css  js  c++  java
  • 三大关系数据库字段值超长的一个有趣对比

    三大关系数据库字段值超长的一个有趣对比

     

    在开发中,我们可能会遇到插入字段值超长的情况,前阵子遇到这样一个案例,结果一对比后发现一个有趣的现象,如果插入字段值超长,ORACLE、SQL Server、MySQL它们会提示那个字段值超长吗?下面看看实验吧:

     

    ORACLE数据库

     

    SQL> create table test(id number(10), name varchar2(12));
     
    Table created.
     
    SQL> insert into test
      2  select 10, 'kkkkkkkkkkkkkkkkkk' from dual;
    select 10, 'kkkkkkkkkkkkkkkkkk' from dual
               *
    ERROR at line 2:
    ORA-12899: value too large for column "SYS"."TEST"."NAME" (actual: 18, maximum:
    12)

     

     

    MySQL数据库

     

     

    SQL> create table test(id number(10), name varchar2(12));
     
    Table created.
     
    SQL> insert into test
      2  select 10, 'kkkkkkkkkkkkkkkkkk' from dual;
    select 10, 'kkkkkkkkkkkkkkkkkk' from dual
               *
    ERROR at line 2:
    ORA-12899: value too large for column "SYS"."TEST"."NAME" (actual: 18, maximum:
    12)

     

    SQL SERVER数据库

     

    USE  AdventureWorks2014;
    GO
     
    CREATE TABLE TEST(ID int, NAME varchar(12));
     
    INSERT INTO dbo.TEST 
    SELECT 100,'kkkkkkkkkkkkkkkkkkkkkkkkk'
     
    Msg 8152, Level 16, State 14, Line 6
    String or binary data would be truncated.
    The statement has been terminated.

     

     

    clip_image001

     

     

    如上实验所示,ORACLE、MySQL都会提示具体字段超长的细节信息,而SQL Server就傻傻的提示String or binary data would be truncated. 如果你表结构字段有十几个,那么就一个个核对吧。 不吹不黑,其实SQL Server有蛮多不友好、甚至让人诟病的地方。举个例子,使用SqlBulkCopy插入数据时,遇到错误数据源的 String 类型的给定值不能转换为指定目标列的类型xxx, 有可能是目标表字段的长度比要导入的数据长度小或者其它原因,难道准确、友好的提示具体出错信息那么难?还有使用SqlbulkCopy有时候提示给定的 ColumnMapping 与源或目标中的任意列均不匹配, 你妹啊,这不是坑爹吗! 这些都是一些细节地方,有时候真的细节见高低!此文权当吐槽篇!

  • 相关阅读:
    从分布式系统的角度看REST
    修改python系统默认编码的一种方法
    Base PyQt4, Simple Web APP Framwork
    用python写的测试网页和文件编码的小程序
    Python学习笔记(二):标准流与重定向
    How to escape (percentencode) a URL with Python « SaltyCrane Blog
    python操作Excel读写使用xlrd
    Quickstart — Requests 0.10.7 documentation
    irb的子会话 相思雨 博客园
    基于python的汉字转GBK码
  • 原文地址:https://www.cnblogs.com/kerrycode/p/7619711.html
Copyright © 2011-2022 走看看