如何从postgresql中包含单词和数字的列中提取数字

How to extract a number from a column with words and numbers in postgresql

我正在尝试在 Postgresql 中编写查询,我需要从详细信息列中提取订单号,但我只想在列中的条目包含“用作订单 x 的付款”时提取订单号,其中 x 是我需要提取的数字。我不确定如何执行此操作,因为订单号包含不同数量的数字。这是我目前所拥有的-

示例字符串 - “用作订单 1034267 的付款” 期望的输出 - 1034267

示例字符串 - “用作订单 55263 的付款” 期望的输出 - 55263

SELECT details
FROM transactions
WHERE details LIKE 'Used as payment on order%'

但这会获取整个列条目,而不仅仅是数字。我怎样才能只从条目中获取号码?

这很容易成为使用 regexp_replace() 并从输入字符串中删除所有非数字的内容:

SELECT regexp_replace(details, '[^0-9]+', '', 'g')
FROM transactions
WHERE details LIKE 'Used as payment on order%'