用于 VS 代码的 MySQL Shell GUI / MySQL Shell  / 第 8 章 JavaScript  /  8.2 数据库笔记本:使用 SELECT 语句检索数据

全面上市前:2022-11-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": "喀布尔",
          “区”:“喀布尔”,
          “流行音乐”:1780000
    }
]

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

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

输出是:

{
  “请求状态”:{
    “类型”:“确定”,
    "msg": "包含 2 行传输的完整结果集。"
  },
  “requestId”:“25361d27-e80d-4cab-0884-cfe7a75eda56”,
  “行”:[
    [
      "瓜亚那城",
      663713
    ],
    [
      “玻利瓦尔城”,
      301107
    ]
  ],
  “列”: [
    {
      "名称": "n",
      “类型”:“字符串”,
      “长度”:140
    },
    {
      “名字”:“P”,
      “类型”:“整数”,
      “长度”:11
    }
  ],
  “完成”:是的,
  “总行数”:2,
  “执行时间”:0.0019462108612060547
}