mysql 提取字符串数据,MySQL REGEX-从字符串中提取数据

I am stuck... I have a field (Description) in MySQL with a very long string. Embedded in that string is a reference number that I need to extract to another field using a view. The string will look something like this.

LOREM IPSUM DOLOR SIT AMET CONSECTETUR ADIPISCING ELIT INTEGER NEC ODIO XX00000000X LIBERO SED CURSUS ANTE DAPIBUS DIAM SED NISI NULLA QUIS SEM AT NIBH ELEMENTUM IMPERDIET

What I need from that string is XX00000000X. It always starts with two letters, numbers in the middle and ends with a letter.

I have the following query:

SELECT

Description,

SUBSTRING_INDEX (Description, ' ', (Description REGEXP '[[:upper:]]{1,2}[[:digit:]]+[[:upper:]]$') * -1 ) AS Reference

FROM db_test.tbl_regex;

The problem is that it only collects the Reference data when it is at the end of the Description field.

解决方案

REGEXP_SUBSTR() was introduced in MariaDB 10.0.5 and MySQL 8.0.

That is what you need to locate and extract the XX00000000X.

REGEXP (as you used it) only returns true/false. SUBSTRING_INDEX() needs the string.

If you can't upgrade to one of those, the best you can do is use REGEXP to identify rows that have XX00000000X, then use your app code to extract it.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
PHP 手册 Mehdi Achour Friedhelm Betz Antony Dovgal Nuno Lopes Hannes Magnusson Georg Richter Damien Seguy Jakub Vrana 其他贡献者 2007-12-10 Philip Olson 文翻译人员: 王远之 肖理达 肖盛文 黄啸宇 宋琪 陈伯乐 刘铭 © 1997-2007 PHP 文档组 版权信息 前言 入门指引 简介 简明教程 安装与配置 安装前需要考虑的事项 Unix 系统下的安装 Mac OS X 系统下的安装 Windows 系统下的安装 PECL 扩展库安装 还有问题? 运行时配置 语言参考 基本语法 类型 变量 常量 表达式 运算符 控制结构 函数 类与对象(PHP 4) 类与对象(PHP 5) Namespaces 异常处理 引用的解释 安全 简介 总则 以 CGI 模式安装时 以 Apache 模块安装时 文件系统安全 数据库安全 错误报告 使用 Register Globals 用户提交的数据 魔术引号 隐藏 PHP 保持更新 特点 用 PHP 进行 HTTP 认证 Cookie 会话 处理 XForms 文件上传处理 使用远程文件 连接处理 数据库永久连接 安全模式 PHP 的命令行模式 函数参考 .NET — .NET 函数 Apache — Apache 特有函数 APC — APC 可选 PHP 缓存 APD — APD 高级 PHP 调试器 Arrays — Array 数组函数 Aspell — Aspell 函数(已废弃) BBCode — BBCode Functions BC math — BC math 高精度数学函数 bcompiler — BCompiler PHP 字节码编译器 Bzip2 — Bzip2 压缩函数 Calendar — Calendar 日历函数 CCVS — CCVS API 函数(已废弃) Classes/Objects — Classes/Objects 类/对象函数 Classkit — Classkit 函数 ClibPDF — ClibPDF Functions [deprecated] COM — COM 和 .Net(Windows)函数 Crack — Crack Functions ctype — Character Type Functions CURL — CURL, Client URL Library Functions Cybercash — Cybercash Payment Functions CyberMUT — Credit Mutuel CyberMUT functions Cyrus IMAP — Cyrus IMAP administration Functions Date/Time — Date/Time 日期/时间函数 DB++ — DB++ Functions dba — Database (dbm-style) Abstraction Layer Functions dBase — dBase Functions DBM — DBM Functions [deprecated] dbx — dbx Functions Direct IO — Direct IO Functions Directories — Directory 目录函数 DOM — DOM Functions DOM XML — DOM XML Functions enchant — enchant Functions Errors and Logging — Error Handling and Logging Functions Exif — Exif Functions Expect — Expect Functions fam — File Alteration Monitor Functions FDF — Forms Data Format Functions Fileinfo — Fileinfo Functions filePro — filePro Functions Filesystem — Filesystem 文件系统函数 Filter — Filter Functions Firebird/InterBase — Firebird/InterBase Functions Firebird/Interbase (PDO) — Firebird/Interbase Functions (PDO_FIREBIRD) FriBiDi — FriBiDi Functions FrontBase — FrontBase Functions FTP — FTP 函数 Function handling — Function Handling Functions GeoIP — GeoIP Functions gettext — Gettext Functions GMP — GMP Functions gnupg — gnupg 函数 gopher — Net_Gopher haru — Haru PDF Functions hash — hash Functions HTTP — HTTP 函数 Hyperwave — Hyperwave Functions Hyperwave API — Hyperwave API Functions i18n — i18n 函数 IBM (PDO) — IBM Functions (PDO_IBM) ibm_db2 — IBM DB2, Cloudscape and Apache Derby Functions iconv — iconv Functions id3 — ID3 Functions IIS Functions — IIS Administration Functions Image — Image 图像函数 Imagick Image Library IMAP — IMAP, POP3 and NNTP Functions Informix — Informix Functions Informix (PDO) — Informix Functions (PDO_INFORMIX) Ingres II — Ingres II Functions IRC Gateway — IRC Gateway Functions Java — PHP / Java Integration JSON — JSON 函数 kadm5 — KADM5 LDAP — LDAP Functions libxml — libxml Functions Lotus Notes — Lotus Notes Functions LZF — LZF Functions Mail — Mail 邮件函数 Mailparse — Mailparse Functions Math — Math 数学函数 MaxDB — MaxDB PHP Extension MCAL — MCAL Functions mcrypt — Mcrypt Encryption Functions MCVE — MCVE (Monetra) Payment Functions Memcache — Memcache Functions mhash — Mhash Functions Mimetype — Mimetype Functions Ming (flash) — Ming functions for Flash Misc. — Miscellaneous Functions mnoGoSearch — mnoGoSearch Functions MS SQL Server — Microsoft SQL Server Functions MS SQL Server (PDO) — Microsoft SQL Server and Sybase Functions (PDO_DBLIB) Msession — Mohawk Software Session Handler Functions mSQL — mSQL Functions Multibyte String — Multibyte String Functions muscat — muscat Functions MySQLMySQL 函数 MySQL (PDO) — MySQL Functions (PDO_MYSQL) mysqli — MySQLi 扩展库 Ncurses — Ncurses Terminal Screen Control Functions Network — Network Functions Newt — Newt Functions NSAPI — NSAPI-specific Functions Object Aggregation — Object Aggregation/Composition Functions Object overloading — Object property and method call overloading OCI8 — Oracle 函数 ODBC — ODBC Functions (Unified) ODBC and DB2 (PDO) — ODBC and DB2 Functions (PDO_ODBC) OGG/Vorbis — oggvorbis openal — OpenAL Audio Bindings OpenSSL — OpenSSL Functions Oracle — Oracle 函数(已废弃) Oracle (PDO) — Oracle Functions (PDO_OCI) Output Control — Output Control 输出控制函数 OvrimosSQL — Ovrimos SQL Functions Paradox — Paradox File Access Parsekit — Parsekit Functions PCNTL — Process Control Functions PCRE — Perl 兼容正则表达式函数 PDF — PDF 函数 PDO — PDO Functions phar — Phar archive stream and classes PHP Options/Info — PHP Options&Information POSIX — POSIX Functions POSIX Regex — POSIX 扩展正则表达式函数 PostgreSQL — PostgreSQL 数据库函数 PostgreSQL (PDO) — PostgreSQL Functions (PDO_PGSQL) Printer — Printer Functions Program Execution — Program Execution Functions PS — PostScript document creation Pspell — Pspell Functions qtdom — qtdom Functions radius — Radius Rar — Rar Functions Readline — GNU Readline Recode — GNU Recode Functions RPMReader — RPM Header Reading 函数 runkit — runkit Functions SAM — SAM - Simple Asynchronous Messaging Satellite — Satellite CORBA client extension [deprecated] SCA — SCA Functions SDO — SDO Functions SDO DAS XML — SDO XML Data Access Service Functions SDO-DAS-Relational — SDO Relational Data Access Service Functions Semaphore — Semaphore, Shared Memory and IPC Functions SESAM — SESAM Database Functions Session PgSQL — PostgreSQL Session Save Handler Sessions — Session 会话处理函数 shmop — Shared Memory Functions SimpleXML — SimpleXML functions SNMP — SNMP 函数 SOAP — SOAP Functions Sockets — Socket Functions SPL — Standard PHP Library (SPL) Functions SQLite — SQLite Functions SQLite (PDO) — SQLite Functions (PDO_SQLITE) ssh2 — Secure Shell2 Functions Statistics — Statistics Functions Streams — Stream Functions Strings — String 字符串处理函数 SVN — Subversion 函数 SWF — Shockwave Flash Functions swish — Swish Functions Sybase — Sybase Functions TCP Wrappers — TCP Wrappers Functions tidy — Tidy Functions Tokenizer — Tokenizer Functions Unicode — Unicode Functions URLs — URL 函数 Variables — Variable 变量函数 Verisign Payflow Pro — Verisign Payflow Pro Functions vpopmail — vpopmail Functions W32api — W32api 函数 WDDX — WDDX Functions win32ps — win32ps Functions win32service — win32service Functions xattr — xattr Functions xdiff — xdiff Functions XML — XML 语法解析函数 XML-RPC — XML-RPC 函数 XMLReader — XMLReader functions XMLWriter — XMLWriter Functions XSL — XSL functions XSLT — XSLT Functions YAZ — YAZ Functions YP/NIS — YP/NIS Functions Zip — Zip File Functions Zlib — Zlib Compression Functions PHP at the Core: A Hacker's Guide to the Zend Engine The PHP 5 build system Extension structure Memory management Working with variables Writing functions Working with classes and objects Working with resources Working with INI settings Working with streams PDO Driver How-To Extension FAQs Zend Engine 2 API reference Zend Engine 1 The future: PHP 6 and Zend Engine 3 FAQ — FAQ:常见问题 一般信息 邮件列表 获取 PHP 数据库问题 安装 — 安装常见问题 编译问题 使用 PHP PHP 和 HTML PHP 和 COM PHP 和其它语言 从 PHP/FI 2 移植到 PHP 3 从 PHP 3 移植到 PHP 4 从 PHP 4 移植到 PHP 5 杂类问题 附录 PHP 及其相关工程的历史 Migrating from PHP 5.1.x to PHP 5.2.x Migrating from PHP 5.0.x to PHP 5.1.x 从 PHP 4 移植到 PHP 5 从 PHP 3 移植到 PHP 4 从 PHP/FI 2 移植到 PHP 3 PHP 的调试 配置选项 php.ini 配置选项 所支持时区列表 扩展库分类 函数别名列表 保留字列表 资源类型列表 支持的协议/封装协议列表 可用过滤器列表 所支持的套接字传输器(Socket Transports)列表 PHP 类型比较表 解析器代号列表 Userland Naming Guide 关于本手册 开放出版许可协议 函数索引 补充说明
1. HIVE结构 6 1.1 HIVE架构 6 1.2 Hive 和 Hadoop 关系 7 1.3 Hive 和普通关系数据库的异同 8 1.4 HIVE元数据库 9 1.4.1 DERBY 9 1.4.2 Mysql 10 1.5 HIVE的数据存储 11 1.6 其它HIVE操作 11 2. HIVE 基本操作 12 2.1 create table 12 2.1.1 总述 12 2.1.2 语法 12 2.1.3 基本例子 14 2.1.4 创建分区 15 2.1.5 其它例子 16 2.2 Alter Table 17 2.2.1 Add Partitions 17 2.2.2 Drop Partitions 17 2.2.3 Rename Table 17 2.2.4 Change Column 18 2.2.5 Add/Replace Columns 18 2.3 Create View 18 2.4 Show 19 2.5 Load 19 2.6 Insert 21 2.6.1 Inserting data into Hive Tables from queries 21 2.6.2 Writing data into filesystem from queries 21 2.7 Cli 22 2.7.1 Hive Command line Options 22 2.7.2 Hive interactive Shell Command 24 2.7.3 Hive Resources 24 2.7.4 调用python、shell等语言 25 2.8 DROP 26 2.9 其它 27 2.9.1 Limit 27 2.9.2 Top k 27 2.9.3 REGEX Column Specification 27 3. Hive Select 27 3.1 Group By 28 3.2 Order /Sort By 28 4. Hive Join 29 5. HIVE参数设置 31 6. HIVE UDF 33 6.1 基本函数 33 6.1.1 关系操作符 33 6.1.2 代数操作符 34 6.1.3 逻辑操作符 35 6.1.4 复杂类型操作符 35 6.1.5 内建函数 36 6.1.6 数学函数 36 6.1.7 集合函数 36 6.1.8 类型转换 36 6.1.9 日期函数 36 6.1.10 条件函数 37 6.1.11 字符串函数 37 6.2 UDTF 39 6.2.1 Explode 39 7. HIVE 的MAP/REDUCE 41 7.1 JOIN 41 7.2 GROUP BY 42 7.3 DISTINCT 42 8. 使用HIVE注意点 43 8.1 字符集 43 8.2 压缩 43 8.3 count(distinct) 43 8.4 JOIN 43 8.5 DML操作 44 8.6 HAVING 44 8.7 子查询 44 8.8 Join处理null值的语义区别 44 9. 优化与技巧 47 9.1 全排序 47 9.1.1 例1 48 9.1.2 例2 51 9.2 怎样做笛卡尔积 54 9.3 怎样写exist/in子句 54 9.4 怎样决定reducer个数 55 9.5 合并MapReduce操作 55 9.6 Bucket 与 sampling 56 9.7 Partition 57 9.8 JOIN 58 9.8.1 JOIN原则 58 9.8.2 Map Join 58 9.8.3 大表Join的数据偏斜 60 9.9 合并小文件 62 9.10 Group By 62 10. HIVE FAQ: 62

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值