简体   繁体   中英

Need regex for SQL to extract substring from a long string

I have the below string in my database (SnowFlake)

:display_redemption_mark: 0
:redeemable_properties: '1205,1206,1207,1208,1209,1210,1211,1212,1213,1214,1215,1216,1217,1218,1225,1227,1230,1231,1232,1239,1242,1244,1249,1250,1254,1281,1282,1283,1284,1285,1286,1287,1288,1289,1290,1291,1292,1293,1294,1296,1297,1240,1247,1255'
:redemption_meta_keys: ''
:max_redemptions_in_transaction: 0
:allow_multiple_redemption_on_item: false
:allow_qualifying_items_reused: false

I want to extract the value of the redeemable_properties which in above case

1205,1206,1207,1208,1209,1210,1211,1212,1213,1214,1215,1216,1217,1218,1225,1227,1230,1231,1232,1239,1242,1244,1249,1250,1254,1281,1282,1283,1284,1285,1286,1287,1288,1289,1290,1291,1292,1293,1294,1296,1297,1240,1247,1255

I want to exclude single quote, and double quote as the whole value is a string and is stored in a column of the table. I am creating a new column with the extracted value.

Can you try this one?

select trim( regexp_substr( your_column, '.*:redeemable_properties:([^:]*):',1,1,'e' ), '''" ' ) from your_table;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM