用户名:孤月2012 文章数:54 评论数:7
访问量:3576:942:510:3 注册日期:2012-10-13
今天有人问了个关于Oracle字符串截取和拼接的问题,让我帮他写出SQL,看了下问题描述还比较清晰就试着解决下,利用午休时间把功能实现了,问题看似不难,但思路一定要清晰,不然就乱了,关键大量应用了Oracle的substr 和instr函数,下面贴出问题和脚本:
问题:sql中一个字段值为:1788987565327、768374872394903、21437238740213483874629、23412341234252345。其中顿号间隔的每一组数字位数和尾数不定,现在要使前面这个字段值中顿号前的数字尾数即7、3、9、5都分别加1,变成8、4、0、6输出成1788987565328、768374872394904、21437238740213483874620、23412341234252346。注意其中第三个数,从9加1后,输出成0,而不是10
脚本:
targetstrvarchar2(2000); strlengthnumber; positionnumber; maxpositionnumber; retrunstrvarchar2(2000); tempstrvarchar2(2000); targetstr:= '1788987565327、768374872394903、21437238740213483874629、23412341234252345' ; maxposition:=0; select LENGTH(targetstr) into strlength from dual; for i in 1..strlengthloop select instr(str, '、' ,1,i) into position from ( select targetstr as str from dual); --dbms_output.PUT_LINE(position); ifposition>0 then ifmaxposition=0 then select substr(str,0,instr(str, '、' ,1,1)-1) into retrunstr from ( select targetstr as str from dual); select TO_NUMBER(substr(restr,-1)) into endstr from ( select retrunstr as restr from dual); ifendstr=3 or endstr=5 or endstr=7 then endstr:=endstr+1; elsifendstr=9 then select substr(str,0,instr(str, '、' ,1,1)-2)||TO_CHAR(endstr) into retrunstr from ( select targetstr as str from dual); elsifmaxposition<position then select substr(str,instr(str, '、' ,1,i-1)+1,instr(str, '、' ,1,i)-instr(str, '、' ,1,i-1)-1) into tempstr from ( select targetstr as str from dual); select TO_NUMBER(substr(restr,-1)) into endstr from ( select tempstr as restr from dual); ifendstr=3 or endstr=5 or endstr=7 then endstr:=endstr+1; elsifendstr=9 then select substr(str,1,length(str)-1)||TO_CHAR(endstr) into tempstr from ( select tempstr as str from dual); retrunstr:=retrunstr '、' tempstr; maxposition:=position; ifmaxposition>position then select substr(str,maxposition-length(str)) into tempstr from ( select targetstr as str from dual); select TO_NUMBER(substr(restr,-1)) into endstr from ( select tempstr as restr from dual); ifendstr=3 or endstr=5 or endstr=7 then endstr:=endstr+1; elsifendstr=9 then select substr(str,1,length(str)-1)TO_CHAR(endstr) into tempstr from ( select tempstr as str from dual); retrunstr:=retrunstr '、' tempstr; dbms_output.PUT_LINE(retrunstr); |
运行结果如下:
原字符串:1788987565327、768374872394903、21437238740213483874629、23412341234252345
14:03:38 **** SCRIPT STARTED: 02-Apr-2015 14:0
MySql Study之--MySql日志管理
MySQL有几个不同的日志文件,可以帮助你找出mysqld内部发生的事情:
日志文件 | 日志文件信息内容 |
错误日志 | 记录启动、运行或停止mysqld时出现的问题。(log_err) |
查询日志 | 记录建立的客户端连接和执行的语句。 |
更新日志 | 记录更改数据的语句,不赞成使用该日志。 |
二进制日志 | 记录所有更改数据的语句。还用于复制。(bin_log) |
慢日志 | 记录所有执行时间超过long_query_time秒的所有查询或不使用索引的查询。(slow_query_log) |
二、查询日志存放位置
mysql>showvariableslike '%log%' ; |Variable_name|Value| |back_log| 50 | |binlog_cache_size| 32768 | |binlog_checksum|NONE| |binlog_direct_non_transactional_updates|OFF| |binlog_format|STATEMENT| |binlog_row_image|FULL| |binlog_rows_query_log_events|OFF| |binlog_stmt_cache_size| 32768 | |expire_logs_days| 0 | |general_log|OFF| |general_log_file|/ var /lib/mysql/rh6.log| |innodb_flush_log_at_trx_commit| 1 | |innodb_locks_unsafe_for_binlog|OFF| |innodb_log_buffer_size| 8388608 | |innodb_log_file_size| 5242880 | |innodb_log_files_in_group| 2 | |innodb_log_group_home_dir|./| |innodb_mirrored_log_groups| 1 | |innodb_undo_logs| 128 | |log_bin|OFF| |log_bin_basename|| |log_bin_index|| |log_bin_trust_function_creators|OFF| |log_error|/ var /log/mysqld.log| |log_output|FILE| |log_queries_not_using_indexes|OFF| |log_slave_updates|OFF| |log_warnings| 1 | |max_binlog_cache_size| 18446744073709547520 | |max_binlog_size| 1073741824 | |max_binlog_stmt_cache_size| 18446744073709547520 | |max_relay_log_size| 0 | |relay_log|| |relay_log_basename|| |relay_log_index|| |relay_log_info_file|relay-log.info| |relay_log_info_repository|FILE| |relay_log_purge|ON| |relay_log_recovery|OFF| |relay_log_space_limit| 0 | |slow_query_log|OFF| |slow_query_log_file|/ var /lib/mysql/rh6-slow.log| |sql_log_bin|ON|
订阅:
博文评论 (Atom)
|
没有评论:
发表评论