- ?比较MySQL表中的数据:先需要过滤排除不需要比较的字段,比如timestamp字段等;然后再排序字段(先按关键字排序,再按非空的字段排序,最后按其他字段排序), 当然一般情形还需要加where 条件,下面写了一个函数来构造一个SQL 语句。
CREATE DEFINER=`mysql`@`%` FUNCTION `f_toolkit_getFieldListFromTable`(`databaseName` varchar(255),`tableName` varchar(255),`is_RemoveTimestampField` boolean,excludeFiledlist varchar(1024)) RETURNS varchar(1024) CHARSET latin1BEGIN DECLARE exception_occured TINYINT default 0; DECLARE curr_field varchar(255); DECLARE curr_type varchar(255); DECLARE curr_key varchar(255); DECLARE curr_isnull varchar(10); DECLARE key_field_limit int DEFAULT 5; DECLARE TMP_CUR CURSOR FOR select column_name, column_type,column_key,is_nullable from information_schema.columns where table_schema=trim(databaseName) and table_name=trim(tableName) and locate(binary upper(column_name),binary upper(excludeFiledlist)) = 0 order by column_key desc,IS_NULLABLE,ORDINAL_POSITION; DECLARE CONTINUE HANDLER FOR SQLEXCEPTION,NOT FOUND SET exception_occured = 1; set @result = ''; set @orderBy = ''; set @nonNull = ''; set @nonNull_no = 0; set @nonKey_no = 0; set @nonKeyFields = ''; OPEN TMP_CUR; LOOP_LABLE:LOOP FETCH TMP_CUR into curr_field,curr_type,curr_key,curr_isnull; IF exception_occured = 1 THEN LEAVE LOOP_LABLE; END IF; IF !(is_RemoveTimestampField && curr_type like 'timestamp') then if @result = '' then set @result = curr_field; else set @result = CONCAT(@result,',',curr_field); end if; set @nonKey_no = @nonKey_no + 1; if @nonKeyFields = '' then set @nonKeyFields = curr_field; else if @nonKey_no < key_field_limit then set @nonKeyFields = concat(@nonKeyFields,',',curr_field); end if; end if; if lower(curr_key) in ('pri','mul','uni') then if @orderBy = '' then set @orderBy = curr_field; else set @orderBy = CONCAT(@orderBy,',',curr_field); end if; end if; if lower(curr_isnull) = 'no' && @nonNull_no < key_field_limit then if @nonNull = '' then set @nonNull = curr_field; else set @nonNull = CONCAT(@nonNull,',',curr_field); end if; set @nonNull_no = @nonNull_no + 1; end if; END IF; END LOOP LOOP_LABLE; CLOSE TMP_CUR; if @orderBy = '' then if @nonNull = '' then set @orderBy = @nonKeyFields; else set @orderBy = @nonNull; end if; end if; RETURN CONCAT('select ', @result , ' from ', databaseName, '.', tableName, ' order by ', @orderBy);END
? - 常常要全文搜索object(如Field,table,view,procedure)被其他object引用(这里是包含或用到的意思),写了一个存储过程来完成(需要MySQL 5.1 及以上支持)
CREATE DEFINER=`mysql`@`%` PROCEDURE `P_lookup_allObject_isUsing_Some_object`(`object` varchar(255))BEGIN set @v_obj_orginal = `object`; set `object` = concat('[^a-zA-Z_0-9]',ifnull(`object`,'null'),'[^a-zA-Z_0-9]'); select name from ( select concat(event_SCHEMA,'.',event_NAME) as name, 'event' as type from information_schema.events where EVENT_DEFINITION regexp `object` union select concat(TRIGGER_SCHEMA,'.',TRIGGER_NAME) as name,'trigger' as type from information_schema.triggers where ACTION_STATEMENT regexp `object` or ACTION_CONDITION regexp `object` union select concat(ROUTINE_SCHEMA,'.',ROUTINE_NAME) as type, ROUTINE_TYPE from information_schema.routines where ROUTINE_DEFINITION regexp `object` union select concat(TABLE_SCHEMA,'.',TABLE_NAME) as name, 'view' as type from information_schema.views where VIEW_DEFINITION regexp `object` union select concat(db,'.',`name`) as name, type from mysql.proc where body regexp `object` union select concat(TABLE_SCHEMA,'.',TABLE_NAME) as name, 'column' as type from information_schema.`COLUMNS` where COLUMN_NAME like @v_obj_orginal union select concat(db,'.',`name`) as name, 'event' as type from mysql.`event` where body regexp `object`) as Q order by type, name;END
?
详细解决方案
MySQL表数据比较跟Object全文搜索
热度:874 发布时间:2016-05-05 17:14:02.0
相关解决方案
- mysql 简单化 or能否实现
- 请问registered the JDBC driver [com.mysql.jdbc.Driver] but failed to unregister
- MySQL 5.5 Command Line Client 窗口1输密码就退出
- 请问上Linux平台上怎么搭建JDK \TOMCAT\MYSQL
- 在LINUX上配置 MySQL 开机自动 启动
- mysql 转 orocle java ssh项目一条 sql 句不通!
- 急求帮忙!mysql 【 Column count doesn't match value count 】,该怎么解决
- jsp中的注册登录系统(mysql)
- 上了个 MySQL 5.5.25 但是安装时出错了
- 求jsp博客源代码mvc+mysql,该如何解决
- java mysql 中文乱码有关问题
- 在<object>标签中展示SVG图时,URL变成了空,也就是src的value成了空串
- 请教各位,使用PreparedStatement mysql 数据库 不回滚,盼望解答。多谢。 具体如上
- mysql Statement parameter 一 not set
- java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost:3306,该怎么处理
- iReport中应用JavaBean作为Table的数据源:The supplied java.sql.Connection object is nul
- object error!
- MyBatis 读取 Mysql Blob类型的SQL如何写呢
- JDBC MYSQL 驱动加载失败 JSP DAO ECLIPSE,该怎么解决
- jboss4.2分布式事务出错:Could not enlist in transaction on entering meta-aware object!该怎么处理
- Only a type can be imported. com.mysql.jdbc.Driver resolves to a package解决方案
- tomcat 中抛异com.mysql.jdbc.exceptions.MySQLTransactionRollbackException,该如何处理
- struts+iBatis+mysql,该如何解决
- mysql 有外键的插入解决方案
- s:iterator 迭代 按动态名取List<Map<String,object>>解决方案
- JSP 更新 MySQL 语句时遇到异常了= =
- mysql,该如何处理
- 请问用过ksoap的前辈:Error verifying method org/ksoap2/serialization/SoapObject equals(Ljava/lang/Object;)Z
- 说说,Object 中的getClass()方法,该如何解决
- +++++ mysql 插入成功,查询不到记录?