⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 e257. matching with wildcards in a sql statement.txt

📁 这里面包含了一百多个JAVA源文件
💻 TXT
字号:
SQL provides wildcard matching of text using the LIKE clause. Here is a SQL statement that uses a LIKE clause and a wildcard character. This SQL statement will find all rows with names that start with Pat. 
    SELECT * FROM my_table WHERE name LIKE 'Pat%'

There are two wildcard characters available. The underscore (_) matches any character. The percent sign (%) matches zero or more characters. 
    try {
        // Create a statement
        Statement stmt = connection.createStatement();
    
        // Select the row if col_string contains the word pat
        String sql = "SELECT * FROM my_table WHERE col_string LIKE '%pat%'";
    
        // Select the row if col_string ends with the word pat
        sql = "SELECT * FROM my_table WHERE col_string LIKE 'pat%'";
    
        // Select the row if col_string starts with abc and ends with xyz
        sql = "SELECT * FROM my_table WHERE col_string LIKE 'abc%xyz'";
    
        // Select the row if col_string equals the word pat%
        sql = "SELECT * FROM my_table WHERE col_string LIKE 'pat\\%'";
    
        // Select the row if col_string has 3 characters and starts with p and ends with t
        sql = "SELECT * FROM my_table WHERE col_string LIKE 'p_t'";
    
        // Select the row if col_string equals p_t
        sql = "SELECT * FROM my_table WHERE col_string LIKE 'p\\_t'";
    
        // Execute the query
        ResultSet resultSet = stmt.executeQuery(sql);
    } catch (SQLException e) {
    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -