Skip to content
Advertisement

Oracle SQL: How to fetch only style tag attributes from column?

I want to fetch only style tag attributes from a column i.e., style tag between double quotes (“). Style= can be anywhere in the column. Below is the sample data:

+--------------------------------------------------------------+
|                          STYLE_ATTR                          |
+--------------------------------------------------------------+
| style="width:440px; " aria-label="Test Aria Label"           |
| data-method="getTestData" style="margin-left: 10px"          |
| id="DEMO" style="float: left; " aria-label="Test Aria Label" |
| style="font-size: 100% ; "                                   |
+--------------------------------------------------------------+

Expected: Output:

+-------------------+
|    STYLE_ATTR     |
+-------------------+
| width:440px;      |
| margin-left: 10px |
| float: left;      |
| font-size: 100% ; |
+-------------------+

Tried below code:

select SUBSTR(style_attr, INSTR(style_attr, 'style=')+6) AS style_attr from test_table

With this I am getting double quotes also in the output. Need help on how to get only style tags without double quotes.

Thanks,
Richa

Advertisement

Answer

If you’re happy with what you got but want to get rid of double quotes, so replace them with an empty string:

select REPLACE(SUBSTR(style_attr, INSTR(style_attr, 'style=')+6), '"', '') AS style_attr 
from test_table
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement