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 5
16 selected lines.
SQL >
Tags: Database
Similar Questions
-
Auto generate the column in function
Hi all
I'm using oracle 11g on windows.
I have a table with two columns purch_id and item_code.
name of the table PURCHASE
Column name PURCH_ID number
Column name ITEM_CODE number
This composite primary key for the table (purch_id and item_code).
Item_code is autogenearted with Purch_id for example.
PURCH_ID ITEM_CODE
1080 1
1070 1
1285 1
1070-2
1 1495
I'm writing a function but not doing so to increment the ITEM_CODE 1
When the PURCH_ID are in the table.
The user will be entered only purch_id and if purch_id exists in the item_code table should then be increment of 1.
and if purch_id does not exist in the table, then item_code must be 1.
Could someone please help me fill out this complex function.
Rgds and thanks in advance
Saaz
Something like that?
CREATE OR REPLACE
FUNCTION get_item (i_purch_id in NUMBER)
RETURN NUMBER
IS
cnumber NUMBER: = 1;
v_item_number NUMBER;
v_cnt NUMBER;
BEGIN
SELECT COUNT (*) IN v_cnt
Purchase
WHERE purch_id = i_purch_id;
IF v_cnt > = 1 THEN
SELECT MAX (item_number) + 1
IN v_item_number
Purchase
WHERE purch_id = i_purch_id;
ON THE OTHER
v_item_number: = 1;
END IF;
RETURN v_item_number;
EXCEPTION
WHILE OTHERS THEN
raise_application_error (-20001,' an error has occurred - ' |) SQLCODE |' - ERROR - ' | SQLERRM);
END;
-
Generating lines based on the value of the column?
Hi all
I 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
LennertSQL> 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.
-
Totals based on values that are generated by the formula in the column
For a report of historic opportunity, we have made a new column that generates a value (the type of contract) by the calculation of the duration of the contract. For example "Short term" (less than 12 months) or "Long term" (over 3 years). We do this by the CASE statement. Now, we want to have an overview by country of the number of possibilities of "short-term" contract, the number of contract opportunities 'Long term' etc. However, it seems that we can not display the metric of opportunity 'number of possibilities' as a total according to the result of the column that shows the type of contract. Someone knows how to fix this?Create another column and use the formula Count (possibility." The opportunity ID").
Once you create this form - use a pivot and view the results
-
Update line in the column-based database
Hello
I am trying to find a way to update a row that has a SQL database based on two columns. If the command and the match number sensor order number and sales sensor that already exists in the database, I want to update the column of reading of the sensor. If not exists then I want that it creates a new line. How would I go to do this?
Thank you
Chris
You can use the tools of DB Query.vi Execute. Here is an example of a MS Access 2010 database where a column value is updated in all rows satisfying the WHERE conditions.
Ben64
-
SQL query * I want to insert a file column in the other table based on two columns
I want to insert a column records to another table based on two columns
the query below does not work
insert into def_ver_lnki_p (job_name)
Select def_job.job_name
from def_job where def_job.job_id = def_ver_lnki_p.job_id and def_job.table_id = def_ver_lnki_p.table_id;
Just to correct sql
Update
def_ver_lnki_p define job_name =)
Select def_job.job_name
of def_job
where def_job.job_id = def_ver_lnki_p.job_id
(and def_job.table_id = def_ver_lnki_p.table_id);
-
Display the value of the column automatically based on another column in a table
Hello
I use APEX 5.0, I have a requirement to display the field automatically based on the tabular presentation of other numbers.
in the screen shot attached above when I press Add button line a new line is created and enter the value in 'place no.', 'dept and identification of height place' when I press tab or get out of the column "height", "GID" should appear automatically.
To display the GID my query will be like that. "Select GID from x where no = '1011' place and dept = 88 and height = 88'.
How to get the value of from GID of the another value entered in Place no, dept and height in tabular form.
Thanks in advance
Ravi.
Hi Ravi
No need to point of Application or process. I just completed the task with the following steps
(1) create 4 hidden items
P2_SELWID
P2_SELDEPTH
P2_SELHEIGHT
P2_CALCWNAME
(2) gives 3 CSS classes in three columns of tables.
. WID
. DEPTH
. HEIGHT
(3) create the function jQuery for re - get three items from the page on a line if one of them has been changed.
Add the following code to the function and the declaration of global variables
function setRowItemValues(p_rownum){ wid_col_id = 'f02_' + rownum ; wid_col_val = $('#'+wid_col_id).val(); depth_col_id = 'f03_' + rownum ; depth_col_val = $('#'+depth_col_id).val(); height_col_id = 'f04_' + rownum; height_col_val = $('#'+height_col_id).val(); wname_col_id = 'f05_' + rownum; // set P2_SELWID,P2_SELDEPTH,P2_SELHEIGHT $s("P2_SELWID", wid_col_val ); $s("P2_SELDEPTH", depth_col_val ); $s("P2_SELHEIGHT", height_col_val ); $s("P2_SELWNAMEID", wname_col_id ); // Call the Dynamic Action to get WNAME if all values are not null if( wid_col_val != '' && depth_col_val != '' && height_col_val != '' ){ //Call DA to Get WNAME from WINT $.event.trigger("CalcWNAME"); // set the Tabular form $('#'+wname_col_id).val($x("P2_CALCWNAME").value); } }
and run when the Page loads
$(document).on("change", ".WID,.DEPTH,.HEIGHT", function(){ rownum = $(this).attr('id').substr(4); setRowItemValues(rownum); });
(4) create a dynamic Action to get WNAME based on a PL/SQL function. Note the submitted page elements.
CalcWNAME
(5) set of the corresponding element in the line of the function jQuery, after completing the DA.
Please check and I hope your problem is now solved.
Concerning
Mahmoud
-
Hello
Actually I got to know this update of a record must be made when the primary key is based on two columns.
Previously, I used SPEL for a column. It was working fine.
But I came to know that regardless of the folder I try to update, it was the update page is coming up with the first combination of the record.
As if RC 131
RC 124
RC 125 are the records.
If I click on update of RC 124 also, the update page is coming up with RC 131 values as it is the first.
So I understand that the SPEL should be based on two parameters, because it is a composite key.
How to do?
Please let me know if you don't understand the problem.
Thank you.
Wow!
I got it.
Thank you brothers, always a hope that you could help me
-
Hi all
I haven't worked much on tabular forms and JS. I'm looking for help in this regard.
I'm working on a tabular presentation. with several editable fields... I need to disable a column (just for this single line), which contains an image, based on a field of LOV (static) list) (Y/N). The image column must be disabled if the value is N.
My SQL for the report is something like this: (will keep things simple)
Select
emp_id,
emp_name,
static_list,
(case when STATIC_LIST = "Y" THEN ' < a title = "Edit SAMPLE TBL" href = "f?) p = & APP_ID.:10: & APP_SESSION.:NO:P10_EMP_ID, P10_EMP_NAME :'|| EMP_ID | «, » || EMP_NAME | "" "> < img src =" "#IMAGE_PREFIX #SAMPLE.gif" border = '0' (> < /a > ' other ' ' end) as disable_col, "
dept_name
of sample_table
I scoured the topics in this forum. Most of them were made using the table ID f_001, f_002.
I tried to follow the same path by inspecting the item but the disable_col does not have any ID. Let's say, f_003 is for the static list and f_004 is assigned to dept_name.
I tried dynamic actions, but it did not work. Read in a topic that dynamic action does not work on tables. So I chose this approach. Is there a simpler way to solve this?
need your help on how to proceed with this scenario. Thank you in advance.
Versions: Apex: 4.2, DB: 11 g
Thank you
Daniel
Hi Daniel_A,
Daniel_A wrote:
I did my job in Page 4.
If the IS_VALID column is select as 'Yes' then the column hyper must be enabled, allowing the user to click on it. If she chose the 'no', then the column Hyper must be disabled for this line.
The initial question about toggle the hyperlink is resolved. Check your App-> Page 4 35160.
This is done with the help of two dynamic actions:
- DA first loading of the Page / after updating of region "tabular":
Event: After refresh
Selection type: region
Region: The other 'tabular '.
Condition: No strings attached
Action: Run the JavaScript Code
Fire on loading the Page: Yes
Code:
$( 'select[name="f08"]' ).each(function() { if ( $(this).val() === "N" ) { $(this).closest("tr").find('td[headers="HYPER"]').find("a").addClass("apex_disabled").unbind("click"); } });
Items concerned: no item affected
- Second DA on the evolution of the selection list:
Event: change
Selection type: jQuery Selector
jQuery Selector: select [name = "f08"]
Condition: No strings attached
Action: Run the JavaScript Code
Fire on loading the Page: No.
Code:
var el = this.triggeringElement; if ( el.value === "N" ) { $(el).closest("tr").find('td[headers="HYPER"]').find("a").addClass("apex_disabled").unbind("click"); } else { $(el).closest("tr").find('td[headers="HYPER"]').find("a").removeClass("apex_disabled").bind("click"); }
Items concerned: no item affected
NOTE: as the original question/topic related to toggle the image link in the column, for the problem with the Page 5, please create a new thread with the details.
Kind regards
Kiran
-
Deactivation of the column in a table based on the setting in the search box
Hi all
I use Oracle Apex 4.1. I have two region
1. search box
2. in the form of a table
In the search box, I have a LOV field where the user can select the value. Based on this LOV in the search box, tabular column f06 must disable or read-only.
For example if I select THREE in LOV then only column f06 is expected on the other it must disable. How to get there.
Thanks in advance
Ravi
Hi Bobo,
Hope link below will solve your query.
Disable the column in a table.
BR,
Patrick
-
What is the API to generate the unit price based on price list (advanced price)?
Hello!
I'm looking for the api generate the price unit, based on the price list in advanced pricing. In addition, how will I know what are the manual available modifiers / header lines that can be applied to my order?
Thank you.
The api to use is QP_PREQ_PUB. PRICE_REQUEST. You must complete all the variables table with the point attribute information and qualifier info to get a table at the back the modifiers that can be applied. Check:
HOW to use QP_PREQ_PUB. PRICE_REQUEST API at the price of an item (Doc ID 759804.1)
-
generate the value of the column according to the conditions
statement to generate the selection inputsBANNER Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production PL/SQL Release 11.2.0.3.0 - Production CORE 11.2.0.3.0 Production TNS for HPUX: Version 11.2.0.3.0 - Production NLSRTL Version 11.2.0.3.0 - Production
entryWITH t AS ( SELECT 1 job_request_id, 1 original_job_request_id, mod(level,3) +1 sequence_cd, CHR (LEVEL + 100) value_txt, NULL new_sequence_cd FROM DUAL CONNECT BY LEVEL < 6), t1 AS ( SELECT 2 job_request_id, 1 original_job_request_id, mod(LEVEL,2) + 1 sequence_cd, CHR (LEVEL + 110) value_txt, NULL FROM DUAL CONNECT BY LEVEL < 10), t2 AS ( SELECT 3 job_request_id, 3 original_job_request_id, mod(LEVEL,3) + 7 sequence_cd, CHR (LEVEL + 95) value_txt, NULL FROM DUAL CONNECT BY LEVEL < 9), t3 AS ( SELECT 4 job_request_id, 3 original_job_request_id, mod(LEVEL,2) + 1 sequence_cd, CHR (LEVEL + 95) value_txt, NULL FROM DUAL CONNECT BY LEVEL < 7), t4 AS ( SELECT 7 job_request_id, 3 original_job_request_id, mod(LEVEL,2) + 1 sequence_cd, CHR (LEVEL + 92) value_txt, NULL FROM DUAL CONNECT BY LEVEL < 4), mytable AS (SELECT * FROM t UNION ALL SELECT * FROM t1 UNION ALL SELECT * FROM t2 UNION ALL SELECT * FROM t3 UNION ALL SELECT * FROM t4) SELECT * FROM mytable order by job_request_id, original_job_request_id, sequence_cd;
expected resultsJOB_REQUEST_ID ORIGINAL_JOB_REQUEST_ID SEQUENCE_CD VALUE_TXT NEW_SEQUENCE_CD 1 1 1 g 1 1 2 h 1 1 2 e 1 1 3 i 1 1 3 f 2 1 1 v 2 1 1 p 2 1 1 r 2 1 1 t 2 1 2 u 2 1 2 q 2 1 2 o 2 1 2 s 2 1 2 w 3 3 7 b 3 3 7 e 3 3 8 ` 3 3 8 f 3 3 8 c 3 3 9 d 3 3 9 a 3 3 9 g 4 3 1 e 4 3 1 c 4 3 1 a 4 3 2 b 4 3 2 ` 4 3 2 d 7 3 1 ^ 7 3 2 ] 7 3 2 _
my attempt to explain.JOB_REQUEST_ID ORIGINAL_JOB_REQUEST_ID SEQUENCE_CD VALUE_TXT NEW_SEQUENCE_CD 1 1 1 g 1 1 1 2 h 2 1 1 2 e 2 1 1 3 i 3 1 1 3 f 3 2 1 1 v 4 2 1 1 p 4 2 1 1 r 4 2 1 1 t 4 2 1 2 u 5 2 1 2 q 5 2 1 2 o 5 2 1 2 s 5 2 1 2 w 5 3 3 7 b 7 3 3 7 e 7 3 3 8 ` 8 3 3 8 f 8 3 3 8 c 8 3 3 9 d 9 3 3 9 a 9 3 3 9 g 9 4 3 1 e 10 4 3 1 c 10 4 3 1 a 10 4 3 2 b 11 4 3 2 ` 11 4 3 2 d 11 7 3 1 ^ 12 7 3 2 ] 13 7 3 2 _ 13
If the job request id = id of the new cd of sequence = sequence cd original job application
When the employment application IDS are higher than the original increment the new cd of sequence with respect to the maximum of the original work request id sequence cd.
I hope that the expected results will clarify.Hello
It looks like you want DENSE_RANK, except that you want to ignore the numbers (for example, 6 in this example) when necessary so that new_sequence_cd > = sequence_cd.
With the help of analytical functions:
WITH got_drank AS ( SELECT m.* , DENSE_RANK () OVER ( ORDER BY job_request_id , original_job_request_id , sequence_cd ) AS drank FROM mytable m ) SELECT job_request_id , original_job_request_id , sequence_cd , value_txt , drank + MAX ( sequence_cd - drank ) OVER ( ORDER BY job_request_id , original_job_request_id , sequence_cd ) AS new_sequence_cd FROM got_drank ORDER BY job_request_id , original_job_request_id , sequence_cd ;
You can also use the MODEL.
If you have a new_sequence_cd column in a table, one you want to fill, use the query in a MERGE statement above.
-
How to divide the data in the column based identifier
Hello
I use the oracle database.
I have data in this format in my column 1234 ~ 2345 ~ 3456 ~ 4567.
I need a motion to split the data in the column based on the identifier ' ~', so that I can choose the value after the second occurrence of the identifier.
Do I know who can do this.
Published by: 962987 on October 3, 2012 12:11Hello
Welcome to the forum!
Whenever you have any questions, please post CREATE TABLE and INSERT statements for some examples of data and the results desired from these data. For example, in view of these data
CREATE TABLE table_x ( my_column VARCHAR2 (40) ); INSERT INTO table_x (my_column) VALUES ('1234~2345~3456~4567'); INSERT INTO table_x (my_column) VALUES ('just~2 parts');
I think you're asking for these results
PART_3 MY_COLUMN ---------- ---------------------------------------- 3456 1234~2345~3456~4567 just~2 parts
I suppose that, if the string does not contain at least 2 ' ~ s, you want to return null. It's a good idea to explain what you want like that for special cases and include examples in your sample data and results.
Not all versions of Oracle are exactly the same. In fact, they are all different. If you want the best solution that works with your version, then say what version it is.
The following query will work in Oracle 10.1 and higher:SELECT REGEXP_SUBSTR ( my_column , '[^~]+' , 1 , 3 -- 3rd occurrence (after 2nd delimiter) ) AS part_3 , my_column -- if wanted FROM table_x ;
See the FAQ forum {message identifier: = 9360002}
Published by: Frank Kulash, October 3, 2012 15:24
Adding sample data and results. -
Selectively hiding a row in a Table based on the value of the column
I have a data control that is populated from pro-grammatically, based on the user's selection in the page one of wanting to hide some lines on page 2 at the same time, I don't want to delete the value binding, is there to hide the lines instead of column?To the table of the ADF, to hide the lines according to the requirement, use the visible property on each of the columns.
For example, if you do not want to display all the lines that have IDs Director like 200 or 201.
Thank you
Nini -
How update the column in the table based on the value selected in apex4.1
Hi all
I have the following tables,
and it has the values as follows,leave_type table,it has the following fields, 1.emp_name, 2.sick 3.casual
leave_master table and it includes the following fieldsemp_name sick casual guru 10 10 mishra 10 10
I have the form based on the table "leave_master"1.emp_name, 2.leave_type 3.no_of_days
Here, the leave_type has the LOV which includes.
sick and casual.
When the form is filled out and clicked on the button submit,
I need to update the column leave_type in table leave_type,
for example,.
then I want to update the leave_type column,if emp_name:guru leave_type:sick no_of_days:3
sick sick = - no_of_days for the 'guru' of name
That is to say, ill = 10-3 = 7
then the leave_type of the table must be,
someone can such me what code or method I can use?emp_name sick casual guru 7 10 mishra 10 10
Thank you.
Published by: Gurujothi on May 24, 2012 21:54
Published by: Gurujothi on May 24, 2012 21:54Try something like this...
BEGIN
IF: PXX_LEAVE_TYPE = "Sick" THEN
UPDATE LEAVE_TYPE
THE PATIENT VALUE = SICK -: PXX_NO_OF_DAYS
WHERE EMP_NAME =: PXX_EMP_NAME;
ON THE OTHER
UPDATE LEAVE_TYPE
DEFINE CASUAL = CASUAL -: PXX_NO_OF_DAYS
WHERE EMP_NAME =: PXX_EMP_NAME;
END IF;
COMMIT;
END;
Maybe you are looking for
-
Why stock PIN request when you use Apple pay?
I use iPhone 6 with 64 GB, with 27.8 MB of available space, with iOS 9.3.2 I was happy until today to be able to use Apple pay Walgreen pharmacies. Today Apple pay (or something) forced me to enter my pin code of the debit card, I've always used. Wha
-
Only 1/3 of my favorites imported IE. How can I move the rest?
I have a lot of bookmarks into folders hierarchical sometimes 3 deep. Only some of them and the first level of folders, have been imported. How can I get them all? Manually? [Pathetic groan] I spent about 40 minutes of reading on the bookmarks on the
-
HP Pavilion e109nr 17: HP Pavilion 17-e109nr windows 7
My client bought a WIN8 machine last year and would like to re-intall a 64-bit version of Win7. However. the HP download site watch support only win 8 and win 10 drivers. Is there a way to get Windows 7 drivers for this machine? It is a HP Pavilion e
-
My problem is that my mouse stops working after a few minutes in a certain way. Usually, the main program that I will be ok, but I can't click anything on the bar in the toolbar at the bottom. Even if I move my pointer over the icons on the taskbar,
-
When typing cursor always goes back a few keys so it of difficult to finish the sentence
When typing cursor always goes back a few keys so it of difficult to finish the sentence