首页 > 解决方案 > 如何在 react-native-sqlite-storage 查询中使用 LIKE

问题描述

我想让每个名字都包含“天使”的用户。这是我的代码

this.DATABASE.transaction(tx => {
  tx.executeSql(
    "SELECT * FROM tblUser WHERE Name LIKE '%?%'",["Angel"],
    (tx, data) => {
      var result = [];
      for (let i = 0; i < data.rows.length; i++) {
        result.push(data.rows.item(i));
      }
    },
})

但我得到了错误"Cannot bind argument at index 1 because the index is out of range. The statement has 0 parameters."它只知道它什么?时候独立,不像我的查询那样理解。这个问题有什么解决办法吗?

标签: react-native-sqlite-storage

解决方案


采用

"SELECT * FROM tblUser WHERE Name LIKE ?",[`%${Angel}%`]

推荐阅读