<bdo id='dvcSe'></bdo><ul id='dvcSe'></ul>
  • <legend id='dvcSe'><style id='dvcSe'><dir id='dvcSe'><q id='dvcSe'></q></dir></style></legend><tfoot id='dvcSe'></tfoot>
    <i id='dvcSe'><tr id='dvcSe'><dt id='dvcSe'><q id='dvcSe'><span id='dvcSe'><b id='dvcSe'><form id='dvcSe'><ins id='dvcSe'></ins><ul id='dvcSe'></ul><sub id='dvcSe'></sub></form><legend id='dvcSe'></legend><bdo id='dvcSe'><pre id='dvcSe'><center id='dvcSe'></center></pre></bdo></b><th id='dvcSe'></th></span></q></dt></tr></i><div id='dvcSe'><tfoot id='dvcSe'></tfoot><dl id='dvcSe'><fieldset id='dvcSe'></fieldset></dl></div>

    <small id='dvcSe'></small><noframes id='dvcSe'>

      1. 在 SQLite 中声明变量并使用它

        Declare variable in SQLite and use it(在 SQLite 中声明变量并使用它)

          <i id='9qOp3'><tr id='9qOp3'><dt id='9qOp3'><q id='9qOp3'><span id='9qOp3'><b id='9qOp3'><form id='9qOp3'><ins id='9qOp3'></ins><ul id='9qOp3'></ul><sub id='9qOp3'></sub></form><legend id='9qOp3'></legend><bdo id='9qOp3'><pre id='9qOp3'><center id='9qOp3'></center></pre></bdo></b><th id='9qOp3'></th></span></q></dt></tr></i><div id='9qOp3'><tfoot id='9qOp3'></tfoot><dl id='9qOp3'><fieldset id='9qOp3'></fieldset></dl></div>
          <tfoot id='9qOp3'></tfoot>

            <bdo id='9qOp3'></bdo><ul id='9qOp3'></ul>

            <legend id='9qOp3'><style id='9qOp3'><dir id='9qOp3'><q id='9qOp3'></q></dir></style></legend>

          • <small id='9qOp3'></small><noframes id='9qOp3'>

              <tbody id='9qOp3'></tbody>

                  本文介绍了在 SQLite 中声明变量并使用它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我想在 SQLite 中声明一个变量并在 insert 操作中使用它.

                  I want to declare a variable in SQLite and use it in insert operation.

                  就像在 MS SQL 中一样:

                  Like in MS SQL:

                  declare @name as varchar(10)
                  set name = 'name'
                  select * from table where name = @name
                  

                  例如,我需要获取 last_insert_row 并在 insert 中使用它.

                  For example, I will need to get last_insert_row and use it in insert.

                  我发现了一些关于绑定的东西,但我并没有完全理解它.

                  I have found something about binding but I didn't really fully understood it.

                  推荐答案

                  SQLite 不支持本机变量语法,但您可以使用内存中的临时表实现几乎相同的效果.

                  SQLite doesn't support native variable syntax, but you can achieve virtually the same using an in-memory temp table.

                  我已经在大型项目中使用了以下方法并且效果很好.

                  I've used the below approach for large projects and works like a charm.

                      /* Create in-memory temp table for variables */
                      BEGIN;
                  
                      PRAGMA temp_store = 2; /* 2 means use in-memory */
                      CREATE TEMP TABLE _Variables(Name TEXT PRIMARY KEY, RealValue REAL, IntegerValue INTEGER, BlobValue BLOB, TextValue TEXT);
                  
                      /* Declaring a variable */
                      INSERT INTO _Variables (Name) VALUES ('VariableName');
                  
                      /* Assigning a variable (pick the right storage class) */
                      UPDATE _Variables SET IntegerValue = ... WHERE Name = 'VariableName';
                  
                      /* Getting variable value (use within expression) */
                      ... (SELECT coalesce(RealValue, IntegerValue, BlobValue, TextValue) FROM _Variables WHERE Name = 'VariableName' LIMIT 1) ...
                  
                      DROP TABLE _Variables;
                      END;
                  

                  这篇关于在 SQLite 中声明变量并使用它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  ibtmp1是非压缩的innodb临时表的独立表空间,通过innodb_temp_data_file_path参数指定文件的路径,文件名和大小,默认配置为ibtmp1:12M:autoextend,也就是说在文件系统磁盘足够的情况下,这个文件大小是可以无限增长的。 为了避免ibtmp1文件无止境的暴涨导致
                  SQL query to group by day(按天分组的 SQL 查询)
                  What does SQL clause quot;GROUP BY 1quot; mean?(SQL 子句“GROUP BY 1是什么意思?意思是?)
                  MySQL groupwise MAX() returns unexpected results(MySQL groupwise MAX() 返回意外结果)
                  MySQL SELECT most frequent by group(MySQL SELECT 按组最频繁)
                  Include missing months in Group By query(在 Group By 查询中包含缺失的月份)

                  1. <tfoot id='LDMcC'></tfoot>
                  2. <small id='LDMcC'></small><noframes id='LDMcC'>

                      <tbody id='LDMcC'></tbody>
                      <bdo id='LDMcC'></bdo><ul id='LDMcC'></ul>
                        <i id='LDMcC'><tr id='LDMcC'><dt id='LDMcC'><q id='LDMcC'><span id='LDMcC'><b id='LDMcC'><form id='LDMcC'><ins id='LDMcC'></ins><ul id='LDMcC'></ul><sub id='LDMcC'></sub></form><legend id='LDMcC'></legend><bdo id='LDMcC'><pre id='LDMcC'><center id='LDMcC'></center></pre></bdo></b><th id='LDMcC'></th></span></q></dt></tr></i><div id='LDMcC'><tfoot id='LDMcC'></tfoot><dl id='LDMcC'><fieldset id='LDMcC'></fieldset></dl></div>
                        • <legend id='LDMcC'><style id='LDMcC'><dir id='LDMcC'><q id='LDMcC'></q></dir></style></legend>