Update 1 column,1 single table based on where results of multiple tables
I would like the my_id column in 1 table updated to the static value of 247 for my_id stored in the 1 single table based on the where clause, which uses the my_id column in it.
The update statement updates all rows in table1, instead of just the rows where
the condition ( (b.my_id=a.my_id)
and ( b.my_name like 'OIS SrClerk%')
and (a.f_id=m.f_id)
and (trunc(m.cr_time) < '02-Apr-2008')) is true
What needs to be changed?
update table1 a
set a.my_id=247
from table1 a, table2 b, table3 m
where
(b.my_id=a.my_id)
and ( b.my_name like 'OIS SrClerk%')
and (a.f_id=m.f_id)
and (trunc(m.cr_time) < '02-Apr-2008')
Are you looking for this?
UPDATE table1 A
SET A.my_id = 247
WHERE EXISTS (SELECT 'x'
FROM table2 b,
table3 M
WHERE b.my_id = A.my_id
AND b.my_name LIKE 'OIS SrClerk%'
AND A.f_id = M.f_id
AND TRUNC (M.cr_time) < to_date('02-apr-2008 00:00:00','dd-mon-yyyy HH:MI:SS') )changed date string to to_date
Message was edited by:
devmiral
Similar Messages
-
How to update two columns in two tables?
hi friends
I have two tables linked to each other through SaleNo and SaleDT. their structure as below
Sales Table============
SaleNo int PK auto increment
SaleDT Datetime PK
Qnty decimal
Units decimal
Invoices table
=================InvoiceNo int PK Auto incremented
InvoiceDT Datetime
SaleNo int FK
SaleDT Datetime FK
Note that SaleDT column is NOT assigned with getDate() expression.
1. what I need to do is update the SaleDT column of Sales table and Invoices table with the value '2013-01-31 10:31:55.813', how do I do this without manually breaking the link between the tables?
2. Assume SaleNos 15 to 27 needs update the SaleDT to '2013-06-12 10:31:55.813', how do I do this complex operation where I I have update SaleDt column of two table of SaleNo range from 15 to 27?
thanks
I use Visual studio 2012 Ultimate and SQL server 2008 developer edition!Why not below? May be you will not be able to change your design now, but just want to share.
Sales Table============
SALEID int PK autoincrement
SaleNo int
SaleDT Datetime
Qnty decimal
Units decimalUNIQUE (Saleno,SaleDT)
Invoices table
=================InvoiceNo int PK Auto incremented
InvoiceDT Datetime
SALEID int FK -
Hi all
I have a problem in updating one column in the target table(say table A) from a column in the source table (say table B).
All the columns in table A has been populated. Just one column should be populated. My source is a SQL object that contains a complex sql query that returns three columns date_from, date_to and ID.
In the table A, I have the same date_from and date_to and need to get the ID from the SQL object and set it to the corresponding ID in the table A.
I tried many ways to update the table, but it I couldn't ;(
I should read from a table and update it based on a look-up function mapped to the column I need to update.
I want to map the ID colmn from table A to a look-up ext function that can get the column from the table B. However I don't know how to use the Data Services objects to just update 1 column. If you could give me a consequence of the DS objects to be update a table based on a look-up , I would be so grateful.
Thanks.Your dataflow should look like this :
1) Source = the SQL transform with date_from, date_to and ID as columns.
2) Next add a query (copy all columns from schema in to schema out) and set date_from and date_to as keys. Also make sure column names exactly match the column names in your target table, if not rename them in this query.
3) Add a Map_Operation transform that maps all "normal" operation codes to "update"
4) Finally add your target table and in the properties/options set "use input keys" to yes (or checked).
This will generate UPDATE statements for all columns used in the query with a WHERE clause based on the keys defined in the query (date_from, date_to).
Ben. -
Updating the column of a table
Hello Gurur,
I have two tables they are
Test & emp_op
Desc empop
- empid
-id_num
-node_num
_Desc Test
-id_num
-node_num
-name
-addr
-empid
Now i m trying to update the column empid in test table, copying as it is from empid column of emp_op table . Below is the query i have wriiten to update
update test e
set e.empid = (select t.empid from emp_op t
where t.id_num = e.id_num and
t.node_num = e.node_num );
But it gives me an error ORA-01427: single-row subquery returns more than one row. any idea why ??
if not, is there is any way i can accomplish this task in a different way ??
Thank you so much. I appriciate it!!Hi,
That means some row (maybe more than one) in test matches two or more rows in emp_op.
What do you want to do in that case? Post some sample data (from both tables, relevant columns only) and the results you want to see in test after the UPDATE.
If you know that all the matching rows in emp_op will have the same empid, you can just change SELECT in the sub-query to SELECT DISTINCT . -
Getting errors when updating a column on a table having a primary key
Hi,
I have an application on Oracle APEX that raises the following error after an attempt (through the application) to update a column with no specific constraint on it:
ORA-06550: line 1, column 17: PL/SQL: ORA-00936: missing expression ORA-06550: line 1, column 9: PL/SQL: SQL Statement ignoredUnable to fetch row.
The involved table has a primary key conatraint and the corresponding column can be populated by a sequence (but there is no trigger to manipulate the sequence).
The sequence is mentioned in the involved page definition for populating the primary key.
If I disable the primry key and set to null the corresponding value for the primary of the record to be updated, then it is possible to update that record (thus the above column) through the application.
Did someone encountered this situation before?
If yes, what was then your workaround/solution?
Kind Regards.Dear user8058501 ,
Firstly) Did you check
Auto Row Fetch (After upgrade to 4.0.1)
Automated Row Fetch on Table with Synonym causes ORA-00936: missing expr.
Secondly) If the problem is not resolved, Would you provide a sample on apex.oracle.com with workspace/developer account to be able to help you
Please, if this solves your question, mark it as Correct. Otherwise as helpful.
Best Regards
Mahmoud -
Updating a column from other table
Hi all,
I have a simple update query problem. I have four tables
activist(activist_id,first_name,last_name,c_state),
membership(activist_id,g_n_id),
group_network(g_n_id,g_n_type_id),
school_grop_det(g_n_id,state). For some records in activist table the c_state column is null, i want to update that column with state column of school_group_det table.
Here is the query for the states which are null
select distinct a.activist_id,a.first_name,a.last_name,
a.c_state,sd.state from activist a,membership m,
group_network g,school_group_det sd where
a.activist_id=m.activist_id and g.g_n_id=m.g_n_id and
g.g_n_id=sd.g_N_id and a.c_state is null and g.g_n_type_id='1001'
order by a.activist_id
I got the activist_id,first_name,last_name,c_state from activist and state from school_group_det. now i as i told you want to update the c_state with state column of school_group_Det table.
Pleae any one help me
Thanks
SrinivasFor ur query the reply whay u have got is correct one. For further quries similar to one u had u can download a tool named TOAD (Tools for Oracle Application Developer) from quest site (www.quest.com). Install it a proceed.
Do let me know how and what u feek about TOAD. -
Question about creating and updating new columns in a table
Hi, I have a couple of questions that would love some answers to
Please bear in min that questions relate to datawarehouse / Just large tables with say about 50 million records
1) How do you create new columns in a big table
2) how do you update the new columns
3) would you create an index on a column in a table with 200m rows when the only two possible values are stored in the column (e.g.Y, N) - give your resason
my aswers to these would be
1) simple alter table ...
2) simple update statements
3) No need to create an index
I might be wrong on these in the context of datawarehouse
cheers
css_jay99If the number of Y vs. N is about 50/50, you only have to parse through 50% of the
overall amount of columns.Fnord. If the ratio of Y to N was 1:20 then the index would be useful for searching for values of Y only. Or if the column is nullable and the bulk of the entries were null then it might be useful. But a 50/50 split? FTS is much more effective.
So, it does depend on the data distribution, but in most cases such an index would never be used (or should never be used).
Cheers, APC -
Navigation to update a column in the table jtf.jtf_rs_resource_extns
Hi All,
I'm using oracle 11.5.10
Can somebody tell me the frontend form which is related to the table jtf.jtf_rs_resource_extns
I need to update a column in the above table from the frontend.
Please explain me the navigation for doing the same
Regards,
MohanI can't tell you the answer to your query but what I can tell you is that you have logged the thread in a wrong forum. As far as my knowledge goes, this table does not delong to HRMS.
Just check the product in which you are working and then log the thread in the right forum.
Thanks, -
Need logic to update Varchar column in a table
Hi,
Could you give me logic for below.
I have a table xx_dbc where one of the column Attribute1 is varchar2(240).
Attribute1 has values like
==================
(AIN,PUP,GRI,NINE)
(AIN,PUP)
(AIN)
(GRI,NINE)
I have to update this column for every record with values AIN=10 , PUP=20 , GRI=30 , NINE=40
Columns should be updated like below
(10,20,30,40)
(10,20)
(10)
(30,40)
Thanks.Hi,
Here's one way:
WITH replacements AS
SELECT 'AIN' AS old_str, '10' AS new_str FROM dual UNION ALL
SELECT 'PUP', '20' FROM dual UNION ALL
SELECT 'GRI', '30' FROM dual UNION ALL
SELECT 'NINE', '40' FROM dual
, normalized_data AS
SELECT p_key
, LEVEL AS sort_key
, REGEXP_SUBSTR ( attribute1
, '[^(,)]+'
, 1
, LEVEL
) AS str
FROM xx_dbc
-- WHERE ... -- If you need any filtering, put it here
CONNECT BY LEVEL <= 1 + REGEXP_COUNT (attribute1, ',')
AND PRIOR p_key = p_key
AND PRIOR SYS_GUID () IS NOT NULL
SELECT '(' || LISTAGG ( NVL (r.new_str, n.str)
) WITHIN GROUP (ORDER BY sort_key)
|| ')' AS new_attribute1
, n.p_key -- If wanted
FROM normalized_data n
LEFT OUTER JOIN replacements r ON r.old_str = n.str
GROUP BY n.p_key
ORDER BY n.p_key
Like everything else, it depends on your Oracle version.
In the query above, p_key can be any unique key from xx_dbc, including attribute1 or ROWID.
Relational databases, like Oracle, work best when each column of each row contains only 1 piece of information, not a delimited list of any number of pieces. This is so fundamental to table design that it's called First Normal Form. Most of the work in this problem involves converting your denormalized data into First Normal Form, and then converting it back again. This problem, like many others, would be much simpler and more efficient if your table was in First Normal Form.
The query above assumes the replacement strings (such as 'AIN' and '10') are not already in a table. If they are, or if they can be derived from a table, then you don't need the replacements sub-query; use your real table instead. -
Update a column of a table to a value fast. table size is 16gb
hi guys,
set indexes to unusable will make processing faster.
What other ways to make it faster? Am currently using the below but taking very long.
version: 10.2.0.4
UPDATE PDF.TAB_REF SET CODE='F';
thanksset indexes to unusable will make processing fasterOnly for indexes on "CODE". Indexes on other columns are not updated by this UPDATE statement so they do not need to be set to UNUSABLE.
Now you've unnecessarily added the overhead of having to REBUILD each of those indexes !
(And if you do have a single-column index on "CODE", you don't need it anymore so you should drop the index !)
This would be a FullTableScan.
How large is the table ? Most DBAs/Developers answer a question with "x million rows". But "x million rows of 100bytes each" is very different from "x million rows of 492bytes each" which is very different from "x million rows of 1304bytes each". The FullTableScan has to read all the blocks -- so the effort is relative to the number of blocks, not the number of rows.
Have you monitored the update by querying V$SESSTAT, V$SESS_IO and V$TRANSACTION ?
(I guess you are using OEM's display of "Long Running SQL operations" which is based on V$SESSION_LONGOPS).
Hemant K Chitale -
Stored Procedure for updating dynamic columns in a table
I have a table with a lot of columns around 30ish
Now I want to create a stored procedure that will update a specific column to a new value.
I the @columname and @newvalue to be the parameters, and an addition @itemId for the WHERE clause so it will update that specific row/data only.
here's my Stored Procedure
USE [db]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[usp_UpdateData]
@itemID int,
@ColumnName varchar(50),
@newValue nvarchar(50)
AS
BEGIN
Update dbo.ProjectAllocation
Set @ColumnName = @newValue
Where itemID = @itemID END
When I pass the following
@ColumnName: UserName
@newValue: NewUserName
@itemID: 1
it doesnt update row with itemID = 1.
How can I do this?
----------------------- Sharepoint NewbieDid you try my last post method. Its better to use parameterized approach.
Anyway, if you want to change your code,you may need to change as below.....
SET @sql = 'UPDATE dbo.table SET ' + @ColumnName + '=''' + @newValue + ''' WHERE [itemID] = ' + cast(@itemID as varchar(50)); -
Need to update corresponding columns in details table
Hi,
I have a header and lines table.
In header table we have a comments field, requirement is whenever someone is updating comments in header it should update lines comment column as well.
I tried using fire action on Comments field like as soon as user is entering something in Comments field I am capturing that event and firing and update statement for lines table
but the problem here is, if user enters the comments and doesn't save it at header level it stills fire an update statement in lines and updating the comment field of lines table.
I need to update header comments in lines level at Apply button.
Please someone suggest something.
Best Regards
Ragni GuptaHi Gurus/Expert,
Please suggest something, its really urgent!!
Thanks
Ragni Gupta -
Need to update one column of all table in that particular schema
hi all,
i am using db10g.
my task is to update one particular column's value of all the table in that schema.
to acheive the above
do i have to write update statement for each table or is there any way to do it in bulk?
i hope my question make sense.
Thanks..Hi karthick,
I want to know something which is not related to this thread .
How to include formatted post while replying to thread .
I know using will be used format code before posting . But how can we do it for posted message .
I hope you understand my question .
Thanks in advance . -
Triggers to update one column on 3 tables
hi,
I've three tables:
TABLE TN:
COD_ID.........VARCHAR2(32) primary key
NAME...........VARCHAR2(64) NOT NULL
COD_ID..............NAME
A12.................AT32
A13.................AT33
A14.................AT35
A30.................AT32
TABLE TM:
ID_X..........VARCHAR2(32) PRIMARY KEY
NAME..........VARCHAR2(64)
ID_X..............NAME
A12
A13
A14
A30
TABLE TL:
COD_ID..........VARCHAR2(32) FOREIGN KEY ON TN
ID_X............VARCHAR2(32) FOREIGN KEY ON TM
TL_ID...........VARCHAR2(32) PRIMARY KEY
NAME............VARCHAR2(64)
I'd like to create triggers (or procedure) that update automatically the value NAME in the tables TM and TL.
for example:
If I insert into TN a new COD_ID (A39) and a new NAME (AT38), when I insert a new ID_X in tble TM, I'd like
to have the value AT38 in NAME of TM, and when I insert a new record in table TL I'd like
to have the value AT38 in NAME of TL.
Also when I update NAME of TN.
I tried with these triggers:
CREATE OR REPLACE TRIGGER TN_PR_BEFORE_UPD
BEFORE UPDATE OF NAME ON TL
FOR EACH ROW
DECLARE
tmpVar NUMBER;
BEGIN
update TL set NAME=:new.NAME where TL.COD_id=:new.COD_id;
UPDATE TM SET NAME=:NEW.NAME WHERE ID_X=:NEW.COD_ID;
END TN_PR_BEFORE_UPD;
CREATE OR REPLACE TRIGGER TN_COD_ID
BEFORE UPDATE OF COD_ID ON TL
FOR EACH ROW
BEGIN
SELECT NAME INTO :NEW.NAME FROM TN WHERE TN.COD_ID=:NEW.COD_ID;
END TN_COD_ID;
CREATE OR REPLACE TRIGGER TL_pr
BEFORE UPDATE OF NAME ON TL
BEGIN
UPDATE TM SET NAME=:NEW.NAME WHERE ID_X=:NEW.ID_X AND :NEW.ID_X IS NOT NULL;
END TL_pr;
CREATE OR REPLACE TRIGGER TL_PR_BEFORE_INSERT
before INSERT ON TL
FOR EACH ROW
DECLARE
tmpVar varchar2(64);
BEGIN
SELECT NAME
into tmpVar
FROM TN
WHERE COD_ID=:NEW.COD_ID;
END TL_PR_BEFORE_INSERT;
when I update TN triggers run CORRECTLY but when I insert a new record in TM, TN, TL I don't see a new NAME.
What I wrong??
Thanks
RafUse when updating then insert into table_name
and
when inserting then insert into table_name
clauses in your Triggers to do this -
Ora-21700 when updating xmltype column of a table
Hello,
Can somebody explain why the following statement gives ora-21700 (object does not exist or is market for delete):
update translation_message
set translationxml = XmlType(
'<NPSREPLY DOMAIN="SWI" OBJECT="SUBSCRIBER" REQUEST="DELETE" RETURNCODE="0" RETURNTYPE="NONE" STATUS="STORED" xmlns="http://saly.bc/nps/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://saly.bc/nps/ NPS_Reply.xsd">
<SUBREQUEST SEQUENCE="1">
<ProfileData>
<ACTION SUBTYPE="PSTN">DEL_CNA_FREE</ACTION>
<DN>999999999</DN>
<RETURNCODE>0</RETURNCODE>
</ProfileData>
</SUBREQUEST>
</NPSREPLY>'
where id = 1926938
remark:
when changing
xsi:schemaLocation="http://saly.bc/nps/ NPS_Reply.xsd
in
xsi:schemaLocation="http://saly.bc/nps/NPS_Reply.xsd
the select is running well.
I will explain my problem a little bit more:
The exact oracle error is:
ora-21700 object does not exist or is marked for delete ORA-06512: at "SYS.XMLTYPE".
The following peace of xml causes the problem:
xsi:schemaLocation="http://saly.bc/nps/ NPS_Reply.xsd"
The statement is running fine if you remove the blank after
"/nps/ NPS_Repy". So if you use this peace of xml xsi:schemaLocation="http://saly.bc/nps/NPS_Reply.xsd", the statement works fine.
My question: Wy is the blank not allowed in this peace of xml xsi:schemaLocation="http://saly.bc/nps/ NPS_Reply.xsd"
The purpose of the blank is to indicate that 'NPS_Reply.xsd' will be located somewhere in "http://saly.bc/nps/". So it can be that 'NPS_Reply.xsd' is found directly under "http://saly.bc/nps/" or some levels lower. According XML standards, the blank is allowed for this purposes.
regards, ElsHi,
This schema location is only indicative and not used. The xml is generated by an other application and has to be stored in an xmltype column.
regards, Els
Maybe you are looking for
-
how do i access the data stored on my time capsule? for example, if i try to view a photo, i get the option to "view with iphoto" but when i click on "view with iphoto" nothing happens. i'm having similar trouble openning up movies, music, etc. it
-
Download Error message in Apps
The apps category in my CC keeps giving me an download error message even when I click the reload apps button. Does anyone know how to resolve this issue?
-
Problem with file system logging in Solaris7
Hi, Solaris7 by default provides filesystem logging option. I mount a filesystem with "-o logging" option and then crash the filesystem. Next time i am able to mount the same filesystem without having to do an fsck. But the same does not happen if i
-
Which type of HDMI cable?
i have Hp pavillion dv6-6121tx laptop and i want it to connect with my TV through HDMI cable.Which type of cable should i buy 1.3B or 1.4B or they just don't matter?please tell me
-
Howdy, Fellow Photographers 3 cheers for the Aperture team for the 2.1 update! OK, back to business. 1. I would like to see a deinterlace plugin for we editors so we can take our freeze frames into Aperture from FCP and make a nice photo to edit into