Update of Table, summarizing the content of the separate column.
Hi allSmall update problem: -.
CREATE THE TABLE:
CREATE TABLE TestTab10
(
GROUPID VARCHAR2(10),
ITEMS_1 NUMBER(2),
ITEMS_2 NUMBER(2),
ITEMS_3 NUMBER(2),
TOT_ITEMS VARCHAR(50),
SEQNO NUMBER(10)
);
DATA: -.
INSERT INTO TestTab10("GROUPID","ITEMS_1","ITEMS_2","ITEMS_3","TOT_ITEMS","SEQNO") VALUES ('10001','12','13','','','123456');
INSERT INTO TestTab10("GROUPID","ITEMS_1","ITEMS_2","ITEMS_3","TOT_ITEMS","SEQNO") VALUES ('10001','12','','16','','123457');
INSERT INTO TestTab10("GROUPID","ITEMS_1","ITEMS_2","ITEMS_3","TOT_ITEMS","SEQNO") VALUES ('10002','','','','','123458');
INSERT INTO TestTab10("GROUPID","ITEMS_1","ITEMS_2","ITEMS_3","TOT_ITEMS","SEQNO") VALUES ('10003','','13','','','123459');
INSERT INTO TestTab10("GROUPID","ITEMS_1","ITEMS_2","ITEMS_3","TOT_ITEMS","SEQNO") VALUES ('10003','','13','','','123460');
INSERT INTO TestTab10("GROUPID","ITEMS_1","ITEMS_2","ITEMS_3","TOT_ITEMS","SEQNO") VALUES ('10003','','13','','','123461');
INSERT INTO TestTab10("GROUPID","ITEMS_1","ITEMS_2","ITEMS_3","TOT_ITEMS","SEQNO") VALUES ('10004','11','13','','','123462');
INSERT INTO TestTab10("GROUPID","ITEMS_1","ITEMS_2","ITEMS_3","TOT_ITEMS","SEQNO") VALUES ('10004','','12','','','123463');
INSERT INTO TestTab10("GROUPID","ITEMS_1","ITEMS_2","ITEMS_3","TOT_ITEMS","SEQNO") VALUES ('10004','','13','14','','123464');
Select * from TestTab10;GROUPID ITEMS_1 ITEMS_2 ITEMS_3 TOT_ITEMS SEQNO
---------- ---------- ---------- ---------- -------------------------------------------------- ----------
10001 12 13 123456
10001 12 16 123457
10002 123458
10003 13 123459
10003 13 123460
10003 13 123461
10004 11 13 123462
10004 12 123463
10004 13 14 123464
Desired results: -.GROUPID ITEMS_1 ITEMS_2 ITEMS_3 TOT_ITEMS SEQNO
---------- ---------- ---------- ---------- -------------------------------------------------- ----------
10001 12 13 121316 123456
10001 12 16 121316 123457
10002 123458
10003 13 13 123459
10003 13 13 123460
10003 13 13 123461
10004 11 13 11131214 123462
10004 12 11131214 123463
10004 13 14 11131214 123464
I need to update the Tot_items column with the number of distinct elements which is held within each groupid.The ideas people?
Thanks in advance.
Lack OP wants ordered items:
merge
into testtab10 a
using (
with t as (
select rowid rid,
listagg(items_1 || ',' || items_2 || ',' || items_3,',')
within group (order by seqno)
over(partition by groupid) items
from testtab10
)
select rid,
xmlquery(
'string-join(for $n in distinct-values(ora:tokenize($str,",")) order by xs:integer($n) return $n,",")'
passing ',' || items as "str"
returning content
) tot_items
from t
) b
on (a.rowid = b.rid)
when matched
then
update
set a.tot_items = b.tot_items
/
9 rows merged.
SQL> select *
2 from testtab10
3 /
GROUPID ITEMS_1 ITEMS_2 ITEMS_3 TOT_ITEMS SEQNO
---------- ---------- ---------- ---------- -------------------- ----------
10001 12 13 12,13,16 123456
10001 12 16 12,13,16 123457
10002 123458
10003 13 13 123459
10003 13 13 123460
10003 13 13 123461
10004 11 13 11,12,13,14 123462
10004 12 11,12,13,14 123463
10004 13 14 11,12,13,14 123464
9 rows selected.
SQL>
SY.
Tags: Database
Similar Questions
-
Update a table using the clause
Hello
I want to update a table using the selected values.
Cases in the sample:
create table as empsalary)
Select 1 as empid, 0 in the wages of all the double union
Select option 2, the double 0);
Data update are as follows
with saldata as
(
Select 1 as empid, 5000 as wages, 500 as double pf
Union of all the
Select option 2, 10000,1000 like double pf
)
Select empid, salary saldata
I tried the following query but does not work
updated set of empsalary table (empid, salary) =
(
Select * from)
with saldata as
(
Select 1 as empid, salary, 500 5000 as pf Union double all the
Select option 2, 10000,1000 like double pf
)
Select empid, salary saldata
) sl
where sl.empid = empsalary.empid
)
I use oracle 10g.
Help, please.
Krishna Devi wrote:
Hello
I want to update a table using the selected values.
Cases in the sample:
create table as empsalary)
Select 1 as empid, 0 in the wages of all the double union
Select option 2, the double 0);
Data update are as follows
with saldata as
(
Select 1 as empid, 5000 as wages, 500 as double pf
Union of all the
Select option 2, 10000,1000 like double pf
)
Select empid, salary saldata
I tried the following query but does not work
updated set of empsalary table (empid, salary) =
(
Select * from)
with saldata as
(
Select 1 as empid, salary, 500 5000 as pf Union double all the
Select option 2, 10000,1000 like double pf
)
Select empid, salary saldata
) sl
where sl.empid = empsalary.empid
)
I use oracle 10g.
Help, please.
Thanks for posting creates table and test data.
The error message would have helped because it's pretty obvious that this is the problem:
Update table empsalary
*
ERROR on line 1:
ORA-00903: invalid table name
Just remove the word "table".
-
need a script to create multiple tables as the other columns in tables
I need script to create multiple tables as the other columns of tables respectively.
lets consider I want to create tables from table1... table99 like tablex1... .tablex99 columns (without data) respectively (i.e table1 as tablex1, table99 as tablex99).declare cursor c is select object_name from all_objects where object_type='TABLE'; begin for i in c loop execute immediate 'create table '||i.object_name||'_x as select * from '||i.object_name||' where 1=2'; end loop; end; use can use this and put your user names accordingly. If you get any error please post the error.
-
trigger to update a table after the use of commit_form;
Hi, I have a master detail shipping form where I enter the details and use commit_form; to save data... after that I want to update a column named as transit in deteil table
but the changes are not reflected.
I wrote it under the procedure and tried to call the block level under update post trigger but it doesn't...PROCEDURE transit_update IS BEGIN if :shipbill.billtype in ( 'Send it to site','Send it to staff','Send it to store','Send it to consumed ','send it to repair') then update ship_1 set transit_qty = transact_qty where billid =:shipbill.billid; end if ; if :shipbill.billtype in ('Received from staff','Received from site','Received from store','Received from STC') then update ship_1 set transit_qty = 0 where billid =:shipbill.billid; end if ; END;
Hello
Why not put the sub condition in PRE-INSERT/PRE-UPDATE (at the level of the blocks) of the retail block?IF :shipbill.billtype IN ('Send it to site','Send it to staff','Send it to store','Send it to consumed ','send it to repair') THEN :ship_1.transit_qty = :ship_1.transact_qty; ELSIF :shipbill.billtype IN ('Received from staff','Received from site','Received from store','Received from STC') THEN :ship_1.transit_qty = 0; END IF;
If billtype is not simple text (filled in by the user) and then trying to find no matter what other condtion. To reduce misspellings error etc.
-Clément
-
Problem with update of table (using the subquery to retrieve value)
Hello
I update a table based on the value of the subquery.
Here's the update statement.
UPDATING temp xm
SET xm.col1 = (SELECT DISTINCT col1
Of
(SELECT col1, col2 COUNT (col2)
FROM table2
WHERE col1 = xm.col1
AND col2 = xm.col2
GROUP BY col1)
where col2 in (select... in the table3)
)
WHERE xm.col5 = < value >
AND xm.col6 = < value >
When I run this statement I get following error.
ORA-00904: "XM". "" Col1 ": invalid identifier.
Can someone help me why I get this error?
Why doesn't the main table alias in the subquery?
Is it possible to avoid this / re - write the query in a different way?
Thank you
Published by: user552703 on November 2, 2009 20:42You can nest only 1 level deep (referring to the table to be updated).
Have you looked at using the MERGE command? It is "easier" perform updates of this nature, assuming you are using a recent version of Oracle (9 or MORE).
-
Update a table of the source - duplicates exist in the source
Hi all
I need a logic to know how to update a target from the source table. It is here in source table contains duplicate data.
Oracle version is 10.2.0.3.0
OS - Sun Solaris
Target table - fields A, B, and C. A and B are primary keys.
A, B AND C
1 1
1 2
2 2
2 1
Table of the source - no primary key.
A, B AND C
1 1 2
1 1 2
1 1 3
2 1 4
From the fields A and B, column C must be updated on the source table.
In the target table, 4 ranks should get updated to the value 4.
In the target table - for the first row in the source table, the 3 first lines are adapting. I'm fine with all values (2,2,3).
In the target table - for the second and third rows, the value of c must be null.
Currently I'm updating it through cursor. but it takes a lot of time.
In production, less than one percent of the files are duplicate records. It asked me to update the right folders with regular update instruction and duplicate with the slider or other logic records. where less than one per 100 records will be be curly to the cursor. Basically, the direction as to reduce the load on the slider.
Your help is most appreciated.
Thank youTry a different USING clause:
using (select a, b, c, d from (select a, b, c, d ,row_number() over (partition by a, b order by c) rn from s ) where rn = 1 ) s
This will select the first row (numerically) within each combination, b. If you want the last line add a DESC in the order of.
-
Update two tables at the same time?
Hi, I'm having some trouble finding how to create a new field in both tables of the same shape. (php mysql)
I have two paintings: a table listing the projects and
a table listing assignments for example, a project may have more than one assignment.
When the user submits the form the insert record server behavior creates a new project. The projectID in the project table field is an AutoNumber created in mysql.
Now when the new assignment record is created in the assignment table must use the projectID AutoNumber to refer to the parent project.
That's the problem, I don't know how to get the new AutoNumber the table project. I tried setting a variable from a select query to find the last record on the project table... but the problem is that it assigns the value when you load the web page. If two users loading the same page before insertion, the action takes place so both are assigned the same projectID. Of course, which is useless.
I'm not a programmer so need help to understand this.
See you soon,.
How to retrieve the value of an autoincrement column:
-
Change of primary key on the Table clears the other columns
Preliminary info/Installation
JDeveloper 11 g 11.1.1.6.0
We have a table (object view or entity) that has 8 columns. The primary key is composed of 4 1 columns.
The table is displayed in a page fragment.
2 of the 4 non-primary key columns are LOV.
All the 8 columns are needed.
The table is editable including 2 of primary key columns.
Question
Assume that the table displays the 3 lines. If we change a rank 1 non-primary key column and a primary key in row 2 column, everything works well when we are committed to the database
If, however, we first change a primary key column, then a primary key on a different line column, then the column/row primary key that changed us first, gets annihilated and the other columns LOV on this same line. The 2 columns that are not LOV keep data as it should. We then get a validation error because the required data are not present. All this happens before we try all commit to the database. If debug us and look the iterator, it has the old data in this document, before and after any performance on the binding.
If we look at and update the data via the App Module, everything works well. We have tried to update the view, etc. through valueChangeListener also with no luck.If you change the primary key value, it should not be the primary key.
This is true in the design of database relational regardless of how access you the data. In addition, EO don't like if you change the primary key value.
Have you considered adding a surrogate key (use a sequence) and make your PK course a unique key?
John
-
MV for replication. No PK in the source table and the LOB column
I would like to replicate tables between 2 instances in 2 different hosts. Mixed 11 GR 1 material and Oracle 10 g 2. I have my doubts:
1. some tables from the source is not PK, and I understand that MV with rowid is not supported. Is there no workaround known workaround on this case without changing the structure of the source table? Full/complete update is acceptable.
2 one of the table has the CLOB data type. Can I just ignore this column in MV? A known issue with this kind of approach?#1. You must use WITH ROWID MV and I believe it is supported up to the latest version, unless you can find any document, please give me the code of Notes.
#2. CLOB column is supported in MV, so no need to jump. -
Hi all
any help please...
I have a lot of tables in the diagram
Select * from tab; show all tables...
Now, there is a single table called has columns as name like this, dept, empno, joindate, sal...
now the description column in table present in so many other tables in the schema above...
How can I know the names of tables where this 'Description' column shows.
Note: I use the 10 g version and I do not have DBA privilege on the diagram...
Thanks in advance
ASP.Are you logged in as owner of these tables? Otherwise (and it seems that you're not), you have privileges on these table? If you do, use:
SELECT OWNER, TABLE_NAME FROM ALL_TAB_COLUMNS WHERE COLUMN_NAME = 'DESIGNATION' /
If you don't have privileges, but you can choose from DBA_TAB_COLUMNS, use:
SELECT OWNER, TABLE_NAME FROM DBA_TAB_COLUMNS WHERE COLUMN_NAME = 'DESIGNATION' /
Otherwise ask your DBA to run it.
SY.
-
Grant table with the nested column.
Hello
I looked for an answer to this question, but I couldn't find it. So, here goes. I am trying to grant select on a table with a column that is nested in another user and still will not work select it. Here is an example.
FIRST_USER@TST > create type test_object as an object (ref01 varchar2 (3));
0 m
Type of creation.
FIRST_USER@TST > create type test_type is the table of the test_object;
0 m
Type of creation.
"afiedt.buf" 3 lines, 100 characters
1 create table table1 (x varchar2 (1), y test_type)
2 * store table is nested as type1_nt back as a value
FIRST_USER@TST > /.
Table created.
FIRST_USER@TST > grant select on table1 to SECOND_USER;
Grant succeeded.
SECOND_USER @TST > select * from FIRST_USER.table1;
Select * from FIRST_USER.table1
*
ERROR on line 1:
ORA-01031: insufficient privileges
I don't know I'm missing something. I may have to give the grant another way maybe? Help, please.
Thank you.See http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14260/adobjmng.htm#sthref786.
You must grant execute of the consumer on the underlying type.
-
DB trigger error - update even table in the script of the trigger
Hi all
I have a table tab1, whenever any update is done on this table on column col1 and col2 also needs to get the update. (These are related to user forms can be updated only col1 form frontend)
So I created a trigger as follows.
----------------
CREATE OR REPLACE TRIGGER tri1
AFTER UPDATE
ON tab1
FOR EACH LINE
WHERE (NEW.col1 = 'YES')
DECLARE
PRAGMA AUTONOMOUS_TRANSACTION;
BEGIN
Tab1 SET col2 = 1 UPDATE
WHERE transaction_id =: OLD.transaction_id;
COMMIT;
END;
--------
When there is no update on this table, I get following error. Please let me know if I'm missing something.
ORA-00060: Deadlock detected while you wait resource
ORA-06512: at "user1.tab1", line 5
ORA-04088: error during execution of trigger 'user1.tab1 '.
Please let me know if I'm not clear. Thank you
Published by: DharV on August 23, 2011 05:17Your transaction_id is unique?
If this is the case, then you could perhaps use AFTER UPDATE BEFORE UPDATE:
CREATE OR REPLACE TRIGGER tri1 BEFORE UPDATE ON tab1 FOR EACH ROW WHEN (NEW.col1 = 'YES') BEGIN :NEW.col2 := 1; END;
If your transaction_id is not unique - if you really want to update more than one line in tab1 - your update cannot update the same line that the trigger has responded, even with the use of an autonomous transaction. Then you could combine the BEFORE UPDATE trigger above with your own AFTER UPDATE, but then add ROWID! =: OLD. ROWID to where clause, but it would be a bad idea because some of your lines will be updated in a single transaction and others in another transaction.
In general the autonomous transaction is not a great way to solve the problem of changing table within a trigger. I hope that you have a unique transaction_id and can do BEFORE the UPDATE - if it is then a better way is to save the update id in an overall picture in FOR EACH ROW triggers, and only then AFTER an UPDATE fire is NOT "for each line" update the list of saved IDs
-
Update field table to the base sequence number another field
Hello
I have the following structure:
create the table from_list
*(*
NR_ID NUMBER of non-null,
EX_ID NUMBER of non-null,
NUMBER OF OE_ID
*);*
insert into from_list (NR_ID, EX_ID, OE_ID)
Select 1, 1, null of union double
Select 1, 1, 1 double Union
Select 1, 2, 3 double Union
Select 1, 2, 4 double Union
Select option 1, 2, null of union double
Select 2, 1, null of union double
Select 2, 1, null of union double
Select 3, 10, double null.
commit;
Thus,.
Select go t from_list
order of t.nr_id, t.ex_id, t.oe_id
NR_ID EX_ID OE_ID
1-1-1
1 1
1 2 3
1 2 4
1 2
2 1
3 10
I need to change the field value OE_ID null records and for each NR_ID, the EX_ID and the next OE_ID.
With the above data, the result would be:
NR_ID EX_ID OE_ID
1-1-1
1 1 2
1 2 3
1 2 4
1 2 5
2-1-1
3-10-1
Thank you.The only thing I will add to the post of Warren is an additional sorting or two.
The collation that is used with the ROW_NUMBER function is not deterministic: in other words, he does not want to break all the possible links. In his case, the code worked, but, when you do not use a deterministic sort, then you let the tierbreaking randomly. There is never a guarantee that Oracle will sort it the same way every time.
Thus the ORDER BY in the analytical ROW_NUMBER() function must reference all three columns.
Here's how you need to change line 3 since its first solution:
ROW_NUMBER() OVER (PARTITION BY nr_id ORDER BY nr_id, ex_id, oe_id) oe_id
In the second solution, change fit in line 4
-
Retrieves a table in the separate variable
I have a table which currently has many different times that some text is used. It displays the number of times it is used. the table is printed out and a long chain.
$opt = array)
"Delone: howMuch' = > 0, '.
"Deltwo: howMuch'' = > 0, '.
"Delthree: howMuch'' = > 0, '.
"Day: howMuch'' = > 0, '.
);
While ($row_rsPayone = mysql_fetch_assoc$row_rsPayone)) {}
If (array_key_exists ($row_rsPayone['payment_type'], $opt)) {}
$opt [$row_rsPayone["pay_op"]] ++;
}
}
print_r($opt);
the output current is
Array ([Delone: howMuch] = > 19 [Deltwo: howMuch] = > 34 [Delthree: howMuch] = > 15 [day: howMuch] = > 9)
I want to divide each value in a separate variable, so I can use the results separately
I tried
Extract ($opt);
echo $bal = explode ("", $opt ");
echo $bal [0];
echo $bal [1];
echo $bal [2];
echo $bal [3];
but I get no output
You can use a foreach loop to go through the $opt table and assign it to a $variable as below:
$i = 0;
foreach ($opt as $key-online $value) {}
$variable [$i] = '$key; $value ';
$i++;
}
ECHO '.
«. $variable [0]. »
";ECHO '.
«. $variable [1]. »
";ECHO '.
«. $variable [2]. »
";ECHO '.
«. $variable [3]. »
"; -
A better way to treat the form as a table with the variable column type?
I wanted to make a column to return according to the status of a flag column as readonly. I have a column defined as follows in the report query.
Decode (sys_flag, 'Y', APEX_ITEM. DISPLAY_AND_SAVE 3, TYPE_CODE, APEX_ITEM. SELECT_LIST_FROM_LOV (3, TYPE_CODE, 'LOV_TYPE_CODE_LOV')) AS TYPE_CODE
To get the SRM process noting that column, I had to put this 'band of HTML code' to 'No', then the column attributes, I put:
"Expression HTML" to "#TYPE_CODE #
' Display under "to"text display (saves the State).
And then it took me to get new lines of work:
"Default of Type" to "Expression of PL/SQL.
'Default' to APEX_ITEM. SELECT_LIST_FROM_LOV (3, NVL(:P18_TYPE_CODE,'LOV_TYPE'), NULL, 'LOV_TYPE_CODE_LOV', ' NO')
This makes large, however submit that it seems that the checksum of line used by MRU included the raw HTML generated by the APEX_ITEM package and not just the value of the column. I worked around this by including an element hidden checksum and creating a process that replaces the checksum generated automatically with my custom.
Is there a better way to intercept this checksum, preferably before it is rendered on the page? I now hide the sum of hidden HTML control in the output HTML of another column, so it's a bit ugly. If not, is there an easier way to achieve what I'm looking for? I tried several combinations, and it seems to work better. It's just a shame there's no way to have a standard hidden column included in the SRM process.Hello
I tried different possibilities and seems to run the following:
Create a report questioning in NORMAL SQL function to help:
SELECT APEX_ITEM.HIDDEN(1,EMPNO) || APEX_ITEM.TEXT(2,ENAME) ename, CASE WHEN DEPTNO = 10 THEN APEX_ITEM.HIDDEN(3, SAL) || SAL ELSE APEX_ITEM.TEXT(3, SAL) END SAL, EMPNO, DEPTNO || APEX_ITEM.MD5_CHECKSUM(ENAME, SAL) DETPNO FROM EMP
Do not specify something special for column definitions.
Create a button that submits the page.
Create a PL/SQL process that runs "On submit - after calculations" and Validations, triggered by this button and using the following code:
BEGIN APEX_ITEM.MULTI_ROW_UPDATE('#OWNER#:EMP:EMPNO,1:,|ENAME,2:SAL,3'); END;
I've done here: http://htmldb.oracle.com/pls/otn/f?p=55041:35
Any element with the value of DEPTNO 10 has the value SAL, read-only, as otherwise it's editable. This is done by creating a hidden input field for the actual value, followed by the text version OR by creating a single entry field. This ensures that we have the correct number of SAL elements on the page.
APEX_ITEM. MULTI_ROW_UPDATE is the "manual" version of the MRU that you would normally get with a form of table and works for above normal as sql based query reports. The format of this very strict is that you must always allow for two primary keys. See the text of presentation here: http://download.oracle.com/docs/cd/B28359_01/appdev.111/b32258/api.htm#CHDFDACC
Andy
Maybe you are looking for
-
default search engine is changed?
Manager to go back, I installed in my laptop, but since then, when I type some words in the address bar, the default search engine change to go back, how do return to normal (google as a default search engine when im typing a few words into the addre
-
No drivers BUS SM for Satellite C850D-115
Hey,. I have a problem: On my Satellite C850D-115 is a missing driver. BUS SM driver. I can't find it on the Toshiba support site. This part of the chipset driver driver? I can't find whether :( Model number: PSC9UESerial number: 1D41499R Thanks for
-
WiFi button remains orange / does not work
My HP Pavilion Notebook PC g4 has trouble with the WiFi button. Usually, the button remains orange and does not respond by pressing. Rarely, when I turn on the laptop, the button is blue, but the laptop freezes as soon as I try to do anything. I trie
-
application mail Mavericks don't synch background
My macbook air is mid2013 mavericks 10.9.5 My problem is mail application. The mail app don't synch email while closed. I opened the application mail to synch my emails. When I open "Mail", I can get new e-mail. Is this normal?
-
What benefits is the Agere System HDA Modem offer that is not my current program?
Can you explain what this update is for and that it adds to the computer? I receive an optional for update for Agere System HDA Modem on my HP laptop. Should I download it, or do I really need? I also wanted to know what would offer the benefits of d