當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Node.js MySQL LOWER()用法及代碼示例

LOWER()函數是MySQL中的內置函數,用於將給定字符串的所有字符轉換為小寫。

用法:

LOWER(input_string)

參數:LOWER()函數接受如上所述和以下描述的單個參數。

  • input_string:我們將把這個字符串轉換成小寫

返回值:LOWER()函數返回一個新的小寫字符串。

模塊:

  • mysql:處理MySQL連接和查詢
npm install mysql

SQL發布者表預覽:

Database table

範例1:

Javascript


const mysql = require("mysql");
  
let db_con = mysql.createConnection({
  host:"localhost",
  user:"root",
  password:"",
  database:"gfg_db",
});
  
db_con.connect((err) => {
  if (err) {
    console.log("Database Connection Failed !!!", err);
    return;
  }
  
  console.log("We are connected to gfg_db database");
  
  // here is the query
  let query = "SELECT LOWER('This iNpUT strinG @!#$%^&*()?') AS lowercase_name";
  
  db_con.query(query, (err, rows) => {
    if (err) throw err;
  
    console.log(rows);
  });
});

輸出:

Node.js MySQL LOWER() Function 1

範例2:

Javascript


const mysql = require("mysql");
  
let db_con = mysql.createConnection({
  host:"localhost",
  user:"root",
  password:"",
  database:"gfg_db",
});
  
db_con.connect((err) => {
  if (err) {
    console.log("Database Connection Failed !!!", err);
    return;
  }
  
  console.log("We are connected to gfg_db database");
  
  // here is the query
  let query = "SELECT LOWER(name) AS lowercase_name FROM publishers";
  
  db_con.query(query, (err, rows) => {
    if (err) throw err;
  
    console.log(rows);
  });
});

輸出:

Node.js MySQL LOWER() Function 2


相關用法


注:本文由純淨天空篩選整理自pratikraut0000大神的英文原創作品 Node.js MySQL LOWER() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。