sqlite插入错误

时间:2012-09-18 02:35:34

标签: sql sqlite

我使用Firefox插件SQLite Manager执行我的SQL:

    declare @id int
    declare @lon float
    declare @lat float
    set @id=5
    set @lon=118.476000
    set @lat=32.033720
    while @i<=10000
      begin
        INSERT INTO njdm 
          (ID,dalei,xiaolei,hanyi,level,longitude,latitude) 
        VALUES 
          (@id, 5, 10, "地名描述",1,@lon,@lat)

        set @id=@id+1
        set @lon=@lon+0.000010
        set @lat=@lat+0.000010
      end

得到错误:

    [ near "declare": syntax error ]
    Exception Name: NS_ERROR_FAILURE
    Exception Message: Component returned failure code: 0x80004005 (NS_ERROR_FAILURE)                          [mozIStorageConnection.createStatement]

任何帮助?TIA!

3 个答案:

答案 0 :(得分:0)

      declare @id int
        declare @lon float
        declare @lat float
        set @id=5
        set @lon=118.476000
        set @lat=32.033720
        while @id<=10000
          begin
            INSERT INTO njdm 
              (ID,dalei,xiaolei,hanyi,level,longitude,latitude) 
            VALUES 
              (@id, 5, 10, "地名描述",1,@lon,@lat)

            set @id=@id+1
            set @lon=@lon+0.000010
            set @lat=@lat+0.000010
          end

Note:  while @id<=10000 instead of  while @i<=10000

答案 1 :(得分:0)

SQLite does not appear to support WHILE constructs。您可以finagle a similar effect using extra tables,但将某些工作卸载到应用程序可能更容易。

答案 2 :(得分:0)

SQLite仅支持 SQL操作,它不直接支持变量,变量赋值,循环或其他程序构造。您需要使用支持这些构造的其他语言编写此代码,然后通过构造动态SQL或使用与您选择的语言关联的SQLite支持库之一将命令发送到SQLite。