Generating lines based on the value of the column?
Hi allI would like to know if there is a function that can help me in creating lines based on a column value and, if so, which. I'm on version 11.2.0.3.0
for example, I have these data in the table:
ID O A C
1 5 3 5
2 9 2 3
Where ID is an identifier unique record and column C contains the number of records, I would have returned for this ID. In this example, the folder with the ID 1 would be repeated 5 times and the folder with the id 2 would be repeated 3 times. The result would look like this:
ID O A C
1 5 3 5
1 5 3 5
1 5 3 5
1 5 3 5
1 5 3 5
2 9 2 3
2 9 2 3
2 9 2 3
Column C contains the number of repetitions Records and is defined as a positive integer > = 1.
Of course, in real life, the table contains (at this time) 41 M number of records and the value of C can vary between 1 and 554, hardcode on the example above values is not possible.
Any pointers in the right direction are much appreciated.
Kind regards
Lennert
SQL> ed
Wrote file afiedt.buf
1 with t as (select 1 as id, 5 as c from dual union all
2 select 2, 3 from dual)
3 --
4 select id, c
5 from t
6 connect by level <= c
7 and id = prior id
8* and prior sys_guid() is not null
SQL> /
ID C
---------- ----------
1 5
1 5
1 5
1 5
1 5
2 3
2 3
2 3
8 rows selected.
Tags: Database
Similar Questions
-
How to merge values into a line, based on distinct values in another column
I have a table like
updatedby updateddate text
Approval John 1st May 2009 1 added file
Approval of John 1 May 2009 2 added file
May 2, 2009 1 deleted David approval form
I need the text column values to be concatenated and displayed for unique (updatedby updateddate) records. The output is something like
updatedby updateddate text
Approval of May 1, 2009 John save further approval 1 sheet, 2 added
May 2, 2009 1 deleted David approval form
I had planned to do it using PLSQL. Is there a way to achieve this in SQl...? Please suggestSQL> ed Wrote file afiedt.buf 1 with t as (select 'John' as updatedby, to_date('01-May-2009','DD-MON-YYYY') as updateddate, 'Approval record 1 added' as text from dual union all 2 select 'John', to_date('01-May-2009','DD-MON-YYYY'), 'Approval record 2 added' from dual union all 3 select 'David', to_date('02-May-2009','DD-MON-YYYY'), 'Approval record 1 removed' from dual) 4 -- END OF SAMPLE DATA 5 -- 6 select updatedby, updateddate, ltrim(sys_connect_by_path(text,','),',') as text 7 from ( 8 select updatedby, updateddate, text, row_number() over (partition by updatedby, updateddate order by text) as rn 9 from t 10 ) 11 where connect_by_isleaf = 1 12 connect by rn = prior rn+1 and updatedby = prior updatedby and updateddate = prior updateddate 13 start with rn = 1 14* order by 2 SQL> / UPDAT UPDATEDDA TEXT ----- --------- ---------------------------------------------------------------------------------------------------- John 01-MAY-09 Approval record 1 added,Approval record 2 added David 02-MAY-09 Approval record 1 removed SQL>
Edited by: BluShadow May 21, 2009 12:37
Argh! hair to the pole by SY -
assign the number to a line based on the analytical condition function
Oracle 11g Server
ID val1 val2 1 0 0a 1 1 0 b 1 2 0c 2 0 0a 2 2 0 b WITH input AS (SELECT 1 id ,0 val1 ,'0a' val2 FROM dual UNION ALL SELECT 1 id ,1 val1 ,'0b' val2 FROM dual UNION ALL SELECT 1 id ,2 val1 ,'0c' val2 FROM dual UNION ALL SELECT 2 id ,0 val1 ,'0a' val2 FROM dual UNION ALL SELECT 2 Id ,2val1 ,'0b' val2 FROM dual) SELECT * FROM input;
!-[CodeBlockEnd:ae52826b-04c5-4aa4-a6c0-1d0405656e55]-->Output:
ID val1 val2 assigned_number 1 0 0a 0 1 1 0 b 0 1 2 0c 2 2 0 0a 0 2 2 0 b 1 The dense numbering sequence must be assigned to each line based on the column id and val1.
For an identifier given, the numbering begins only after val1 > 1 until then the assigned_number will be zero.
WITH the entry INTO
(SELECT 1 id)
0 val1
'0' has val2
OF the double
UNION ALL
SELECT 1 id
1 val1
b '0' val2
OF the double
UNION ALL
SELECT 1 id
2 val1
, 0'c ' val2
OF the double
UNION ALL
SELECT 2 id
0 val1
'0' has val2
OF the double
UNION ALL
SELECT the Id 2
2val1
b '0' val2
THE DOUBLE)
SELECT id, val1, val2,
Rank() over (partition by order of case when val1 > 1 then 0 otherwise end val1) dr-1
SINCE the entry;
ID VAL1 IS DR
---------- ---------- -- ----------
1 0 0a 0
1 1 0b 0
1 2 0c 2
2 0 0a 0
2 2 0b 1
-
State of color lines based on a value in the same row
I would like to color report lines based on a value in the same row.
For bolting with the table 'EMP ':
I would like job = MANAGER and Red work = CLERK to be green etc etc.
The other example I found was the possibility of a single color either the nail or the default color.
I'm looking for a way to do multiple colors.Hello
In the model line, you can use #1 #, 2 # #, etc. to indicate where a field in the report should be released. It doesn't have to be clear - that is to say, you can use it in style tags if you wish.
So take a query such as:
SELECT EMPNO, ENAME, DEPTNO, DECODE(DEPTNO, 10, 'green', 20, 'red', 30, 'cyan', 'white') BG_COLOUR FROM EMP
You get the column 1 = empno, 2 = ename, 3 = deptno and 4 = bg_colour. In the model line, you can then do:
Before defining lines (implements the table):
<table> <tr><td>ID</td><td>Name</td><td>Dept</td></tr>
After setting (farm table) lines:
</table>
Model 1 (used for all lines) line:
<tr style="background-color:#4#;"><td>#1#</td><td>#2#</td><td>#3#</td></tr>
Then, for each row, the color that has been calculated by using the DECODE function is used in the style tag for color the background of the whole line.
How to determine the colors, it's you. I used DECODE here, but you can use a field on the DEPT table to hold and use it in your SQL statement.
Andy
-
Hide a line based on the State.
Hello, I have a requirement where I have to hide a line based on the State. I am able to highlight the lines but hide the entire line does not work.
Condition must be met on a line:
- Thus, if a sum of EXP5_11, EXP6_11, EXP7_11 and EXP8_11 in a current group is all zeros hide this line. Please refer to the RTF-model.
Attachments:
- RTF-model.
- XML file.
- Sample output generated when the lines are highlighted the meeting status.
Any help is much appreciated on how I can hide a line.
EM-: [email protected]
If please remove your IF condition and add the following code inside the foreach tag
This works very well in my test.
-
Create lines based on the difference in date
Hello
I would like to create lines based on the difference between the start and end dates (per year).
for example
ID1 Start_time End_time ID2
07/01/2003 1, 12.00.00.000000000 2005-01-07 12.00.00.000000000 12307/01/1999 1, 12.00.00.000000000 07/01/2003 12.00.00.000000000 345
I need:
ID1 Start_time End_time ID2
07/01/2004 1, 12.00.00.000000000 2005-01-07 12.00.00.000000000 12307/01/2003 1 12.00.00.000000000 07/01/2004 12.00.00.000000000 123
1 01/07/2002 12.00.00.000000000 07/01/2003 12.00.00.000000000 345
07/01/2001 1, 12.00.00.000000000 01/07/2002 12.00.00.000000000 345
07/01/2000 1, 12.00.00.000000000 01/07/2001 12.00.00.000000000 345
07/01/1999 1, 12.00.00.000000000 07/01/2000 12.00.00.000000000 345
Thank you
Hello
Here's one way:
SELECT ID1
, ADD_MONTHS (start_time, 12 * (LEVEL - 1)) AS start_time value
, ADD_MONTHS (start_time, 12 * LEVEL) AS end_time
id2
FROM table_x
CONNECT BY LEVEL<= months_between="" (end_time,="" start_time)="">=>
AND PRIOR id2 = id2
AND PRIOR SYS_GUID () IS NOT NULL
;
I'm assuming that id2 is unique.
Would what results you if end_time wasn't exactly N years after start_time?
-
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
-
Web Forms: Deleting line based on the value of a specific column
Hello
I have an online form in which I want to apply delete missing on the ranks, but only on the value of the first column. So, if the first column is #missing I want the deleted row, even if the columns are given in it.
Is it possible to do this?
I'm on ver 11.1.2.2 Hyperion Planning
Shehzad
Published by: shehzad k on January 24, 2013 11:51Unfortunately, no. There is no way to add the delete line based SOLELY on the existence of a value in the first column. It would be nice to see some of the more advanced features "conditional delete", we en flies over to the planning of the entry forms.
You can do the "clumsy" things with data validations where you gray - out ranks in view of the existence of a value in a particular cell, however while this might SUGGEST that the user should not enter data in a particular line, it would not PREVENT to do so.
We have seen many improvements in form lately with the introduction of data validations. I hope the momentum continues.
-Jake
-
the sum of the column lines based on distinct values of column B
Hi all
Here is my xml
rowset <>
< ROW >
< ORDER_NO > 103-4385509 < / ORDER_NO >
< SITE_NO > 103 < / SITE_NO >
< ORDER_ID > 4385509 < / ORDER_ID >
< CUSTOMER_ID > 2676832 < / CUSTOMER_ID >
< TAX_AMOUNT >.33 < / TAX_AMOUNT >
< CREATED_DATE > 20/08/2010 < / CREATED_DATE >
< USER_CREATED > TSDAL671 < / USER_CREATED >
< Delivery_Method > CARRY OUT STORE < / Delivery_Method >
< Entered_By > TSDAL671 < / Entered_By >
< SKU_NO > 321182 < / SKU_NO >
< NAME_TEXT > MGR_OVERRIDE < / NAME_TEXT >
< > 319 ATTRIBUTE_ID < / ATTRIBUTE_ID >
Override < ATTRIBUTE_VALUE > done < / ATTRIBUTE_VALUE >
< DETAIL_SEQ_NO > 1 < / DETAIL_SEQ_NO >
< / ROW >
< ROW >
< ORDER_NO > 103-4385509 < / ORDER_NO >
< SITE_NO > 103 < / SITE_NO >
< ORDER_ID > 4385509 < / ORDER_ID >
< CUSTOMER_ID > 2676832 < / CUSTOMER_ID >
< TAX_AMOUNT >.33 < / TAX_AMOUNT >
< CREATED_DATE > 20/08/2010 < / CREATED_DATE >
< USER_CREATED > TSDAL671 < / USER_CREATED >
< Delivery_Method > CARRY OUT STORE < / Delivery_Method >
< Entered_By > TSDAL671 < / Entered_By >
< SKU_NO > 321182 < / SKU_NO >
< NAME_TEXT > OEDTL_TAX_INFO < / NAME_TEXT >
< > 314 ATTRIBUTE_ID < / ATTRIBUTE_ID >
< ATTRIBUTE_VALUE > 441130760 | 441130760 | 441130760 | 1. 1. 1. 20100820 | 2676832 | 2. SPARE PARTS | < / ATTRIBUTE_VALUE >
< DETAIL_SEQ_NO > 1 < / DETAIL_SEQ_NO >
< / ROW >
< ROW >
< ORDER_NO > 103-4385509 < / ORDER_NO >
< SITE_NO > 103 < / SITE_NO >
< ORDER_ID > 4385509 < / ORDER_ID >
< CUSTOMER_ID > 2676832 < / CUSTOMER_ID >
< TAX_AMOUNT >.18 < / TAX_AMOUNT >
< CREATED_DATE > 20/08/2010 < / CREATED_DATE >
< USER_CREATED > TSDAL671 < / USER_CREATED >
< Delivery_Method > CARRY OUT STORE < / Delivery_Method >
< Entered_By > TSDAL671 < / Entered_By >
< SKU_NO > 412679 < / SKU_NO >
< NAME_TEXT > OEDTL_TAX_INFO < / NAME_TEXT >
< > 314 ATTRIBUTE_ID < / ATTRIBUTE_ID >
< ATTRIBUTE_VALUE > 441130760 | 441130760 | 441130760 | 1. 1. 1. 20100820 | 2676832 | 2. 0035 | < / ATTRIBUTE_VALUE >
< DETAIL_SEQ_NO > 2 < / DETAIL_SEQ_NO >
< / ROW >
I have to display 3 lines but all the sum of TAX_AMOUNT grouped by ORDER_ID, I need sum for 2 records based on the distinct value of DETAIL_SEQ
so my output should be something like below
ORDER_ID | TAX_AMOUNT | DETAIL_SEQ | ATTRIBUTE_ID
-----------------------------------------------------------------------------
4385509 | 0.33 | 1. 319
4385509 | 0.33 | 1. 314
4385509 | 0.18 | 2. 314
--------------------------------------
SUM = 0.51
------------------------------------------
Note: I can't make separate in the sql attribute_id is different for the same DETAIL_SEQ_NO.
I tired to do <? sum ([xdoxslt:distinct_values (current - group () / DETAIL_SEQ_NO)] / TAX_AMOUNT)? >
It did not work.
Can someone help me please!
Thanks in advance!This syntax will not work.
A method to do so.
-
Generate the series based on the column
Hi Experts,
Oracle9i Enterprise Edition Release 9.2.0.1.0 - Production
PL/SQL Release 9.2.0.1.0 - Production
Could you please help me to generate the folloing sequence.
act_no to_be 1 1 0 2 1 2 1 2 0 3 1 3 0 4 1 4 1 4 1 4 0 5 1 5 1 5 1 5 1 5 1 5 Based on the act_no I want to generate the sequence to_be in sql. Help, please. Thanks in advance.
You must have a column that defines the order of the line. I added a column ID that defines the order of the single column. With this you can do.
SQL > t
2 as
(3)
4. Select 1 id, 1 act_no Union double all the
5 select id 2, act_no 0 of all the double union
6 select id 3, 1 act_no Union double all the
7 select id 4, 1 act_no Union double all the
8 select id 5, 0 act_no of all the double union
9 select id 6, 1 act_no of all the double union
10. select id 7, 0 act_no of all the double union
11 select id 8, 1 act_no Union double all the
12. select id 9, 1 act_no of all the double union
13. select id 10, 1 act_no of all the double union
14 select id 11, 0 act_no of all the double union
15 select 12 id, 1 act_no of all the double union
16. select id 13, 1 act_no of all the double union
17 select id 14, 1 act_no of all the double union
18 select id 15, 1 act_no of all the double union
19 select id 16, 1 double act_no
20)
21 select t.id
22, t.act_no
23, max (t1.rno) on to_be (t.id control)
24 t
25 left
Join the 26)
27 select row_number() over (order by id) rno
28 , id
29, act_no
30 t
31 where act_no = 0 or (id = 1 and act_no = 1)
(32) t1
33 on t.id = t1.id
order of 34
35 by id;ID ACT_NO TO_BE
---------- ---------- ----------
1 1 1
2 0 2
3 1 2
4 1 2
5 0 3
6 1 3
7 0 4
8 1 4
9 1 4
10 1 4
11 0 5
12 1 5
13 1 5
14 1 5
15 1 5
16 1 516 selected lines.
SQL >
-
Query SQL to split the lines based on the amount
I have the data in the following format in the table.
ORDER_ID PRODUCT_ID QUANTITY
O1 A1 3
I need to write the sql query to divide the data in following format:
ORDER_ID PRODUCT_ID QUANTITY
O1 A1 1
O1 A1 1
O1 A1 1
Query must split the data based on the value in the quantity column.
Thank you
Developer
Hello
create table order_items ( order_id varchar2(2), product_id varchar2(2), quantity number ) ; insert into order_items values ('O1', 'A1', 3) ; -- Recursive Subquery Factoring with item(order_id, product_id, quantity) as ( select order_id, product_id, quantity from order_items union all select order_id, product_id, quantity - 1 from item where quantity > 1 ) select order_id, product_id, 1 quantity from item order by order_id ; drop table order_items purge ; Table ORDER_ITEMS created. 1 row inserted. OR PR QUANTITY -- -- ---------- O1 A1 1 O1 A1 1 O1 A1 1 Table ORDER_ITEMS dropped.
-
SQLCL - retrieves different number of lines based on the style of SQL
SQLcl: Release 4.1.0 Release Candidate on Tue Jul 14 10:24:05 2015 Copyright (c) 1982, 2015, Oracle. All rights reserved.
I need spool on CSV for 2 SQL statements for a thorough comparison. So, my appearance of SQL statements like this,
set sqlformat csv set trimspool on spool file1.csv select blah blah blah from some_table; spool off
Second SQL looks like this,
set sqlformat csv set trimspool on spool file1.csv with s1 as (sql_statement) ,s2 as (sql_Statement) select blah blah from table join s1 ... join s2 ... ; spool off
the two SQLs are stored in individual files, when I run the first sql, it reads 4400 + lines as expected and generates a CSV. When I run the second SQL (which uses WITH clause), it gets only 50 lines and stops.
Ideas or reasons for this? The second SQL is also expected to extract about 4400 lines, it's the sql developer and I can export in csv, but wait sqlcl behaves well. I guess it I'm missing something here, can someone point me to the error?
TIA
REDA
I think I understand the problem, it was a classic user error. Sorry everyone, I have an obscure where clause that I completely missed. Once removed, it worked flawlessly.
REDA
-
Select lines based on the State of the same line
Hello
I have the following table structure and lines defind here
http://sqlfiddle.com/#! 3f474/4/3
I want Select if lines
is null, then I need to select rows that have the IS_PAYABLE = 'Y '. IfPRODUCT_NO
is not nullPRODUCT_NO
then IS_PAYABLE will be ' no or IS_PAYABLE will be null.
For example
For PRODUCT_REG HPO_FABRIC, a
NULL if I need select this line only, not the other two rows.PRODUCT_NO
I can do
, but if there are many records with null or not null PRODUCT_NOselect * from SUPPLIER_DETAILS where IS_PAYABLE='Y'
How can I do this using sql?select PRODUCT_REG, PRODUCT_SUPPLIER_CODE, PRODUCT_NO, START_DATE, END_DATE, IS_PAYABLE from ( select PRODUCT_REG, PRODUCT_SUPPLIER_CODE, PRODUCT_NO, START_DATE, END_DATE, IS_PAYABLE, row_number() over (partition by product_reg order by decode(is_payable,'Y',1,'N',2,3), product_no nulls first) rn from SUPPLIER_DETAILS ) where rn = 1 PRODUCT_REG PRODUCT_SUPPLIER_CODE PRODUCT_NO START_DATE END_DATE IS_PAYABLE HPO_FABRIC JP_008 - 08/01/2001 08/31/2001 Y STG_PIL SJ_090 STG-PILLOWS 01/04/2001 01/31/2001 -
Published by: chris227 on 17.09.2012 13:30
-
Follow-up - how can I order lines based on a value from column to HFR
As discussed in my question on queries Top, I have a column that I ordered highest to lowest on a report.
I have now, thanks to mballo, have a column of row (still hidden) as well as the column that contains the values. I have 25 rows. My use of the Rank ([M, 1:25].ifNN(-1), descending) provides values but no order.
How can I get the lines sorted by the values in a particular column, then the first line has the highest value and the rest in descending order?
JIn the property sheet of grid, there is an option "comes out" about 1/2 at the bottom of the page. Once activated it will bring up a window that allows you to apply the sorting. You can take specific lines or all the rows and then apply that based on a column. Or vice versa.
-
With the help of trigger to copy lines without specifying the column names
Hello
I have a large table:
Time V0 V1 S1 S0... V800 S800
I make a copy of this table.
Then, I want to create a trigger that inserts all rows in the copy whenever they are inserted in the original:
create or replace trigger gila_dem2_trig
before inserting
on gila_dem2_1_1m
REFERRING AGAIN AS NINE OLD AND OLD
FOR EACH LINE
Start
insert into gila_dem2_1_1m_copy (V0 of time... S800) values (: new.) New time: V0.., new: S800)
end;
I want to do this without having to explicitly name the columns. Something like: nouveaux.* would be nice
but does not work.
Is there a way to do this?
Concerning
TomasWhile you can write dynamic SQL statements in triggers it won't help.
You will not be able to dynamically reference the: NEW values.
Your only choice is to specify all columns
Maybe you are looking for
-
my drop down menu at the top to access websites I have vist is it not help
My dropdown where sites I vist where type you www .or never .com this window isn't here how I get it back?
-
Microphone not work. -my words are not heard, but my breathing can be heard.
When I use my headset with an online course, my words are not heard, but my breathing can be heard. My microphone worked during testing, but not when I asked a question. Is something wrong with my microphone headphones?
-
DVD drive (E) will not play DVD, CD only
Inspiron 530 Vista. When I right click (OPEN or EXPLORE), it ejects it and says "Please insert a disk". If I double click, window States ' computer (not responding) ". I downloaded "updated the driver" of the DELL site - still does not work. Ran qu
-
HelloI have 11.1.2.1. I get the below error. I tried the solution saving as an Excel 97-2003 workbook and record of return as an Excel workbook. As my spreadsheet contains macros (.xlsm) I wasn't able to use the solution as I am missing links and the
-
don't deploy not bcc atg successfully project.
Hi allI am creating the project of TCC atg merchandising and adding an asset (product) that.but he stayed in the second last stage.Thus, I removed prod server cache.So please atg CCI expert to help me.-Aurélien.