我有一张与Oracle 12c中旧终端系统的订单相关的备注表。每个订单参考都有几行注释,按序列号排序。
我想将每个订单参考的所有相关注释连接在一起,以便我可以尝试从中提取一些地址数据。地址数据可以分布在几个不同的序列号上。结构是:
| SEQ | NOTE_TEXT | ORDER | ... |
|-----|--------------------------|-------|-----|
| 1 | The address for this | | |
| 2 | is 123 The Street, City, | | |
| 3 | County, Postcode | | |
| 1 | This customer has ordered| | |
| 2 | this product on date | | |
| 1 | Some other note | | |
| 1 | This order is for A Smith| | |
| 2 | The address is 4 The Lane| | |
| 3 | City, County, Postcode | | |
------------------------------------------------
我想把它变成:
|--------|---------------------------------------------------------------------------|
| ORDER | NOTE_TEXT |
|--------|---------------------------------------------------------------------------|
| ABC123 | The address for this is 123 The Street, City, County, Postcode |
| DEF456 | This customer has ordered this product on date |
| GHI789 | Some other note |
| JKL012 | This order is for A Smith The address is 4 A Lane, City, County, Postcode |
|--------|---------------------------------------------------------------------------|
在连接之前修剪每个音符行可能会很好,但我还需要确保在两行的连接之间放置一个空格,以防万一有人用文本填满整行。哦,序列无序,所以我也需要先订购。
感谢您的帮助!
答案 0 :(得分:3)
您可以使用listagg:
order
另请注意,"
是oracle中的保留关键字。最好使用其他标识符或使用Optional<Integer> result = Optional.ofNullable(input)
.filter(str -> str.matches("-?\\d+"))
.map(Integer::parseInt);
来逃避它。