SQL中特定字符串及内容提取问题

平淡的牛马 2017-12-04 10:12:00
各位大神,最近遇到了一个棘手的问题。在postgresql表格中,有一列内容全是字符,格式如图。现在想提取每一栏中MEDICATIONS ON ADMISSION:后的内容(也就是提取Carvedilol,到Coumadin.的全部字符串)。求大神指导,另外我参考了别人的做法写了一条代码substring(ne.text, 'MEDICATIONS ON ADMISSION: (.*?)\n,') as medications,但总是返回空值,其中的通配符也不理解,请大神指教。
...全文
530 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
道素 2017-12-05
  • 打赏
  • 举报
回复
忘了解释我的写法了 substr(string, from [, count]) 我上面的写法将from换成逗号也行 我的那种写法表示从Medications on admission:开始 . 点后表示到哪里为止(到任意之后后有个换行位置,就是到行尾) 比如: substring('foobar' from 'o.b') = oob
道素 2017-12-05
  • 打赏
  • 举报
回复
你试试用这个:

substring(notes from 'Medications on admission:.*\n') as medications

select substring('ALLERGIES: The dddd.

Medications on admission: Synthroid, Trileptal, Lamictal, Klonopin, MOBIC, and Flagyl. 
Physical Examination on Admission: Temperature 36.7 degrees, heart rate 85, blood pressure 138/78, respiratory rate 18, and O2 saturation 98% on room air. The patients physical examination is notable for an' from 'Medications on admission:.*\n') as medications


+------------------------------------------------------------------------------------------+
| medications                                                                              |
+------------------------------------------------------------------------------------------+
| Medications on admission: Synthroid, Trileptal, Lamictal, Klonopin, MOBIC, and Flagyl. 
 |
+------------------------------------------------------------------------------------------+
OwenZeng_DBA 2017-12-04
  • 打赏
  • 举报
回复
这是SQL SERVER版块,PG的去PG的版块问吧..

27,582

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 应用实例
社区管理员
  • 应用实例社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧