文档首页
MySQL Shell for VS Code


MySQL Shell for VS Code  /  JavaScript  /  数据库笔记本:使用 SELECT 语句检索数据

预发布版本:2024-07-17

8.2 数据库笔记本:使用 SELECT 语句检索数据

数据库笔记本:返回一行数据的基本查询

runSql(
  "SELECT Name as name," +
  "District as district, Population as pop FROM world.city WHERE Name = 'Kabul' ",
  (ResultSetRows) => {
    print(ResultSetRows);
  }
);

输出为

[
    {
          "name": "Kabul",
          "district": "Kabol",
          "pop": 1780000
    }
]

数据库笔记本:返回多行数据的基本查询

runSqlIterative(
  "SELECT Name as n," +
    "Population as p FROM world.city WHERE CountryCode = 'Ven' AND District LIKE 'Bolivar'",
  (IResultSetData) => {
    print(IResultSetData);
  }
);

输出为

{
  "requestState": {
    "type": "OK",
    "msg": "Full result set consisting of 2 rows transferred."
  },
  "requestId": "25361d27-e80d-4cab-0884-cfe7a75eda56",
  "rows": [
    [
      "Ciudad Guayana",
      663713
    ],
    [
      "Ciudad Bolívar",
      301107
    ]
  ],
  "columns": [
    {
      "name": "n",
      "type": "STRING",
      "length": 140
    },
    {
      "name": "p",
      "type": "INT",
      "length": 11
    }
  ],
  "done": true,
  "totalRowCount": 2,
  "executionTime": 0.0019462108612060547
}