break the values of columns in separate lines
HelloI have a query that returns the values of 4 columns of it. Of this, a column can have many values it contains separated by semocolon (-). The requirement now is if this particular column has more than one value, separated by the semocolon (-), then the query must return each of them separately as a new line and keep the rest, column values as common for each of these values of this colummn.
For example, select...
output:
col1 col2 col3
Risk of BB IE6 71 of the PACK_PWRMART file. DELETE_POSITION_WO_RISK ($FEEDINSTANCEID); PACK_PWRMART. DELETE_INSTRU_REL_POS_WO_RISK; QC 8401
COL4
2010-02-11 09:29:45 December 28, 2010
Now, col3 has 3 values separated by (;). Therefore, the output of the query
col1 col2 col3( now split with 3 values) col4
71 BB IE6 risk file PACK_PWRMART.DELETE_POSITION_WO_RISK($FEEDINSTANCEID) 2/11/2010 9:29:45 AM 28-Dec-2010
72 BB IE6 risk file PACK_PWRMART.DELETE_INSTRU_REL_POS_WO_RISK 2/11/2010 9:29:45 AM 28-Dec-2010
73 BB IE6 risk file QC 8401 2/11/2010 9:29:45 AM 28-Dec-2010
The solution that I thought:I don't know if this can be achieved in a single SQL statement, so I thought I should write a block of code that will use the collection separate each of the value of this column and use some sort of record of object to insert the entire line in it 3 times (or the number of times as much as the values in this column) , but without success.
Something like this:
declare
type feed_name is table of varchar2(4000);--feed_static.feed_description% type INDEX BY PLS_INTEGER;
feed_nm feed_name;
param_val feed_name;
dat feed_name;
feed_desc feed_name;
str number;
str1 varchar2(1000);
begin
select feed_description as "Feed Name" ,
param_value as "Post_Proc Prarameter",
'28-Dec-2010' as "COB date",
ft.feed_type_description as "Feed Type"
BULK COLLECT INTO feed_nm,param_val,dat,feed_desc
from feed_static fs, feed_parameter fp, feed_type ft
where fs.feed_id =fp.feed_id
and fs.feed_type_id = ft.feed_type_id
and fs.feed_type_id not in (4,15,16,25)
and fp.param_name = 'postproc'
and fp.close_action_id is null
and fs.feed_description in ('BB 0J0 risk file')--,'BB 1J1 risk file')
order by fs.feed_type_id,feed_description;
FOR i IN 1..param_val.count
loop
select length((param_val(i))) - length(replace(param_val(i),';')) into str from dual;
dbms_output.put_line(str);
for j in 1..str
loop
SELECT SUBSTR(param_val(i), 1 ,INSTR(param_val(i), ';', 1, j)-1) into str1 FROM dual;
dbms_output.put_line(str1);
str1:=' ';
end loop;
end loop;
end;
But the "dbms_output.put_line (str1); does not give me o/p as required except the first value (assume thr are the 3 values of the column).Also I'm not sure of what I'm trying to do is in the right direction or not.
I have not used any RECORDING still to poulate values separated again (I'm not sure about hoe to use)
Cam anyone help me please with this code.
Rgds,
Aashish
Try this:
select feed_description as "Feed Name" ,
param_value as "Post_Proc Prarameter",
'28-Dec-2010' as "COB date",
--ft.feed_type_description as "Feed Type" ,
regexp_substr( ft.feed_type_description,'[^;]+',1,rown.seq)
from feed_static fs, feed_parameter fp, feed_type ft, (SELECT LEVEL seq FROM DUAL
CONNECT BY LEVEL<=max(length(ft.feed_type_description)- length(replace(ft.feed_type_description,';'))))rown
where fs.feed_id =fp.feed_id
and fs.feed_type_id = ft.feed_type_id
and fs.feed_type_id not in (4,15,16,25)
and fp.param_name = 'postproc'
AND rown.seq<=(length(ft.feed_type_description)- length(replace(ft.feed_type_description,';')))
and fp.close_action_id is null
and fs.feed_description in ('BB 0J0 risk file')--,'BB 1J1 risk file')
order by fs.feed_type_id,feed_description;
regexp_count started in 11g. It counts the number of models in a particular string. I replaced by length - length (repalce).
You can replace the word 'max (length (ft.feed_type_description) - length (replace(ft.feed_type_description,';'))))' with 10 or 15, i.e. the maximum number of semicolons in the chain
Tags: Database
Similar Questions
-
change the color of line based on the value of column 5 Apex in the classic report
Version of the apex 5.0.0.00.31
Standard universal theme
Page theme default template
Classic report
Foldable report template
Hello
I know this question has been asked several times here, but I'm working on 5 Apex and need to know the correct way to do it in this version.
I need to change the color of the text of the entire line (no background color) based on the value in one of the columns of the classic report. I have just two conditions, if the value of column = Yes, color should be red, otherwise it must be green.
I am new to jscript and css, so appreciate if someone can tell me the solution with steps.
I have already checked this link that changes the value of the column, need to do something similar to the whole line.
https://tylermuth.WordPress.com/2007/12/01/conditional-column-formatting-in-apex/
Hi coolmaddy007-Oracle,.
Here's an example set up on the apex.oracle.com according to the specifications you gave: https://apex.oracle.com/pls/apex/f?p=35467:1
Version of the apex 5.0.0.00.31
Standard universal theme
Page theme default template
Classic report
Foldable report template
Here is how it is done:
Create a dynamic action with the following specifications:
Name: Give the appropriate name
Event: After refresh
Selection type: region
Region: select your region classic report
Condition: No strings attached
Action: Run the JavaScript Code
Fire on loading the Page: Yes
Code:
$('td[headers="JOB"]').each(function() { if ( $(this).text() === 'MANAGER' ) { $(this).closest('tr').find('td').css({"color":"red"}); } if ( $(this).text() === 'SALESMAN' ) { $(this).closest('tr').find('td').css({"color":"green"}); } if ( $(this).text() === 'CLERK' ) { $(this).closest('tr').find('td').css({"color":"blue"}); } });
NOTE: Download the selector appropriate for your knowledge $('td[headers="JOB"]') case using firebug/browser development tools.
Items concerned: leave blank.
PS: Changed the example to change the color of text instead of the background color.
I hope this helps!
Kind regards
Kiran
-
How to access the values in column fron a report (region)
Hello
In the region of report footer section, I want to access the value of a column (e.g. name col = COL01) for first place. I know that I can access total number of rows using #TOTAL_ROWS #. Is it possible to do this?
Thanks in advance,
PareshHello
I did not have a v2 to try this out, but try this:
1. in your report, add the following in the header of the region:
<div id="TheReport">
2 - in the foot of the region:
</div> <script type="text/javascript"> var t = document.getElementById("TheReport"); var r = t.getElementsByTagName("TABLE")[1]; var rows = r.rows; var tds = rows[0].cells; var k; if (tds) { for (k = 0; k < tds.length; k++) { if (tds[k].id == 'ENAME') { alert(rows[1].cells[k].innerHTML); } } } </script>
Remove your old javascript code and replace line alert() with all you need to do with the value of .cells [k] .innerHTML lines [1].
This includes in your report in a div tag The JavaScript find it and gets the second table (the table report is a table of the area which is now within the DIV tag). As older versions of the Summit has not used the attribute "headers" on cells, we check the ID values for the column headings in row [0] - once we found the right column, we retrieve the corresponding value according to the data in row of lines [1].
Andy
-
Request to remove row where the value of column contains alphabets
Hello
Could someone please help me to get this application working.
Request to remove row where the value of column contains alphabets.
DELETE FROM BIN_ITEM WHERE order_nmb LIKE '% [A - Z] % ' | LIKE '% [a - z] %'
Thank you and best regards,
Madam.
SELECT order_nmb FROM BIN_ITEM WHERE regexp_count(order_nmb,'[0-9]') = 0
----
Ramin Hashimzade
-
Returns the value of column line
Greetings! I currently have a request we will tell
SELECT value, period FROM MAS_CFUS_KEYACM_CONTROLDATA ORDER BY cf_keyword_ID
RESULTS
Period value
--------------------------
100.0002 1 JANUARY 14
-35.68 1 DECEMBER 14
-1943.67 NOVEMBER 1, 14
678.0013 OCTOBER 1, 14
This continues for about 15 results by cf_keyword_ID.
I'm looking to return the VALUE first in a new column called PREV1, the second value of PREV2, third in PREV3 and so on. The same goes for the dates. And all this for only the first 10 values of each cf_keyword_ID. Can anyone suggest the best way to achieve this?
Thank you!!
Hello
This is called pivoting. Because I don't have a copy of your table test, I'll use scott.emp to illustrate.
This shows the first 3 employees for each job, in order by hiredate, along with their hiredates:
WITH relevant_data AS
(
SELECT ename, job, hiredate
row_number () taken OVER (PARTITION OF work
ORDER BY hiredate
) AS r_num
FROM scott.emp
)
SELECT *.
OF relevant_data
PIVOT (MIN (ename) AS ename
MIN (hiredate) AS hiredate
FOR r_num (1, 2, 3)
)
ORDER BY job
;
Output:
WORK 1_ENAME 1_HIREDATE 2_ENAME 2_HIREDATE 3_ENAME 3_HIREDATE
--------- ---------- ----------- ---------- ----------- ---------- -----------
ANALYST FORD 3 December 1981 SCOTT April 19, 1987
The CLERK SMITH December 17, 1980, 3 December 1981 JAMES MILLER January 23, 1982
MANAGER JONES 2 April 1981 BLAKE 1 May 1981 CLARK June 9, 1981
PRESIDENT KING November 17, 1981
SELLER ALLEN 20 February 1981 WARD 22 February 1981 TURNER 08-Sep-1981
There are actually more than 3 SECRETARIES and SALESMEN. Which does not cause an error; the only first 3 are shown.
As you can see, having less of 3 does not cause any errors, either.
For more info on pivots, see the FAQ of the Forum:
Re: 4. How can I convert rows to columns?
I hope that answers your question.
If this isn't the case, please post a small example of data (CREATE TABLE and only relevant columns, INSERT statements) for all of the tables involved and also publish outcomes from these data.
Explain, using specific examples, how you get these results from these data.
If yod post rather a problem using scott.emp, then you need not display the sample data; just results and explanations.
Always say what version of Oracle you are using (for example, 11.2.0.2.0).
See the FAQ forum:
-
Coverting a line in the values in columns
Hi friends Expert SQL,
I have a line that contains 6 columns where I want the data to appear in the form of columns, as shown here:
From:
Select item1, item2, item3, amt1, amt2, amt3 in item_table, when sno = 1; <-returns 1 row as below
ITEM1 ITEM2 ITEM3 AMT1 AMT2 AMT3
---------- ------------ ------------- ----------- ------------ ----------
AAA BBB CCC 10,00 20,00 15,00
Explanation of data: item1 (AAA) price is amt1 (10.00), item2 (BBB) price is amt2 (20 h 00) and item3 (CCC) price is amt3 (15.00). Ok.
Now I want that data to be converted to columns, as shown here:
TO:
AMT ELEMENTS
--------- ---------
AAA 10.00
BBB 20.00
CCC 30.00
Please help me guys, I want a SQL to display these data.
I found a single query that converts a row of columns, but this is not my requirement: [for your reference only]
SQL > select substr (the_string
, decode (level, 1, 1, instr(the_string,',',1,level-1) + 1)
, decode (instr(the_string,',',1,level), 0, length (the_string), instr(the_string,',',1,level) - decode (level, 1, 0, instr(the_string,',',1,level-1))-1)
) the_value
from (select (select item1 |)) «, » || Item2. «, » || Item3 item_table where sno = 1) ELEMENTS
the double)
connect by level < = length (the_string) - length (replace(the_string,',')) + 1
Thank you and best regards,
KiranWITH pivot_data AS (SELECT 'AAA' ITEM1, 'BBB' ITEM2, 'CCC' ITEM3, '10.0' AMT1, '20.0' AMT2, '15.00' AMT3 FROM DUAL) SELECT t1.items, t.amount FROM (SELECT NULL items, amount, ROWNUM rn FROM pivot_data UNPIVOT INCLUDE NULLS (amount FOR items IN (AMT1, AMT2, AMT3) )) t, (SELECT items, NULL amount, ROWNUM rn FROM pivot_data UNPIVOT INCLUDE NULLS (items FOR amount IN (ITEM1, ITEM2, ITEM3))) t1 WHERE t.rn = t1.rn
ITEMS AMOUNT AAA 10.0 BBB 20.0 CCC 15.00
-
Add the value of column based on a different line with the same id
Hello world
I have a query that displays the first three columns of the table below. I would like to add a column to this output, most indicating (for each row) if there is an electronic product in the same order. For example, the command 1 in the table below contains 1 unit of furniture and 1 unit of electronics. In my outings, I would add a flag 'Y' for the two rows 1 and 3. Also, I would add a "N" indicator to any order which does contain all the electronics.
Any ideas on how to achieve this? Any idea or suggestion is appreciated!
order_id product_cat quantity with_electronics 1 furniture 1 THERE 2 grocery 1 N 1 Electronics 1 THERE Thank you
Zsolt
Hi, Zsolt,
You can also use analytical functions. For example:
SELECT order_id, product_cat, quantity
MAX (CASE
WHEN product_cat = 'electronics '.
THEN 'Y '.
ANOTHER "N".
END
) OVER (PARTITION BY order_id) AS with_electronics
Orders
;
Of course, I can't test it without a table.
-
Problems with slot-shaped table and set the values of column
Hello
I have a problem with a tabular presentation.
I have two tables
P_detail and table v_master
columns of v_master:
v_id
v_Name
v_info
columns of p_detail:
P_ID
p_master_fk
p_name
p_info
I want to have a tabular presentation where I can store permanent data retail values. That's why I want to keep the default main column join the detail columns.
In SQL, I can do this with an outer join:
SELECT m.v_name, d.p_master_fk, d.p_name, d.p_info
OF v_master, p_detail
WHERE v_id = p_master_fk (+)
I get the lines that exist for the master data and can add values for the columns of detail. I removed the "add lines" because that makes no sense, because the amount lines are already offered at the opening of the tabular presentation.
Now, I want to get/save the v_id (main table) in the p_master_fk column value
How can I do this?
Thank you and best regards,
MatthiasHello
One approach is to use a database instead trigger. If you define a database view using the query:
SELECT m.v_id, m.v_name, d.p_id, d.p_master_fk, d.p_name, d.p_info
OF v_master m, p_detail d
WHERE v_id = p_master_fk (+)Then, create a trigger on the view that will insert in the detail table if d.p_id is null and update the secondary table if d.p_id is not null instead.
The Apex tabular form is then based on the view (with identifiers like hidden columns) and all treatments multirow Apex should work without modification.
Rod West
-
By passing the value in column IR to package Oracle
All,
I try to call a package Oracle of APEX and must pass the value of a column of IR in this packaging. I tried saying: ADJ_ID but I don't think his pasing anything for the backend.
Here are the steps.
1. the user runs IR
2. There is a column that I put as "ROLLBACK" on this report for each line that has a LINK that calls URLS like
JavaScript:apex.confirm (' safe to restore adaptation? "," SEND");
3. once the user confirms submit, I call the package, package gets called but I want to send a value for that line to the package, I do this by saying: (colon) rating but it does not work.
Thank you
VishalYou must set you page item (as you try to pass by using the method of colon in PLSQL) first
You can change your link to
* JavaScript:apex.confirm ("Sure to restore adaptation?", {request: 'SUBMIT', value: {"P1_ROW_VALUE": 10}}); *
P1_ROW_VALUE is the Page element that you want to set and 10 here is specific to the LINE value
If you use the "links" section in the report attributes
and then, something like that would* JavaScript:apex.confirm ('Safe to restore the fit?', {request: "SUBMIT", value: {'P1_ROW_VALUE': ' #COLUMN_ALIAS #'}}); *
Alias_de_colonne is the name of the column you want to set the element with the value.
Published by: 814948 on November 23, 2010 08:46
-
How to extract the values of column aliases based on different column values?
Hello gurus,
I have a table with the following struture-
And try to find the values of the column as"drop table T; create table T(Name, Symbol, Amount,dep) as select 'Anderia', 'AA', 1050000,'HR' from dual union all select 'Michael', 'ML',150000,'Sales' from DUAL union all select 'Bill', 'BL', 1050000,'Finance' from dual union all select 'Nancy', 'NY', 4000,'HR' from DUAL union all select 'Anderia', 'AA',3000,'HR' from dual union all select 'Michael', 'ML',1050000,'Sales' from DUAL union all select 'Bill', 'BL', 1200000,'Finance' from DUAL union all select 'Anderia', 'AA', 1200000,'HR' from DUAL union all select 'Vish', 'VH', 1200000,'Marketing' from DUAL;"
Name, symbol, dep, amount, % Total, Total $Cumm, rank but some additional as-columns
Amount HR, % HRTotal, $HR Cumm Total,
Finance amount, FinanceTotal %, $Finance Cumm Total
Sales amount, a percentage of Total sales, $Sales Cumm Total.
Amount marketing, MarketingTotal %, $Marketing Cumm Total
then I use the following query to retrieve the name, the symbol, the dep, amount, % Total, Total $Cumm, rank columns.
But I want to extract the following columns so... How can I do?select name , decode(grouping(symbol), 0, symbol, 'Total') symbol , dep , sum(amount) amount , sum(per_total) "% Total" , decode(grouping(symbol), 0, max(Cum_per_total), null) "% Cumm Total" , decode(grouping(symbol), 0, max(rank), null) rank from ( select name , symbol , dep , amount , per_total , sum(per_total) over(order by rk) cum_per_total , rank , rk from ( select name , symbol , dep , sum(amount) amount , round((sum(amount)/max(total_amount)) * 100,2) per_total , dense_rank () over (order by sum(amount) desc) as rank , row_number() over(order by sum(amount) desc) as rk from ( select name , symbol , amount , dep , sum(amount) over() total_amount , sum(amount) over () from t ) group by name, symbol, dep ) ) group by grouping sets((name, symbol, dep), ()) order by rank, max(rk) nulls last
Amount HR, % HRTotal, $HR Cumm Total,
Finance amount, FinanceTotal %, $Finance Cumm Total
Sales amount, a percentage of Total sales, $Sales Cumm Total.
Amount marketing, MarketingTotal %, $Marketing Cumm Total
as I want that all records, then will the dep..do-specific I need to use the case here?
Thanks for all your time and effort in advanceIf I understand your needs, you need pivot: SQL and PL/SQL FAQ
-
"All the values in column" change in the dash prompt
In OBIEE 11 g, how to change the dashboard prompt label everything value? I don't want to change the value in the XML file, because it will prompt value impact all the dashboard.
This is there best method to implement this problem?
For example:
In prompt dashboard-> edit-> options-> check ' include "All values in the column" in the list ", so I can display value"(toutes les valeurs de colonne) ' in the command prompt. " Customers want to change this value, such as 'all values '. Is this possible? Thank you.Hello
Can do this by using Union All is prompt, SQL and variable presentation in the report.
Reference: http://www.varanasisaichand.com/2010/01/editing-all-choices-in-dashboard.html
Kind regards
Srikanth -
ADF: Assigning the value of column VO to OutputText.
Hi all
I have a VO who im showing as ADF read Table only. And one column that VO should be included outside of this table, I mean, I don't want to include this column in the table that I want to assign the value of the column to Text output component (Active).
I want to assign the value of the column to the output text component.
How can I achieve this.
I think im clear with my requirement.
Any answer will be really grateful.Please read this before posting
https://forums.Oracle.com/forums/Ann.jspa?annID=56am now back to the topic.
tell as an example.
Here, I had to employee vo drag and drop as readonly af:table employee.
in this readonly af:table no need to show their id of employee, but you don't want to show this id used as some text output at the top / bottom of the table.
I think reason?. as it comes to your condition.If am so right, moving later.
Drag and drop the af: table without employee id. and then drag and drop the employee as af text id: output
important: employee select id in the user interface that came out text go to partial property inspector trigger are at table.You may wonder why I like this mean?
If you like this then means that move through the records of documents / select in af:table means revalent employee id get you. This way you get the desired results. :)Thanks & cordially
ADF7. -
How can I compare the value of column within the COUNT() function?
I want to compare the value of the column within the COUNT() function as below how ever it gives me the error. I want to calculate the percentage, how can I do this task?
Thank you.
SELECT department_id
, COUNTY (salary < 250000) / COUNT (*)
OF plch_employees
GROUP BY department_id
ORDER BY department_id;SELECT department_id. COUNT(CASE WHEN salary < 250000 THEN 1 END) / COUNT(*) FROM plch_employees GROUP BY department_id ORDER BY department_id /
SY.
-
Change the value of column select and insert different
Hi all
I've written a procedure where I am selecting values in other tables and inserting into a new table. The code is below
If you see line 54 in the code, you will find the combined_bu_code is comes from a procedure and the value of BU is stored in prod. Table SEM_BACKLOG_LOG. I need to check, if the combined_bu_code came as PWR then insert as table BACKLOG_OTD_NEW POWER not as PWR.
You are looking for assistance on this. Thanks in advance
Concerning
Published by: User_Apex on June 23, 2011 03:03
Published by: User_Apex on June 23, 2011 03:53DECODE(SMTC_OTD_CHART.get_combined_bu_code(a.BU), 'PWR', 'POWER', SMTC_OTD_CHART.get_combined_bu_code(a.BU)) COMBINED_BU_CODE
Kind regards
Richard-----
blog: http://blog.warp11.nl
Twitter: @rhjmartens
If you answer this question, please mark the thread as closed and give points where won... -
Clear the check box according to the value of column DB
Hello
My requirement is to disable the check box according to the value of a column DB. Say for example my report displays the following. Check box, the name of the EMP, Dept. If the Department is the checkbox should be disabled and user should not be able to select the check box.
Ask your help for a solution.
Thank you
PrasanthYou must use the parameter p_attributes of the apex_item.checkbox API to make the boxes off (readonly do not work with the checkboxes)
SELECT .. CASE WHEN
THEN APEX_ITEM.CHECKBOX(1, ) ELSE APEX_ITEM.CHECKBOX(1, ,'disabled="disabled"') END ..
Maybe you are looking for
-
tried to re set now I can't get past a loading error "the proxy server refuses connections."
I tried the "reset Firefox" button and now I can't get Firefox it loads. Get error "the proxy server refuses connections." I'm not on a LAN, just a computer at home, how can I fix?
-
HP laptop - 15-f233wm: external monitor connected to the HDMI port has video but NO sound
If I connect an external monitor to the HDMI port and check my audio device on the right on the screen cone winder it displays 2 only) 1 HP and Intel) 2 Audio display speakers and No HDMI option selection.
-
Re: Speakers Crackle on Satellite A100-049
I've only had my phone for over a year, but for about six months now the top speakers crackle. Especially when I play music but it can happen when matches are played on there also. Why is this?
-
Calculator & paint in the Notification area.
Could you, please, help me to add the 'calculator' and 'paint' in the notification area on my XP SP3! NOT for the quick launch.
-
Remote Desktop program elements not drawn
We use Sage Line 50 v21 under Remote Desktop on Server 2008 R2 accessible from Windows 7 Professional SP 1. When some windows are open several fields and buttons do not appear until the user clicks on them, specifically VAT return options window. Can