Updating a table from another table
I have a target table a.
SQL> select * from a;
FUND TERM
1
2
3
4
5
6
7
8
8 rows selected.
And, I have another table 'b' where I have the values for 'term' backed up for 4 funds.
SQL> select * from b;
FUND TERM
1 07-JUL-08
2 08-JUL-08
3 09-JUL-08
4 10-JUL-08
4 rows selected.
I could use the below merge sql statement to update the target table 'a' with term dates from table b.
SQL> merge into a
using b
on (a.fund = b.fund)
when matched then
update set a.term = b.term;
Merge successfully completed.
SQL> select * from a;
FUND TERM
1 07-JUL-08
2 08-JUL-08
3 09-JUL-08
4 10-JUL-08
5
6
7
8
8 rows selected.
But, my question is, how could this update be done without using 'merge' in sql (not pl/sql). I think I've done it in the past, but just cannot recall how I did it.
Thanks in advance for any tips you may provide.
A few ways:
update a
set a.term = (select b.term
from b
where b.fund = a.fund)
where exists (select b.term
from b
where b.fund = a.fund)
or
update
select a.term a_term
,b.term b_term
from a,b
where a.fund = b.fund
set a_term = b_term;The second one only works if you have a "key preserved table".
Similar Messages
-
I can't create table from another table?
Hi everyone!
I have a problem that I don't known the reason why?
I'm using Oracle version 8i and I want to create a table from another table, such as:
CREATE TABLE a_backup as SELECT * FROM a => It's OK, table a_backup is created.
But there is only a table that I can't created like that, such as:
CREATE TABLE b_backup AS SELECT * FROM b;
When I run over command, SQL Plus is not responding... and clients are can't access to DB or Executing forever
This is the first time I met this problem.
Can Anyone help me to resolved it?
Thanks in advance!xi`tin wrote:
Hi everyone!
I have a problem that I don't known the reason why?
I'm using Oracle version 8i and I want to create a table from another table, such as:You realize, of course, that 8i is completely out of support .... Is your OS and hardware just as old as your rdbms software, or is it only the rdbms that your company refuses to upgrade?
CREATE TABLE a_backup as SELECT * FROM a => It's OK, table a_backup is created.
But there is only a table that I can't created like that, such as:
CREATE TABLE b_backup AS SELECT * FROM b;
When I run over command, SQL Plus is not responding... and clients are can't access to DB or Executing forever
This is the first time I met this problem.
Can Anyone help me to resolved it?
Thanks in advance! -
Create table from another table including constraints
Hi,
Is there a way to create a table from another table including constraints.
CREATE TABLE COPY_EMP
as
SELECT *
FROM EMP
WHERE 1 =2 ;
This creates the table, but the constraints are not copied over.
I was reading about DBMS_REDEFINITION - can that be used for this scenario ?
Thanks!
Anand>
I tried that, but the constraint names are posing a problem. And unfortunately our constraints are not named in a standard, so am finding it difficult to replace them.
Was just wondering if there were any simpler approach to this.
>
No - there isn't.
You will have to use new names for the constraints. That usually means extracting the DDL and manually changing the constraint names. -
Create a new table from another table that exists ussing a stored procedure
Hi,
I want to know if is posibble to create a new table from another table that exists ussing a stored procedure. This new table is created from other table that exists in the DB.
(in the next code the table tbl1 exist into the schema of the DB, but temp_tbl1 does not exist, it must be created by the procedure)
create or replace procedute temp is
temp_tbl1 tbl1%TYPE; //the temp_tbl1 will have the same type of tbl1
begin
create table temp_tbl1 as (select * from tbl1);
end temp;
thanks very muchcat wrote:
Hello,
I think my problem is not about this grant, because if I execute this as an "anonymous procedure":
DECLARE
BEGIN
EXECUTE IMMEDIATE 'CREATE TABLE Abonus (id NUMBER, amt NUMBER)';
END;
It runs ok
But if I do:
CREATE OR REPLACE procedure temp as
BEGIN
EXECUTE IMMEDIATE 'CREATE TABLE Abonus (id NUMBER, amt NUMBER)';
END;
I have the error
ORA-01031: Insufficient privileges
ORA-06512: at "temp", line 3Anonymous blocks are treated as "Invoker's Rights" from a privilege perspective whereas stored programs by default are treated as "Definer's Rights". Therefore using anonymous blocks is not a valid test to check this.
The simplest form of checking this issue is by executing
SET ROLE NONE;and then to run your statement/code block in question interactively. Using this approach you get in your session the effective rights of a "Definer's Rights" stored program, i.e. only privileges that you got granted directly to your user.
You can revert to the default setting by issuing
SET ROLE ALL;For more information regarding this topic, read e.g. the documentation:
http://download.oracle.com/docs/cd/B28359_01/appdev.111/b28370/subprograms.htm#LNPLS00809
Regards,
Randolf
Oracle related stuff blog:
http://oracle-randolf.blogspot.com/
SQLTools++ for Oracle (Open source Oracle GUI for Windows):
http://www.sqltools-plusplus.org:7676/
http://sourceforge.net/projects/sqlt-pp/ -
Create a table from another table
I have Windows XP with 10g 10.2.0.1.0
I need to create a table from another table to re-arrange the table column order and add the following statement at the end of creation.
PCTFREE 10 PCTUSED 0 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING STORAGE
INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT
TABLESPACE "TAB_DATA"
Below iis my SQL statement, but it doesn't work. Please help.
create table my_table as (select t1, t5, t2, t3, t4 from orig_table
PCTFREE 10 PCTUSED 0 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING STORAGE
INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT
TABLESPACE "TAB_DATA"
*);*Kee Kee wrote:
I have Windows XP with 10g 10.2.0.1.0
I need to create a table from another table to re-arrange the table column order Why? Column order has no meaning. The individual SELECT statement specifies the column order that particular statement wants, which may be different from the needs of some other SELECT statement.
and add the following statement at the end of creation.
PCTFREE 10 PCTUSED 0 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING STORAGE
INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT
TABLESPACE "TAB_DATA"
Below iis my SQL statement, but it doesn't work. Please help.
create table my_table as (select t1, t5, t2, t3, t4 from orig_table
PCTFREE 10 PCTUSED 0 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING STORAGE
INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT
TABLESPACE "TAB_DATA" -
INSERTING INTO A TABLE FROM ANOTHER TABLE
Hi,
I am having a table called emp in which 5 columns are there, I want to insert some rows from another table called employees, only into three columns of emp table through a sub query.
Is this scenario is possible, I tried so many queries but it is not working out.
Can any body help me out.
The columns in emp table is
empno, ename, doj, designation, salary, deptno, mgrid
The columns in employees table is
empno, name, hiredate, post, salary, commission, deptno, mgr
I want to insert into empno, ename, doj, designation columns of emp table from the employees table empno, name, hiredate, post columns.
Ramesh.It looks like your EMP table has 7 columns, not 5, and you want to insert into 4 columns, not 3.
insert into emp
(empno, ename, doj, designation)
select empno, name, hiredate, post
from employees; -
Question on Creating table from another table and copying the partition str
Dear All,
I want to know whether is there any way where we can create a table using another table and have the partitions of the new table to be exactly like the used table.
Like
CREATE TABLE TEST AS SELECT * FROM TEMP;
The table TEMP is having range and hash partitions.
Is there any way when we use the above command, we get the table partitions of TEMP to be copied to the new table TEST.
Appreciate your suggestions on this one.
Thanks,
Madhu K.may this answer your question...
http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:595568200346856483
Ravi Kumar -
Need a Query to update table from another table.
I have two tables Table A and Table B , till now in table “A”. I have a column which consist of IDs and duplicate IDs( which are basically formed by Original Ids) , I have another table i.e. table “B” , which gives a mapping between original ids and duplicate Ids
TABLE A:
ID/DUPLICATEID NAME
1 Rahul
1_CAD Pawan
2 Nikhil
3 TOM
3_CAD Ravi
3_MQ Puneet
TABLE B:
ORIGINALID DUPLICATEID
1 1_CAD
3 3_CAD
3 3_MQ
Now I want to have another column in Table “A” , which will give me the mapping between the original Id and duplicate Id as shown in updated table “A”.
UPDATED TABLE A:
ID/DUPLICATEID NAME ORIGINAL_ID
1 Rahul
1_CAD Pawan
2 Nikhil
3 TOM
3_CAD Ravi
3_MQ Puneet
Now I want to write a Query in which I can update this column (ORIGINAL_ID) of Table “A”, from the table B(basically want to update mulitple rows using single query), because table B already has this mapping. Can any one help me in this. I am basically a Java guy , so I don’t know much about it. I hope to get a positive response from you people, Thanks in advance!Here you go...
<pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%">
<code>
SQL> CREATE TABLE A (ID VARCHAR2(10), NAME VARCHAR2(10), NEW_ID VARCHAR2(10));
Table created.
SQL> INSERT INTO A VALUES ('1', 'Rahul', '');
1 row created.
SQL> INSERT INTO A VALUES ('1_CAD', 'Pawan', '');
1 row created.
SQL> INSERT INTO A VALUES ('2', 'Nikhil', '');
1 row created.
SQL> INSERT INTO A VALUES ('3', 'TOM', '');
1 row created.
SQL> INSERT INTO A VALUES ('3_CAD', 'Ravi', '');
1 row created.
SQL> INSERT INTO A VALUES ('3_MQ', 'Puneet', '');
1 row created.
SQL> CREATE TABLE B (ID VARCHAR2(10), NAME VARCHAR2(10));
Table created.
SQL> INSERT INTO B VALUES ('1', '1_CAD');
1 row created.
SQL> INSERT INTO B VALUES ('3', '3_CAD');
1 row created.
SQL> INSERT INTO B VALUES ('3', '3_MQ');
1 row created.
SQL> COMMIT;
Commit complete.
SQL> UPDATE A
2 SET NEW_ID = NVL((SELECT B.ID FROM B WHERE A.ID = B.NAME),A.ID)
3 /
6 rows updated.
SQL> COMMIT;
Commit complete.
SQL> SELECT * FROM A;
ID NAME NEW_ID
1 Rahul 1
1_CAD Pawan 1
2 Nikhil 2
3 TOM 3
3_CAD Ravi 3
3_MQ Puneet 3
6 rows selected.
</code></pre>
Note: While asking question do give us DML/DDL script. It will make peoples life better.
Karthick.
http://www.karthickarp.blogspot.com/ -
How to update one table from another table?
Hi,
Please go through the case I am mentioning below and if possible try to provide with a solution.
I am working on a report to generate cash flow forecast, where in one of the fields is "Payroll", in which its being mentioned as:
In the selection screen: I am entering Project ID, profit Center and Period(in MM/YYYY format).
Selection of all entries in table COSP for selected cost elements above, value type 1, version , all periods and for all selected WBS elements and all objects underneath.
From this, update table COFP with information from COSP with value type 62 and same period.
For updation of various fields the following information is being given.
How should we update COFP?
New entries per OBJNR/PERIO and HKONT are required via using the information from COSP:
COFP-MANDT = SY-MANDT
COFP-KOKRS = if COSP-OBJNR begins with PR
Check table PRPS with COSP-OBJNR = PRPS-OBJNR and enter PRPS-PKOKR
If COSP-OBJNR begins with NV
Check table AFVC with COSP-OBJNR = AFVC-OBJNR,
go to Table AFKO with AFVC-AUFPL,
go to table AUFK with AFKO-AUFNR and enter AUFK-KOKRS
If COSP-OBJNR begins with OR
Check table AUFK with COSP-OBJNR = AUFK-OBJNR
and enter AUFK-KOKRS
COFP-BELNR = Check table NRIV, CLIENT = SY-MANDT, OBJECT = RK_BELEG,
SUBOBJECT = COFP-KOKRS, NRRANGENR = 05,
Add 1 to NRLEVEL and begin with 500000000
Use same BELNR for one update-run
COFP-BUZEI = 1 + and 1 in next entry but same update-run
COFP-TWAER = COSP-TWAER
COFP-ZHLDT = always last day of month in field COFP-PERIO
COFP-GJAHR = COSP-GJAHR
COFP-PERIO = if entry in field WKG001 à PERIO = 001
If entry in field WKG006 à PERIO = 006
COFP-WRTTP = 62
COFP-VRGNG = FIPL
COFP-POSIT = Check table SKB1 where SAKNR = COSP-KSTAR and use SKB1-FIPOS
for going to table FMCI-FIPOS and enter FMCI-POSIT
COFP-OBJNR = COSP-OBJNR
COFP-HKONT = COSP-KSTAR
COFP-WKGBTR = WKGXXX
COFP-WKGBTRO = -
COFP-WTGBTR = WTGXXX
COFP-WTGBTRO = -
COFP-WOGBTR = WTGXXX
COFP-WOGBTRO = -
COFP-BUKRS1 = -
COFP-GJAHR1 = -
COFP-BELNR1 = -
COFP-BUZEI1 = -
COFP-BUKRS2 = -
COFP-GJAHR2 = -
COFP-BELNR2 = -
COFP-BUZEI2 = -
COFP-EBELN = -
COFP-EBELP = -
COFP-ZEKKN = -
COFP-ETENRM = -
COFP-STUNR = -
COFP-LIFNR = -
COFP-KUNNR = -
COFP-GSBER = -
COFP-BUKRS = (nearly same as COFP-KOKRS!)
if COSP-OBJNR begins with PR
Check table PRPS with COSP-OBJNR = PRPS-OBJNR and enter PRPS-PBUKR
If COSP-OBJNR begins with NV
Check table AFVC with COSP-OBJNR = AFVC-OBJNR,
go to Table AFKO with AFVC-AUFPL,
go to table AUFK with AFKO-AUFNR and enter AUFK-BUKRS
If COSP-OBJNR begins with OR
Check table AUFK with COSP-OBJNR = AUFK-OBJNR
and enter AUFK-BUKRS
COFP-EINDT = -
COFP-SGTXT = -
COFP-GEBER = -
COFP-KURSF = -
COFP-KUFIX = -
COFP-GBETR = -
COFP-KURSR = -
COFP-KURSFIKRS = -
COFP-KZKRS = -
COFP-UMBKZ = -
COFP-KBLNR = -
COFP-KBLPOS = -
COFP-HI FIVOR = -
COFP-LO FIVOR = -
COFP-HI ACCOUNT = -
COFP-LO ACCOUNT = -
COFP-HI LIFNR = -
COFP-LO LIFNR = -
COFP-HI KUNNR = -
COFP-LO KUNNR = -
COFP-XDELETE = -
COFP-HI XOPVW = -
COFP-LO XOPVW = -
COFP-ZAEHK = -
COFP-CHAINBELNR = -
COFP-MWSKZ = -
COFP-LEDNR = -
COFP-BELTP = 1
COFP-VERSN = 0
COFP-OWAER = COSP-TWAER
COFP-CPUDT = SY-DATUM
COFP-CPUTM = SY-TIME
after doing updation, its again saying Selection of all entries in table COFP with value type 51 to 62, selected year, selected cost elements above and for all selected WBS elements and all objects underneath. Summarisation by period.
Now, can someone help me as how to proceed with the entire thing? An elaborate and illustrative answer would be highly appreciable.
If you require any other information....then get back to me ..asap.
Its bit urgent.
Thanks & Regards,
RaviHi
update <table> from <i_tab>
for different conditions.
loop at i_cosp.
if cosp-mandt eq sy-mandt and cosp-objnr eq 'PR'.
Read table i_PRPS with key i_PRPS-OBJNR = i_COSP-OBJNR.
if sy-subrc eq 0.
update PRPS set PKOKR = ? where objnr = i_prpr-objnr.
endif.
endif.
similarly for all the conditions
Regards
Message was edited by: Harikishore Sreenivasulu -
Update table from another table
I have two tables
t1 t2
a b c d e f
1 2 3 1 1 11
4 5 6 1 2 22
7 8 9 7 1 33
I would like to update t1.c with t2.f if t1.a = t2.d and t2.e = 1
result:
t1 t2
a b c d e f
1 2 11 1 1 11
4 5 6 1 2 22
7 8 33 7 1 33
I tried
update t1
set c = (select f from t2 where t1.a = t2.d and t2.e = 1)
but this nulls out column t1.c where a = 4, since there is no row in t2 with d=4.
I then tried
update t1
set c = (select f from t2 where t1.a = t2.d and t2.e = 1)
where a in (select d from t2 where e = 1)
which worked, but took a lot longer (the real tables have a lot more rows)
Is there a better way to only update rows in t1, where a row in t2 exists?
Thanks, SalomonTry using exists instead of in and see if the update runs faster:
update t1
set c = (select f from t2 where t1.a = t2.d and t2.e = 1)
where exists(select d from t2 where t1.a = t2.d and t2.e = 1) -
How to post a data into table from another table
oracle forms6i
Hai All
I have created an form for the purpose of attendance generating. I had a problem that i can post only two data
I have two tables One table was created dynamically the data in the tables are fetched from text file and they are divided and stored the fields are
Barcode Bartime Bardate
000011 0815 08-01-2010-- he come in
000012 0816 08-01-2010
000013 0815 08-01-2010
000011 1130 08-01-2010--- he goes for a break
000011 1145 08-01-2010--- he again comes in
000011 1650 08-01-2010
000012 1655 08-01-2010
000013 1645 08-01-2010-- he goes home
From this i need to move these data to the database table the table name is dail_att and the fields are
barcode, timein,timeout,breakin,breakout,date Like i need like this
Barcode Timein Breakin Breakout Timeout Attend_date
000011 0815 1130 1145 1650 08-01-2010
I have tried using some count function and row count but it is not working Pls let give some good solutions
The coding is
declare
cnt number;
bar_code varchar2(25);
bar_date date;
in_time varchar2(25);
out_time varchar2(25);
intr_intime varchar2(25);
intr_outtime varchar2(25);
Cursor c1 is
select count(*),barcode,bardate,bartime
--row_number() over ( order by bartime ) RN
from temp_attendance
group by barcode,bardate,bartime
order by bardate;
begin
For r1 in c1 loop
--select barcode,bardate,bartime
--row_number() over partition by barcodeorder by bartime as rn
-- from temp_attendance
--group by barcode,bardate,bartime
-- order by bardate;
if (cnt <= 1 ) then
select barcode,intime,intrtimein,introuttime,outtime,attend_date into bar_code,in_time,intr_intime,intr_outtime,out_time,bar_date from dail_att where attend_date = r1.bardate-1;
update dail_att set outtime= r1.bartime where attend_date=r1.bardate and barcode=r1.barcode;
elsif(cnt <= 2 ) then
insert into dail_att(barcode,attend_date,intime,outtime)
values(r1.barcode,r1.bardate,min(r1.bartime),max(r1.bartime));
-- else
-- update dail_att set outtime= r1.bartime where attend_date=r1.bardate and barcode=r1.barcode;
end if;
End loop;
forms_ddl('commit');
exception
when others then
forms_ddl('rollback');
message(sqlerrm||dbms_error_Text);
message(sqlerrm||dbms_error_Text);
End;
Thanks & Regards
Srikkanth.MHai Sir
Once again thanks for Your Response,
Sir here i dont want to hard code timing because if there is any change in shifts then we need to change those thing
So i have tried some thing like this
declare
Cursor c1 is
Select BARCODE,BARDATE,BARTIME
From temp_attendance
ORDER BY BARCODE,BARTIME ;
begin
For r1 in c1 loop
if c1% rowcount=0 then
if sql%notfound then
insert into dail_att(barcode,attend_date,intime)
values(r1.barcode,r1.bardate,r1.bartime);
else
update dail_att set outtime= r1.bartime where barcode= r1.barcode
and intime is not null and attend_date=r1.bardate;
end if;
else
if sql%found then
update dail_att set intrintime= r1.bartime where barcode= r1.barcode
and intime is not null and attend_date=r1.bardate;
else
update dail_att set introuttime= r1.bartime where barcode= r1.barcode
and intime is not null and attend_date=r1.bardate;
end if;
End loop;
End;
if it correct pls tell ur comments on this and further changes
Thanks & Regards
Srikkanth.M -
Create a table from another table and add constraint statement. Please help
Previously, I post a question and it works as below:
create table my_table
PCTFREE 10 PCTUSED 0 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING STORAGE
INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT
TABLESPACE TAB_DATA
as select t1, t5, t2, t3, t4 from orig_table;
I have been trying to use the same strategy as I post earlier, but it doesn't work.
CONSTRAINT "MY_TEMP" UNIQUE ("ID", "SNAME", "CNAME", "TIME", "SYSTEM_ID")
USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT) TABLESPACE "TAB_DATA" ENABLE
CLUSTER MY_CLUSTER
"CNAME"
Below iis my SQL statement, but it doesn't work. Please help.
create table my_table
CONSTRAINT "MY_TEMP" UNIQUE ("ID", "SNAME", "CNAME", "TIME", "SYSTEM_ID")
USING INDEX PCTFREE 10 INITRANS 2 MAXTRANS 255 COMPUTE STATISTICS STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645 PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT) TABLESPACE "TAB_DATA" ENABLE
CLUSTER MY_CLUSTER
"CNAME"
as (select t1, t5, t2, t3, t4 from orig_table;Hi,
Why do you need to combine the two action togather. You can get the things done in two steps.
Create table tab1 as select * from tab2;
Then you create any contraint that you want to create on tab2 using 'alter table add constraint'.
Regards -
Need Logic for Inserting data into table from another table
Hi,
Could you please give me some logic on below:
TABLE_A has columns A,B,C,D
What i did
==========
Created new table
TABLE_1_A with columns A1,A2,B1,B2,B3
Requirement
===========
I should populate columns A1,A2 (table TABLE_1_A) with the data from column A (table TABLE_A)
& simillarly populate columns B1,B2 with the data from B.
the data is huge in the table_a.
Database: 10g
Thanks.Hi,
Here's one way:
INSERT INTO table_1_a
(a1, a2, b1, b2)
SELECT a, a, b, b
FROM table_a
I hope this answers your question.
If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all tables involved, and also post the results you want from that data.
If you're asking about a DML statement, such as INSERT, the sample data will be the contents of the table before the DML, and the results will be state of the changed table(s) when everything is finished.
Explain, using specific examples, how you get those results from that data.
See the forum FAQ {message:id=9360002} -
How to update one table from another
I am creating scripts in Oracle 10g. I have a table that has data corruption on three date fields.
I created a table with the following sql of all the affected rows:
CREATE TABLE LSU_INTER_FIX_DATE AS
select request_id,received_date,planned_start_date, actual_start_date
from lsu_inter2_requests_t
where received_date < to_date('01-JAN-1900')
OR planned_start_date < to_date('01-JAN-1900')
OR actual_start_date < to_date('01-JAN-1900')
I then repaired all of the rows with three data fixes
UPDATE LSU_INTER_FIX_DATE
SET received_date = TO_CHAR(received_date,'YY-MON') ||'-'||(TO_CHAR(received_date,'RRRR') + 2000)
where received_date < to_date('01-JAN-1900')
UPDATE LSU_INTER_FIX_DATE
SET planned_start_date = TO_CHAR(planned_start_date,'YY-MON') ||'-'||(TO_CHAR(planned_start_date,'RRRR') + 2000)
where planned_start_date < to_date('01-JAN-1900')
UPDATE LSU_INTER_FIX_DATE
SET actual_start_date = TO_CHAR(actual_start_date,'YY-MON') ||'-'||(TO_CHAR(actual_start_date,'RRRR') + 2000)
where actual_start_date < to_date('01-JAN-1900')
I now want to update the original base table with the corrected data so I wrote the following SQL UPDATE command:
UPDATE lsu_inter2_requests_t aaa
SET aaa.received_date = bbb.received_date
FROM LSU_INTER_FIX_DATE bbb WHERE aaa.request_id = bbb.request_id
When I run this sql Oracle returns the error “ORA-00933 SQL command not properly ended.” How do I update multiple rows in one table from another table that share the same primary key?Comet wrote:
I am creating scripts in Oracle 10g. I have a table that has data corruption on three date fields.
I created a table with the following sql of all the affected rows:
CREATE TABLE LSU_INTER_FIX_DATE AS
select request_id,received_date,planned_start_date, actual_start_date
from lsu_inter2_requests_t
where received_date < to_date('01-JAN-1900')
OR planned_start_date < to_date('01-JAN-1900')
OR actual_start_date < to_date('01-JAN-1900')
I then repaired all of the rows with three data fixes
UPDATE LSU_INTER_FIX_DATE
SET received_date = TO_CHAR(received_date,'YY-MON') ||'-'||(TO_CHAR(received_date,'RRRR') + 2000)
where received_date < to_date('01-JAN-1900')
UPDATE LSU_INTER_FIX_DATE
SET planned_start_date = TO_CHAR(planned_start_date,'YY-MON') ||'-'||(TO_CHAR(planned_start_date,'RRRR') + 2000)
where planned_start_date < to_date('01-JAN-1900')
UPDATE LSU_INTER_FIX_DATE
SET actual_start_date = TO_CHAR(actual_start_date,'YY-MON') ||'-'||(TO_CHAR(actual_start_date,'RRRR') + 2000)
where actual_start_date < to_date('01-JAN-1900')
I now want to update the original base table with the corrected data so I wrote the following SQL UPDATE command:
UPDATE lsu_inter2_requests_t aaa
SET aaa.received_date = bbb.received_date
FROM LSU_INTER_FIX_DATE bbb WHERE aaa.request_id = bbb.request_id
When I run this sql Oracle returns the error “ORA-00933 SQL command not properly ended.” How do I update multiple rows in one table from another table that share the same primary key?I am not convinced you have what you think you have
>
UPDATE LSU_INTER_FIX_DATE
SET received_date = TO_CHAR(received_date,'YY-MON') ||'-'||(TO_CHAR(received_date,'RRRR') + 2000)
where received_date < to_date('01-JAN-1900')
When you want to produce a DATE datatype when starting with a string,
you must use TO_DATE() on the SET line!
(TO_CHAR(received_date,'RRRR') + 2000)since when do you do add characters (from TO_CHAR) with a constant number (2000)?
You should NEVER EVER rely on implicit datatype conversion
Edited by: sb92075 on Jul 27, 2011 7:09 PM -
Procedure to insert in table from other table returning multiple records
Hi Everybody,
I am new to oracle. So need your advice guys. I have to insert values to one table from another table. Please let me know , how i can do this.
E.g:
INSERT INTO TABLEA(`Name`,`ID`,`another_field`) VALUES ('Somevalue',(SELECT DISTINCT id FROM TABLEB WHERE tb.cat = '5' AND ID NOT IN (select id from TABLEC)), 'somevalue')
Above thing is not working for me.
I have to insert ID IN TABLE A by getting value from this query:
SELECT DISTINCT id FROM TABLEB WHERE tb.cat = '5' AND ID NOT IN (select id from TABLEC)
This query is returning multiple IDs, so how can i insert all in TABLEA by creating some sp.
Please help me out of this. I will be very thankful to you all guys. I will really appreciate your suggestions and comments.
Regards
DevWhy cant you just do this,
INSERT INTO TABLEA (NAME, ID, another_field)
SELECT DISTINCT 'Somevalue',
ID,
'somevalue'
FROM TABLEB
WHERE tb.cat = '5'
AND ID NOT IN (SELECT ID FROM TABLEC)G.
Maybe you are looking for
-
How to Calculate Line items Total of Matrix Column
hai experts, Im facing a problem like 1. i have a matrix with a column Labour Costs in that im taking some cost. 2. in footer a have a Edit Text like Total Labour Cost 3 when i enter amount i
-
when i use pages and want to send a doc in word format, i always go to share and all works well. today when i go to share and specify to send my pages doc in word format, nothing happens. it just reverts back to my doc page. this happens in any of th
-
Starting a new thread on this as I have done much digging and no longer believe its a conflicting record issue. I am SCCM 2012 SP1 on Server 2008 R2/SQL 2012 CU2. My "Lan" based management point is HTTP and I also have an Internet Management point t
-
The issue is that, we had designed a form in Adobe Acrobat 7.0 and had that form fields with a font of "Dejavu Sans Mono" and text size of 7.We had this field prefilled with certain fields whenever the user clicks the appropriate link for helping the
-
Leading zero check got activated in production .
Hi, We had a DIMP ( Discrete Industries Mill Products) addtional installation to our existing landscape on last weekedn. we have a strange issue after that. Most of the select queries based on material number,vendor,customer are failing. with furthe