zoukankan      html  css  js  c++  java
  • MySql动态拼接SQL并动态赋值

    CREATE DEFINER=`root`@`localhost` PROCEDURE `p_dc_log`(
    IN UName VARCHAR(50),
    IN Description VARCHAR(50),
    IN PageSize int,
    IN PageIndex int,
    OUT TotalCount int
    )
    BEGIN
        set @QueryWhere = '';
        
        #条件查询
        IF LENGTH(UName) > 0 THEN
          set @QueryWhere = CONCAT(@QueryWhere,' AND UserName = ? ');
        END IF;
        
        IF LENGTH(Description) > 0  THEN
            set @QueryWhere = CONCAT(@QueryWhere,' AND Description LIKE ''%',Description,'%'' ');
        END IF;
        
        #查询总条数
        SELECT @QuerySql := CONCAT('SELECT COUNT(1) INTO @TotalCount FROM dc_log WHERE 1 = 1',@QueryWhere);
    
        PREPARE stmt FROM 'SELECT COUNT(1) INTO @TotalCount FROM dc_log WHERE 1 = 1';
        
        EXECUTE stmt;    
        
        SELECT @TotalCount AS Tcount;
        
        SET TotalCount = @TotalCount;
    END
  • 相关阅读:
    结构和联合
    字符串、字符和字节
    数组
    函数
    指针
    操作符和表达式
    语句
    数据
    TinyXML2 使用
    是否忘记了向源中添加“#include "StdAfx.h"”?
  • 原文地址:https://www.cnblogs.com/superfeeling/p/13068641.html
Copyright © 2011-2022 走看看