Make a column based on another value of the column in the same table
JDev 11.1.1.6.0
It may be a silly question but I'm stuck
I need to conditionally return a column that said Condition is as if the value in the other column of the same table B is equal to F. I should make A column only when this condition is met. I tried the following code:
< af:column sortProperty = "PhoneNumber1." | |
sortable = "false". | |
headerText = "#{bindings." A.hints.PhoneNumber1.label}. | |
ID = "c146. | |
rendering = "#{rank." PhoneNumber1ResponseFlag eq 'F'} ">" | |
< af:outputText value = "#{rank." PhoneNumber1}. | |
ID = "ot130" / > | |
< / af:column > | |
< af:column sortProperty = "PhoneNumber1ResponseFlag." | |
sortable = "false". | |
headerText = "#{bindings." B.hints.PhoneNumber1ResponseFlag.label}. | |
ID = "c80" rendered = "true" > | |
< af:outputText value = "#{rank." PhoneNumber1ResponseFlag}. | |
ID = "ot129" / > | |
< / af:column > |
The data presented in the table for the PhoneNumber1ResponseFlag column are F. Still my condition does not work.
Well, I've finally sorted it myself by managed bean.
Here are the steps I followed:
- Wrote a new bean managed.
- Added a Boolean variable called flag and made to true when the "'PhoneNumber1ResponseFlag ' current line attribute is equal to F."
- Changing the property made column on this indicator.
Tags: Java
Similar Questions
-
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
-
comparing string values in the same table
I have a table with ID (14 digit string values) starting with "A". Ex: A21849B1020792. There may be a different ID with the same substring 'B1020792' in the same table, example: A12349B1020792. If this happens, the ID of the last creation date of must be returned in the result. In other words, comparison is done on the same table. "In the example provided, say A12349B1020792 has the date of 1 January 2015 'and A21849B1020792 has date February 1, 2015", since A21849B1020792 has the most recent date, the result must contain only A21849B1020792.
ID create_date
--- ------------------
A21849B1020792 02/01/2015
A12349 B1020792 01/01/2015
A12345B1234567 01/03/2015
A43567B1234567 01/04/2015
Here's the query I used:substr (a.id, 7) select sc, max (a.create_date) cd1
of table a, table b
where a.id! = b.id
and substr (a.id, 7) = substr (b.id, 7)
and a.id like 'A %' and b.id like 'A %' / * (I used a % because I am interested only IDs that begin with A) * /.
and a.id ('A12349B1020792', 'A21849B1020792','A12345B1234567 ','A43567B1234567')
Group of substr (a.id, 7);
Result:
---------
sc cd1
--- ------
B1020792 02/01/2015
B1234567 04/01/2015
There is one thing that I'm not able to do with my request, that is, be able to get real IDs list and not list of substrings. If I added a.id column in the select clause and the group by clause, the query includes both by substr (a.id, 7) and a.id and as a result, the query returns four lines as below:
substr (a.id, 7) select sc, max (a.create_date) cd1, a.id ID
of table a, table b
where a.id! = b.id
and substr (a.id, 7) = substr (b.id, 7)
and a.id like 'A %' and b.id like 'A %' / * (I used a % because I am interested only IDs that begin with A) * /.
and a.id ('A12349B1020792', 'A21849B1020792','A12345B1234567 ','A43567B1234567')
Group by substr (a.id, 7), a.id.
Result:
---------
sc cd1 ID
--- ------ ---------
01/01/2015 A12349B1020792 B1020792
B1020792 01/02/2015 A21849B1020792
B1234567 01/03/2015 A12345B1234567
B1234567 01/04/2015 A43567B1234567
My goal is to retrieve a list of all the unique identifiers that have the later dates.
ID:
---
A21849B1020792
A43567B1234567
Thanks for your time in advance!
Hello
user11951344 wrote:
I have a table with ID (14 digit string values) starting with "A". Ex: A21849B1020792. There may be a different ID with the same substring "B1020792" in the same table, example: A12349B1020792. If this is the case, the ID of the last creation date must be returned in the result. In other words, comparison is done on the same table. "In the example provided, say A12349B1020792 updated 1 January 2015 ' and A21849B1020792 a date February 1, 2015", as A21849B1020792 has the most recent date, the result should contain only the A21849B1020792.
ID create_date
--- ------------------
A21849B1020792 02/01/2015
A12349B1020792 01/01/2015
A12345B1234567 03/01/2015
A43567B1234567 01/04/2015
Here's the query I used:
substr (a.id, 7) select sc, max (a.create_date) cd1
of table a, table b
where a.id! = b.id
and substr (a.id, 7) = substr (b.id, 7)
and a.id like 'A %' and b.id like 'A %' / * (I used a % because I am interested only IDs that begin with A) * /.
and a.id ('A21849B1020792', 'A12345B1234567', 'A12349B1020792', 'A43567B1234567')
Group of substr (a.id, 7);
Result:
---------
sc cd1
--- ------
B1020792 02/01/2015
B1234567 01/04/2015
There is one thing that I am not able to do with my request, that is, the ability to retrieve the list of IDs real and not a list of substrings. If I added a.id column in the select clause and the group by clause, the query groups according to the two substr (a.id, 7) and a.id and as a result, the query returns four lines as below:
substr (a.id, 7) select sc, max (a.create_date) cd1, a.id ID
of table a, table b
where a.id! = b.id
and substr (a.id, 7) = substr (b.id, 7)
and a.id like 'A %' and b.id like 'A %' / * (I used a % because I am interested only IDs that begin with A) * /.
and a.id ('A21849B1020792', 'A12345B1234567', 'A12349B1020792', 'A43567B1234567')
Group by substr (a.id, 7), a.id.
Result:
---------
sc cd1 ID
--- ------ ---------
B1020792 01/01/2015 A12349B1020792
B1020792 02/01/2015 A21849B1020792
B1234567 03/01/2015 A12345B1234567
B1234567 01/04/2015 A43567B1234567
My goal is to retrieve a list of all the unique identifiers that have the later dates.
ID:
---
A21849B1020792
A43567B1234567
Thanks for your time in advance!
If it makes sense to treat the first 6 characters of the ID separately from the rest of the id in this problem, maybe it makes sense to store those two parts of the id in two different columns. Relational databases work best when each column of each row contains 1 single piece of data (at most). It is so fundamental to the design of table that he called the first normal form.
Given that the two parts are stored in column 1, so you can something like this Request Top - N:
WITH got_r_num AS
(
SELECT r.id
r.create_date AS cd1
, RANK () OVER (PARTITION OF SUBSTR (r.id, 7))
ORDER BY r.create_date DESC
) AS r_num
FROM table_x g - g for data values
JOIN table_x r - r for related values
ON SUBSTR (r.id, 7) = SUBSTR (g.id, 7)
WHERE g.id IN ('A12349B1020792'
, "A21849B1020792".
, "A12345B1234567".
, "A43567B1234567".
)
- AND g.id LIKE 'A %' - if necessary. The above condition ensures already g.id start with "A".
AND r.id LIKE 'a % '.
)
SELECT id, create_date
OF got_r_num
WHERE r_num = 1
;
If you would care to post CREATE TABLE and INSERT instructions for the sample data, and then I could test this.
-
Updated with the values in the same table, for other records corresponding to conditions
Hi Experts,
Sorry do not provide the structure of the table (it is a simple structure)
I have a requirement where I need to update the columns of a table based on the same table with some match empid and date values. If the date and empid match so I have these values to any other folder and update of one who is not having details of Office . I need the Update query
Before the update my array of values is as below
Sort_num Emp_id Bureau start_date
1 101 AUS 01/01/2013
2 101 01/01/2013
3 101 15/01/2013
4 103 USA 01/05/2013
5 103 01/01/2013
6 103 05/01/2013
7 104 FRA 01/10/2013
8 104 10/01/2013
9 104 01/01/2013After update my table should be as below
Sort_num Emp_id Bureau start_date
1 101 AUS 01/01/2013
2 101 AUS 01/01/2013
3 101 15/01/2013
4 103 USA 01/05/2013
5 103 01/01/2013
6 103 USA 01/05/2013
7 104 FRA 01/10/2013
8 104 FRA 01/10/2013
9 104 01/01/2013Thanks in advance
I don't have the time to create the table with the data, but basically, you should be able to code the following text
update one table
Office set = (select desktop in table b where b.emp_id = a.emp_id)
and b.start_date = a.start_date
and b.office is not null
)
where is ([as well as overall query])
and a.office is null
In my opinion, who will do the trick.
HTH - Mark D Powell.
-
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
-
Update the value of the column based on another value of the column to another table
Hi all
I have something very confused me and need your help.
Having two tables A and B.
Table A have 2 column (+ id + and desc1)
Table B have column 2 also (+ transnum + and desc2)
Now, I want to update the column desc2 of table B identical desc1 of table was where transnum of Table B same as the id of the table has.
I use this SQL
update of a2 set a2.desc2 = a1.desc1 of a2 on a2.transnum = a1.id inner join a1
but this error occurs
Error from line 5 in order:
update of a2 set a2.desc2 = a1.desc1 of a2 on a2.transnum = a1.id inner join a1
Error in the command line: 5 column: 35
Error report:
SQL error: ORA-00933: SQL not correctly completed command
* 00933. 00000 - "command not properly ended SQL."
* Question: *.
* Action. *
Hope someone can help me. TQ for help...SQL> create table a1 (id number(2),des varchar2(10)); Table created. SQL> create table b1 (transnum number(2),des varchar2(10)); Table created. SQL> insert into a1 values (1,'maran'); 1 row created. SQL> insert into b1 values (1,'ram'); 1 row created. SQL> commit; Commit complete. SQL> update b1 set des=(select des from a1 where b1.transnum=a1.id); 1 row updated. SQL> select * from b1; TRANSNUM DES ---------- ---------- 1 maran
-
update of column based on the values of the same table
I have the T1 table with 4 columns "col1", "col2", "col3", "col4", "col5", "col6" as follows
Col1 Col2 Col3 Col4 Col5 Col6
1111 Ville1 C AA DDD A1
2222 city SD HHH A1 1
3333 City2 B EE OOO
4444 City 1 B JJ SSS A1
5555 City2 C KK VVV
6666 City2 RR QQQ
7777 City2 B BBB XX
I've already updated column value 6 'A1' where the 2 column is 'Ville1 '.
Now, I want to update Col. 6 where col2 is the of ' with the following conditions
If Col 3 = 'B', then Col6 should be = col4
Otherwise, it should be = col5SET col6 = DECODE(col3,'B',col4,col5)
"WHERE col2 = s" -
Need a script to select the update the row to another row in the same table
I have a table with the columns and values
I need to update the InactiveDate of a line with the EffectiveDate of a line with the EffectiveDate newer than the update line and the even KeyID.KeyID EffectiveDate InactiveDate 1 01/01/2013 1 01/02/2013 1 01/03/2013 2 12/31/2012 2 01/02/2013 2 01/03/2013
I want to have a select script that showsKeyID EffectiveDate InactiveDate 1 01/01/2013 01/02/2013 1 01/02/2013 01/03/2013 1 01/03/2013 2 12/31/2012 01/02/2013 2 01/02/2013 01/03/2013 2 01/03/2013
Thanks for any help.KeyID EffectiveDate InactiveDate New_InactiveDate 1 01/01/2013 01/02/2013 1 01/02/2013 01/03/2013 1 01/03/2013 2 12/31/2012 01/02/2013 2 01/02/2013 01/03/2013 2 01/03/2013
Published by: 881656 on January 3, 2013 17:57
Published by: 881656 on January 3, 2013 18:15
Published by: 881656 on January 3, 2013 18:20Hello
881656 wrote:
I have a table with the columns and valuesKeyID EffectiveDate InactiveDate 1 01/01/2013 1 01/02/2013 1 01/03/2013 2 12/31/2012 2 01/02/2013 2 01/03/2013 I need to update the InactiveDate of a row with the EffectiveDate of a row with the newer EffectiveDate than the row to be updated and with the same KeyID. KeyID EffectiveDate InactiveDate 1 01/01/2013 01/02/2013 1 01/02/2013 01/03/2013 1 01/03/2013 2 12/31/2012 01/02/2013 2 01/02/2013 01/03/2013 2 01/03/2013
This sounds like a job for the analytical function of LEAD:
MERGE INTO table_x dst USING ( SELECT keyid , effectivedate , LEAD (effectivedate) OVER ( PARTITION BY keyid ORDER BY activedate ) AS inactivedate ) src WHEN MATCHED THEN UPDATE ON ( src.id = dst.id AND src.effectivedate = dst.effectivedate ) SET dst.inactivedate = src.inactivedate ;
I want to have a select script which shows KeyID EffectiveDate InactiveDate New_InactiveDate 1 01/01/2013 01/02/2013 1 01/02/2013 01/03/2013 1 01/03/2013 2 12/31/2012 01/02/2013 2 01/02/2013 01/03/2013 2 01/03/2013
Once that you have done the above MERGER, it is simply:
SELECT * FROM table_x ORDER BY keyid , effectivedate ;
If you do not have sthe FUSION, then see the query in the USING clause of the MERGER.
I hope that answers your question.
If not, post a small example data (CREATE TABLE and only relevant columns, INSERT statements), and the results you want from this data.
In the case of a DML (UPDATE), for example, the sample data should show what looks like the tables before the DML, and the results will be the content of the table changed after the DML.
Explain, using specific examples, how you get these results from these data.
Always say what version of Oracle you are using (for example, 11.2.0.2.0).
See the FAQ forum {message identifier: = 9360002} -
Create a query to compare the values in the same table
Suppose you have the table, below even ID occur for the same month as well as different months
ID value of months
--------------------------------------------------------------
226220 201203 100
1660 201204 200
26739 201204 1010
7750 201205 31.1
I need a query to determine the results laid below
The month ID value Prior_month_value Prior_Month
----------------------------------------------------------------------------
1234 201203 10 201201 100
3456 201206 56.1 201204 78
Help, please
Published by: Jaguar on 10 July 2012 03:00With the information we have, it's the best we can get to...
SQL> with t as (select 226220 as ID, 201203 as Month, 100 as Value from dual union all 2 select 1660, 201204, 200 from dual union all 3 select 26739, 201204, 1010 from dual union all 4 select 7750, 201205, 31.1 from dual) 5 -- 6 -- end of example data 7 -- 8 select decode(rownum,1,1234,3456) as id 9 ,decode(rownum,1,201203,201206) as month 10 ,decode(rownum,1,10,56.1) as prior_month_value 11 ,decode(rownum,1,201201,201204) as prior_month 12 ,decode(rownum,1,100,78) as value 13 from ( 14 select * from t where rownum <= 2 15 ) 16 / ID MONTH PRIOR_MONTH_VALUE PRIOR_MONTH VALUE ---------- ---------- ----------------- ----------- ---------- 1234 201203 10 201201 100 3456 201206 56.1 201204 78
Waste in... trash out.
-
Looping through the names of columns that are based on a value of the variable
I have an ArrayCollection collection with a series of columns named price1, price2... through price10
I try through these columns based on a value of the loop variable, but may not understand the syntax:
for (var column: int = 1; column < 11; column ++) {}
testPrice = myGrid.selectedItem.price (column); <-this does not work
}Try testPrice = myGrid.selectedItem ["price" + column];
Don't forget to test this selectedItem is not null before you try to set the values.
TS
-
Display list items based on another element of the list
Hi all
I want to display the list item based on another element of the list, but his does not work.
This is my code:
/ * WHEN-NEW-FORM-INSTANCE * /-his work.
DECLARErg_district recordgroup;
rg_name VARCHAR2 (40): = "district";
vtemp NUMBER;
BEGIN
rg_district: = FIND_GROUP (rg_name);
IF ID_NULL (rg_district)
THEN
rg_district: =.
CREATE_GROUP_FROM_QUERY (rg_name,
'select dist, dist district_mas.
);
vtemp: = POPULATE_GROUP (rg_district);
POPULATE_LIST ('BLOCK3.) Of RIDING ", rg_name);
END IF;
END;
* / CHANGED AFTER a - list * /-does not work. Cannot complete the list based on the list
DECLARE
rg_branch recordgroup;
rg_name1 VARCHAR2 (1000): = "branch";
vtemp NUMBER;
BEGIN
rg_branch: = FIND_GROUP (rg_name1);
IF this is ID_NULL (rg_branch)
THEN
DELETE_GROUP (rg_name1);
rg_branch: =.
CREATE_GROUP_FROM_QUERY
("rg_branch",
"SELECT FROM dist_branch WHERE district IN branch (DIST DISTRICT_MAS WHERE DISTRICT = SELECT').
|| : BLOCK3. DISTRICT OF
);
vtemp: = POPULATE_GROUP (rg_branch);
POPULATE_LIST ('BLOCK3.) Branch of THE ', rg_branch);
END IF;
END;
Table:
CREATE TABLE DISTRICT_MAS
(
DIST VARCHAR2 (100 CHAR)
);
CREATE TABLE DIST_BRANCH
(
NEIGHBORHOOD VARCHAR2 (100 CHAR),
DIRECTORATE GENERAL OF THE VARCHAR2 (100 CHAR)
);
Values:
insert into district_mas values ('chennai');
insert into district_mas values ('coimbatore');
insert into dist_branch values ('chennai', 'chennai_north');insert into dist_branch values ('coimbatore', 'Podanur');
Concerning
Nassik M
I tested the code below when the list has changed
DECLARE
rg_branch recordgroup;
rg_name1 VARCHAR2 (1000): = "branch";
vtemp NUMBER;
QT VARCHAR2 (10): = "';
BEGIN
rg_branch: = FIND_GROUP (rg_name1);
IF this is ID_NULL (rg_branch)
THEN
DELETE_GROUP (rg_name1);
END IF;
rg_branch: =.
CREATE_GROUP_FROM_QUERY
(rg_name1,
'SELECT branch, branch OF THE DISTRICT WHERE the dist_branch =' | QT | : BLOCK3. DISTRICT OF | QT);
vtemp: = POPULATE_GROUP (rg_branch);
POPULATE_LIST ('BLOCK3.) Branch of THE ', rg_branch);
END;
Hope it's work...
Hamid
-
How to update columns with the value of other lines in the same table
Hello
I use Oracle 11.2, I'd use SQL statements to update a column based on values in other rows in the same table. Here are the details:
create table TB_test (number 4 myId, crtTs date, date of MDPU);
insert into tb_test (1, to_date ('20110101', 'YYYYMMDD'), null);
insert into tb_test (1, to_date ('20110201', 'YYYYMMDD'), null);
insert into tb_test (1, to_date ('20110301', 'YYYYMMDD'), null);
insert into tb_test (2, to_date ('20110901', 'YYYYMMDD'), null);
insert into tb_test (2, to_date ('20110902', 'YYYYMMDD'), null);
After you run the SQL code, I would like to have the following result:
1, 20110101, 20110201
1, 20110201, 20110301
1, 20110301, null
2, 20110901, 20110902
2, 20110902, null
Thanks for your suggestion.I guess you need this, otherwise please explain logic correctly:
SQL> merge into tb_test t 2 using ( 3 select rowid as rid 4 , lead(crtts) over(partition by myid order by crtts) as updts 5 from tb_test 6 ) v 7 on (t.rowid = v.rid) 8 when matched then update 9 set t.updts = v.updts 10 ; 5 rows merged. SQL> select * from tb_test order by 1,2; MYID CRTTS UPDTS ---------- --------- --------- 1 01-JAN-11 01-FEB-11 1 01-FEB-11 01-MAR-11 1 01-MAR-11 2 01-SEP-11 02-SEP-11 2 02-SEP-11
-
update to column values (false) in a copy of the same table with the correct values
Database is 10gr 2 - had a situation last night where someone changed inadvertently values of column on a couple of hundred thousand records with an incorrect value first thing in the morning and never let me know later in the day. My undo retention was not large enough to create a copy of the table as it was 7 hours comes back with a "insert in table_2 select * from table_1 to timestamp...» "query, so I restored the backup previous nights to another machine and it picked up at 07:00 (just before the hour, he made the change), created a dblink since the production database and created a copy of the table of the restored database.
My first thought was to simply update the table of production with the correct values of the correct copy, using something like this:
Update mnt.workorders
Set approvalstat = (select b.approvalstat
mnt.workorders a, mnt.workorders_copy b
where a.workordersoi = b.workordersoi)
where exists (select *)
mnt.workorders a, mnt.workorders_copy b
where a.workordersoi = b.workordersoi)
It wasn't the exact syntax, but you get the idea, I wanted to put the incorrect values in x columns in the tables of production with the correct values of the copy of the table of the restored backup. Anyway, it was (or seem to) works, but I look at the process through OEM it was estimated 100 + hours with full table scans, so I killed him. I found myself just inserting (copy) the lines added to the production since the table copy by doing a select statement of the production table where < col_with_datestamp > is > = 07:00, truncate the table of production, then re insert the rows from now to correct the copy.
Do a post-mortem today, I replay the scenario on the copy that I restored, trying to figure out a cleaner, a quicker way to do it, if the need arise again. I went and randomly changed some values in a column number (called "comappstat") in a copy of the table of production, and then thought that I would try the following resets the values of the correct table:
Update (select a.comappstat, b.comappstat
mnt.workorders a, mnt.workorders_copy b
where a.workordersoi = b.workordersoi - this is a PK column
and a.comappstat! = b.comappstat)
Set b.comappstat = a.comappstat
Although I thought that the syntax is correct, I get an "ORA-00904: 'A'. '. ' COMAPPSTAT': invalid identifier ' to run this, I was trying to guess where the syntax was wrong here, then thought that perhaps having the subquery returns a single line would be cleaner and faster anyway, so I gave up on that and instead tried this:
Update mnt.workorders_copy
Set comappstat = (select distinct)
a.comappstat
mnt.workorders a, mnt.workorders_copy b
where a.workordersoi = b.workordersoi
and a.comappstat! = b.comappstat)
where a.comappstat! = b.comappstat
and a.workordersoi = b.workordersoi
The subquery executed on its own returns a single value 9, which is the correct value of the column in the table of the prod, and I want to replace the incorrect a '12' (I've updated the copy to change the value of the column comappstat to 12 everywhere where it was 9) However when I run the query again I get this error :
ERROR on line 8:
ORA-00904: "B". "" WORKORDERSOI ": invalid identifier
First of all, I don't see why the update statement does not work (it's probably obvious, but I'm not)
Secondly, it is the best approach for updating a column (or columns) that are incorrect, with the columns in the same table which are correct, or is there a better way?
I would sooner update the table rather than delete or truncate then re insert, as it was a trigger for insert/update I had to disable it on the notice re and truncate the table unusable a demand so I was re insert.
Thank youHello
First of all, after post 79, you need to know how to format your code.
Your last request reads as follows:
UPDATE mnt.workorders_copy SET comappstat = ( SELECT DISTINCT a.comappstat FROM mnt.workorders a , mnt.workorders_copy b WHERE a.workordersoi = b.workordersoi AND a.comappstat != b.comappstat ) WHERE a.comappstat != b.comappstat AND a.workordersoi = b.workordersoi
This will not work for several reasons:
The sub query allows you to define a and b and outside the breakets you can't refer to a or b.
There is no link between the mnt.workorders_copy and the the update and the request of void.If you do this you should have something like this:
UPDATE mnt.workorders A -- THIS IS THE TABLE YOU WANT TO UPDATE SET A.comappstat = ( SELECT B.comappstat FROM mnt.workorders_copy B -- THIS IS THE TABLE WITH THE CORRECT (OLD) VALUES WHERE a.workordersoi = b.workordersoi -- THIS MUST BE THE KEY AND a.comappstat != b.comappstat ) WHERE EXISTS ( SELECT B.comappstat FROM mnt.workorders_copy B WHERE a.workordersoi = b.workordersoi -- THIS MUST BE THE KEY AND a.comappstat != b.comappstat )
Speed is not so good that you run the query to sub for each row in mnt.workorders
Note it is condition in where. You need other wise, you will update the unchanged to null values.I wouold do it like this:
UPDATE ( SELECT A.workordersoi ,A.comappstat ,B.comappstat comappstat_OLD FROM mnt.workorders A -- THIS IS THE TABLE YOU WANT TO UPDATE ,mnt.workorders_copy B -- THIS IS THE TABLE WITH THE CORRECT (OLD) VALUES WHERE a.workordersoi = b.workordersoi -- THIS MUST BE THE KEY AND a.comappstat != b.comappstat ) C SET C.comappstat = comappstat_OLD ;
This way you can test the subquery first and know exectly what will be updated.
This was not a sub query that is executed for each line preformance should be better.Kind regards
Peter
-
Multiple values for the same column in the columns of diffétent in the same row?
Hi all
I wonder how you can display different values for the same column in different columns on the same line. For example, using a CASE statement, I can:
CASE WHEN CODE IN ('1 ', ' 3') THEN COUNT (ID) AS 'Y '.
CASE WHEN CODE NOT IN ('1 ', am') THEN COUNT (ID) AS "N".
Yes, that will produce two columns but will produce null values to empty and also two separate registers.
Any ideas?
Thank youAre you sure that this code works for you?
Select ID ,CASE WHEN MODE_CODE IN ('1', '3') THEN COUNT( No) END as "Fulltime" ,CASE WHEN MODE_CODE NOT IN ('1', '3') THEN COUNT( No ) END as "Other" From table group by ID
I guess the code above fails because MODE_CODE is not in your group by?
My suggestion would be to put the CASE in the COUNT:
Select ID ,COUNT(CASE WHEN MODE_CODE IN ('1', '3') THEN No END) as "Fulltime" ,COUNT(CASE WHEN MODE_CODE NOT IN ('1', '3') THEN No END) as "Other" From table group by ID
CASE expressions return no. when the respective conditions are true and NULL otherwise.
COUNTY will have non-null values. -
Select literal values in the same column
Hello
like the practice:
Select 'A', 'B', 'C' for double
will select these values in their own column on the same line, is there a simple way to select these values in the same column on lines without first their insertion into a table?
Thank youSQL> select 'A' x from dual union 2 select 'B' x from dual union 3 select 'C' x from dual ; X - A B C
A bit complicated:
SQL> select chr(ascii('A')+level-1) x 2 from dual 3 connect by level <=3; X - A B C
Other:
SQL> select regexp_substr('ABC','[[:alpha:]]',1,level) x 2 from dual 3 connect by level <= length('ABC'); X --- A B C
Max
http://oracleitalia.WordPress.comPublished by: Massimo Ruocchio, February 12, 2010 17:55
added a secondPublished by: Massimo Ruocchio, February 12, 2010 17:58
Added the third
Maybe you are looking for
-
When I turn on my machine, I have a small circle in the middle with a picture on and my wife below name. My wife passed away on January 8 this year and I have managed to change his pic, but I would like to change the name under my own name How it's d
-
How to reactivate my tool bar menu?
I disabled the toolbar menu. Now with no menu, I can't turn it back on.I uninstalled firefox. I downloaded the new version and installed it, but it opens without a toolbar menu. This has happened Each time Firefox opened == I accidentally disabled th
-
I tried to reinstall XP Pro, but then I get another error message the file for web printer windows cannot find so it won't let me not finished reinstalling XP. How can I solve this problem or solve the problem with the ntoskrnl.exe that need to be r
-
Port before 1723 Linksys WRT1900AC (VPN)
I can't establish a VPN tunnel to my desktop using PPTP (built in vpn windows) machine. I have a Linksys WRT1900AC, latest firmware (1.1.8.164461) I implemented the single port forwarding (this machine has a static ip address below): I can ping the m
-
5.3 update LR &; Adobe CC
I have Cougar 10.8.5 on my IMac. I use LR 5.3. I intend to go to the Sierra of Mountain Lion. I am also considering buying finally CC although most of my editing (95% +) is done in LR.Should I switch to Sierra first or CC first?