1.MySql 函数LAST_INSERT_ID()获得上一个插入数据的Id值,但是如果是首次连接插入,则该值为0,如何避免该问题.假设一种操作情况:
如果我用该返回Id值作为其他表的外键,那么在首次连接插入时返回了0,可实际插入的记录id并不是0,这样数据关联就有问题了.
这种现象会出现么?怎么处理?==================================
2.如果把long长整型字符串显式转变为long数值,MySql对应函数是什么?
eg.  '10244030434'  ==>  10244030434我的sql使用情况是 
insert into table(id,value)
values(?,?+0)
id是long值
value是long字符串
哪个 ?+0 据说能转过来,不过这种技巧性的东西感觉不安全,想找个函数

解决方案 »

  1.   

    2
    参考CAST、CONVERT
    1
    可以用一个表保存最后一个ID,
    LAST_INSERT_ID() 是插入后才能取得的
      

  2.   

    CAST(expr AS type) The CAST() function takes a value of one type and produce a value of another type, similar to CONVERT(). See the description of CONVERT() for more information. 
    CONVERT(expr,type), CONVERT(expr USING transcoding_name) 
    The CONVERT() and CAST() functions take a value of one type and produce a value of another type. 
    The type can be one of the following values: BINARY[(N)] 
    CHAR[(N)] 
    DATE 
    DATETIME 
    DECIMAL[(M[,D])] 
    SIGNED [INTEGER] 
    TIME 
    UNSIGNED [INTEGER] 
    long的字符串怎么选那种类型?SIGNED?这两句都对么?
    CONVERT('12348723324344',SIGNED)
    CONVERT(12348723234344,CHAR)
      

  3.   

    long的字符串怎么选那种类型?SIGNED? 
    如果范围
    A normal-size integer. 
    The signed range is -2147483648 to 2147483647. 
    The unsigned range is 0 to 4294967295. 
    在这里面的话,可以