在整个Mysql表中搜索特定的字符串(所有字段)

时间:2017-06-08 08:04:12

标签: mysql sql-like

我目前正在使用以下查询进行单字段搜索

SELECT *
FROM user_college_tbl
WHERE college_name LIKE '%Impulse%';

如何搜索整个表格中的特定字符串(所有字段)?

2 个答案:

答案 0 :(得分:0)

您可以考虑使用全文搜索:

class Chunk {

private IntBuffer vaoID;
private IntBuffer vboID;
private IntBuffer indexID;


public void createChunkVBO() {

    FloatBuffer vertices = BufferUtils.createFloatBuffer(16 * 256 * 16 * 3 * 8);
    FloatBuffer colors = BufferUtils.createFloatBuffer(16 * 256 * 16 * 4 * 8);
    FloatBuffer indices = BufferUtils.createFloatBuffer(16 * 256 * 16 * 4 * 6);

    vaoID = BufferUtils.createIntBuffer(1); // Create a buffer for the Vertex Array Object
    vboID = BufferUtils.createIntBuffer(1); // Create a buffer for the Vertex Buffer Object
    indexID = BufferUtils.createIntBuffer(1); // Create a buffer for the Vertex Indices


    for (int x = 0; x < 16; x++) {
        for (int y = 0; y < 256; y++) {
            for (int z = 0; z < 16; z++) {
                System.out.println(x + ", " + y + ", " + z);
                vertices.put(x + World.BLOCK_SIZE);
                vertices.put(y);
                vertices.put(z + World.BLOCK_SIZE);

                vertices.put(x);
                vertices.put(y);
                vertices.put(z + World.BLOCK_SIZE);

                vertices.put(x);
                vertices.put(y);
                vertices.put(z);

                vertices.put(x + World.BLOCK_SIZE);
                vertices.put(y);
                vertices.put(z);

                vertices.put(x + World.BLOCK_SIZE);
                vertices.put(y + World.BLOCK_SIZE);
                vertices.put(z + World.BLOCK_SIZE);

                vertices.put(x);
                vertices.put(y + World.BLOCK_SIZE);
                vertices.put(z + World.BLOCK_SIZE);

                vertices.put(x);
                vertices.put(y + World.BLOCK_SIZE);
                vertices.put(z);

                vertices.put(x + World.BLOCK_SIZE);
                vertices.put(y + World.BLOCK_SIZE);
                vertices.put(z);


                colors.put(1f);
                colors.put(0f);
                colors.put(0f);
                colors.put(1f);

                colors.put(1f);
                colors.put(0f);
                colors.put(0f);
                colors.put(1f);

                colors.put(1f);
                colors.put(0f);
                colors.put(0f);
                colors.put(1f);

                colors.put(1f);
                colors.put(0f);
                colors.put(0f);
                colors.put(1f);

                colors.put(1f);
                colors.put(0f);
                colors.put(0f);
                colors.put(1f);

                colors.put(1f);
                colors.put(0f);
                colors.put(0f);
                colors.put(1f);

                colors.put(1f);
                colors.put(0f);
                colors.put(0f);
                colors.put(1f);

                colors.put(1f);
                colors.put(0f);
                colors.put(0f);
                colors.put(1f);


                indices.put(0 + x * y * z);
                indices.put(1 + x * y * z);
                indices.put(2 + x * y * z);
                indices.put(3 + x * y * z);


                indices.put(4 + x * y * z);
                indices.put(5 + x * y * z);
                indices.put(2 + x * y * z);
                indices.put(3 + x * y * z);


                indices.put(1 + x * y * z);
                indices.put(3 + x * y * z);
                indices.put(7 + x * y * z);
                indices.put(5 + x * y * z);


                indices.put(0 + x * y * z);
                indices.put(3 + x * y * z);
                indices.put(4 + x * y * z);
                indices.put(7 + x * y * z);


                indices.put(0 + x * y * z);
                indices.put(1 + x * y * z);
                indices.put(6 + x * y * z);
                indices.put(7 + x * y * z);


                indices.put(4 + x * y * z);
                indices.put(5 + x * y * z);
                indices.put(6 + x * y * z);
                indices.put(7 + x * y * z);

            }
        }
    }


    glGenVertexArrays(vaoID); // Create an id for the VAO
    glBindVertexArray(vaoID.get(0)); // Bind the VAO so it remembers all the Attributes (none right now)

    glGenBuffers(vboID); // Create an id for the VBO
    glBindBuffer(GL_ARRAY_BUFFER, vboID.get(0)); // Bind the VBO so we can put data into it

    glBufferData(GL_ARRAY_BUFFER, 16 * 256 * 16 * 8 * 7 * Float.SIZE, GL_STATIC_DRAW); // We make an empty buffer with a specific size in bytes
                                                                        // 8 * 7 * sizeof(float)
                                                                        // 8 = number of vertices, 7 = xyzrgba

    glBufferSubData(GL_ARRAY_BUFFER, 0, vertices); // Put the vertices at the beginning of the buffer
    glBufferSubData(GL_ARRAY_BUFFER, 16 * 256 * 16 * 8 * 3 * Float.SIZE, colors); // Put the colors after the vertices

    glGenBuffers(indexID); // Create an id for the Index Buffer
    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indexID.get(0)); // Bind the Index Buffer so we can put data into it
    glBufferData(GL_ELEMENT_ARRAY_BUFFER, indices, GL_STATIC_DRAW); // Store the indices inside the currently bound Index Buffer

}

public void drawChunk() {

    glEnableClientState(GL_VERTEX_ARRAY); // Enable the Vertex Array
    glEnableClientState(GL_COLOR_ARRAY); // Enable the Color Array

    glVertexPointer(3, GL_FLOAT, 0, 0);
    glColorPointer(4, GL_FLOAT, 0, 16 * 256 * 16 * 8 * 3 * Float.SIZE); // Position of the colors in the currently bound buffer

    glDrawElements(GL_QUADS, 24 * 16 * 256 * 16, GL_UNSIGNED_INT, 0); // Draws the elements from the Index Buffer

}


}

这假设您在要包含在搜索中的所有文本列上设置了全文索引:

SELECT *
FROM user_college_tbl
WHERE MATCH(col1, col2, ...) AGAINST ('Impulse' IN NATURAL LANGUAGE MODE)

如果您使用的是早于5.6的MySQL版本,或者您不想要全文搜索,那么您可能只能将表格中每个文本列的CREATE TABLE user_college_tbl ( id INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY, college_name VARCHAR(200), col1 TEXT, col2 TEXT, -- ... more text columns FULLTEXT(college_name, col1, col2, ...) ) ENGINE=InnoDB; 表达式进行ORing,例如< / p>

LIKE

答案 1 :(得分:0)

您也可以进行动态SQL查询。

<强>查询

set @query = null;
select
  group_concat(
    concat(
       column_name, '', ' like \'%Impulse%\' or '
    ) separator ''
  ) into @query
from information_schema.columns
where table_name = 'user_college_tbl';

set @query = concat('select * from user_college_tbl where ', 
           left(@query, length(@query) - 4));


prepare stmt from @query;
execute stmt;
deallocate prepare stmt;