Insert records from one table to other table
Hi,
I want to insert all the records from table 1 which are not in table 2 into table2
o/p
insert into table2
select * from table1
where a.id!=b.id;
Please let me know is there any way that I can populate the records
insert
into table2
select *
from table1
where id not in (
select id
from table2
);SY.
Similar Messages
-
Insert records from report program into R3 table
Hi
I wanted to insert records from report program into R3 table.
here is my code
data : itab type standard table of zemp initial size 10 with header line.
itab-EMPNO = '012'.
itab-ENAME = 'XXXX'.
itab-JOB = 'XXXX'.
APPEND itab.
insert ztable from table itab.
but i am getting the following error
the type of the data base table and work area/internal table "ITAB" are no unicode-converible.
how can I insert records from report program into R3 table
should I have to write move corresponding
pls guide
thanks
manianHi,
itab-EMPNO = '012'.
itab-ENAME = 'XXXX'.
itab-JOB = 'XXXX'.
APPEND itab.
insert ztable from table itab.
Do one thing
Data : itab type table of ztable with header line.
itab-EMPNO = '012'.
itab-ENAME = 'XXXX'.
itab-JOB = 'XXXX'.
APPEND itab.
insert ztable from table itab.
error will resolve, then try to make structure similar to ZTABLE -
Insert record from one table to another with help of cursor
Plz help!!!
tables are - 1. country( country_id pk, country_name, region_id)
2. a( country_id , country_name, region_id)
table a data are
1 a 1
2 b 2
3 c 3
null d 4
5 e 5
6 f 6
7 g 7
insert record from table a to country table with help of cursor, insert all not null records.
this procedure does not give correct result
create or replace
procedure amit as
cursor c1 is select * from a;
rw a%rowtype;
begin
open c1;
fetch c1 into rw;
while(c1%found)
loop
insert into countries values(rw.country_id,rw.country_name,rw.region_id);
commit;
fetch c1 into rw;
if rw.country_id is null then
fetch c1 into rw;
end if;
end loop;
close c1;
exception
when others then
dbms_output.put_line('exception name= '||rw.country_name);
end;bluefrog wrote:
You don't need cursor at all;
create or replace procedure amit as
begin
insert into countries (Country_ID, Country_Name, Region_ID)
(select a.Country_ID
,a.Country_Name
,a.Region_ID
from a
dbms_output.put_line('Rows inserted : ' || sql%rowcount);
commit;
end;
Bluefrog you missed where clause. :)
insert into countries (Country_ID, Country_Name, Region_ID)
(select a.Country_ID
,a.Country_Name
,a.Region_ID
from a
where country_id is not null
); -
Create Trigger to insert records from one table to another
I created the below trigger to move data from one table to another after records have been inserted from another table to that table. What I need done is that each time records have been inserted into TEST_TBL, one of these actions codes should be implimented: U-update, N-insert, D-delete and inserted into TEST_TBL1. But each time I run the script, I get bunch of errors. Please see the script below: - Your help will be appreciated.
create or replace
trigger POWER_tr
after update or insert or delete ON test_tbl
for each row
begin
if updating then
insert into test_tbl1
(idx, mke, ctl, ori, nam, sex, rac, pob, dob, hgt, action_code, date_added
VALUES
(idx, mke, ctl, ori, nam, sex, rac, pob, dob, hgt, 'U', sysdate);
ELSif INSERTING then
insert insert into test_tbl1
(idx, mke, ctl, ori, nam, sex, rac, pob, dob, hgt, action_code, date_added
VALUES
(idx, mke, ctl, ori, nam, sex, rac, pob, dob, hgt, 'N', sysdate);
ELSIF deleting then
insert into test_tbl1
(idx, mke, ctl, ori, nam, sex, rac, pob, dob, hgt, action_code, date_added
VALUES
(idx, mke, ctl, ori, nam, sex, rac, pob, dob, hgt, 'D', sysdate);
END IF;
END POWER_tr;
Thank you,
Albert Zaza
Edited by: azaza on Mar 1, 2009 4:14 PMHello
At the end of trigger show errors / and post what errors are you getting exactly?
Here is a simple example for your reference, this will save old values in history table; you can replace it with new values if that's what do you want.
CREATE OR REPLACE TRIGGER TRG_DU
AFTER DELETE OR UPDATE
ON EMPLOYEE REFERENCING NEW AS New OLD AS Old
FOR EACH ROW
DECLARE
BEGIN
IF UPDATING
THEN
INSERT INTO employee_hist
VALUES ('UPDATE',
:OLD.empid,
:OLD.name,
:OLD.deptid);
ELSIF DELETING
THEN
INSERT INTO employee_hist
VALUES ('UPDATE',
:OLD.empid,
:OLD.name,
:OLD.deptid);
END IF;
EXCEPTION
WHEN OTHERS
THEN
-- Consider logging the error and then re-raise
RAISE;
END TRG_DU;
/Regards
Edited by: OrionNet on Mar 1, 2009 7:27 PM -
Need to create infor record from one plant to other
Hi All,
We have a requirement where we need to create a info record in plant 120.
we already have the info records in the plant 130 and need to merge them in plant 120 even.
So requirement is to get the infor records from plant 130 and create in plant 120.
We have batch input programs ZRM06IBI0 ( create purch info record ) by which we can create the info record with available sequential file. this sequential file will be created by program RM06IBIE ( Create sequetial file for Purch info record ).
The problem here to use this things is that it creates a session for each record which will result in lacs of session created. which is not advaisable.
another option is to use BDC. but because of performance issues we need to skip it out and find any other method or function modules which can get the inforecords info from the database for plant 130 and create the same in plant 120.
Please help me in this regard.
Helpfull answers will be rewarded.
BR,
RaviTry:
INSERT INTO fnd_lobs
(fnd_lob_id,
file_data
VALUES (1, -- or whatever the identifying value is
(SELECT blob_type_column
FROM xxxx
WHERE xxxx_id = 1 -- or whatever the identifying value is
;If this doesn't work, then please list the table create statements for each table. -
Info records from one plant to other....urgent
Hello all,
I have to move data from one plant in SAP to another.I have to transfer all the info records, i know i can do this by LSMW but can someone please tell me how do i make flat files for this, i mean what is the procedure for getting data of all info records out of one plant as flat file and into other plant..
Please reply asap..
Regards
NehaHi Neha...
One of the option is, u need to get the data of relevent fields that u want to upload through LSMW, as u said u have the data already existing for one plant, so download the data from EINE table into an excel sheet and modifythe excel sheet as per the new plant data.
now save this excel sheet into a .txt file and upload through lsmw
Regards
Bapears -
Insert records from user form to multiple tables in same database
Hi Experts, I need your help. I have a form that has multiple text fields that I need to insert the records to their each respective table. For example: The first name field needs to go the the name table, address goes to a seperate table, phone goes to a seperate table and so on.
Is this possible to do?
Thanks Much
ShamThe same for ASP, JSP or PHP. Just the code syntax is different for each language. Are you using MySQL, Access or ?
In any case, create the three recordsets on the database and use insert queries. If you don't know what one is, google insert query and you will see the syntax.
Here is a good example out on the web
http://www.stardeveloper.com/articles/display.html?article=2000032601&page=1
In your case you would get the values for the inserts from the form data and only need to open the database connection once.
Good luck.
Walt
B & B Photography -
Insert data from one form to another table
I have a form which of course insert data into table1, i created a process within this form and include a sql statement to achieve this for me. My thoughts are this will take whatever is the value from the form and insert it into table2.
INSERT INTO ML_LIST (ML_TITLE,ML_LASTNAME)
VALUES
(P20_SSR_TITLE, P20_SSR_LASTNAME);
My error is column not allowed here
Any suggestionsI used the following
Begin
INSERT INTO ML_LIST (ML_TITLE,ML_LASTNAME)
VALUES
(:P20_SSR_TITLE,:P20_SSR_LASTNAME);
End; -
Inserting data from one table to another in different format
Hello,
I would like to know what I am doing wrong with the following code when I write a data from one another to another table in a different format. I am now learning PL/SQL and am using this as
a test problem.
I have a table called students which has the following columns:
SQL> desc student
Name Null? Type
----------- ----------------STUDENT_ID NUMBER(10)
COURSE VARCHAR2(10)
CREDITS NUMBER(10)
I have created another table called new_student which has the following structure:
SQL> desc new_student
Name Null? Type
----------------------------------------- -------- ------------- STUDENT_ID NUMBER(10)
COURSE VARCHAR2(30)
CREDITS VARCHAR2(10)
The data in the student table is:
SQL> select * from student;
STUDENT_ID COURSE CREDITS
1 Science 4
1 History 3
2 Science 4
2 History 3
2 Math 4
3 Sociology 3
3 Psycology 3
I want to store the STUDENT table data in NEW_STUDENT table as:
STUDENT ID COURSES CREDITS
1 Science/History 4/3
2 Science/History/Math 4/3/4
3 Sociology/Psycology 3/3
This is my code:
DECLARE
-- Get all the student IDs
CURSOR studentlist_cursor IS select distinct student_id from student ORDER BY student_id;
-- Get the information for each student ID
CURSOR courses_cursor(nstudentid number) is select course, credits from student where student_id=nstudentid;
nIndex INTEGER;
pltcourses DBMS_SQL.VARCHAR2_TABLE;
pltcredits DBMS_SQL.NUMBER_TABLE;
newcourses varchar2(50);
newcredits varchar2(10);
BEGIN
FOR student_rec IN studentlist_cursor
LOOP
nIndex:=0;
-- Loop through each student ID from student_rec to get the
--courses and creditsstudent ID
FOR courses_rec in courses_cursor(student_rec.student_id)
LOOP
nIndex:=nIndex+1;
pltcourses(nIndex):=courses_rec.course;
-- Store the course data for each student ID in newcourses
-- while doing so check if it is null or put a '/' between each course
loop
if newcourses is null then
newcourses:=pltcourses(nIndex);
else
newcourses:=newcourses||'/'||pltcourses(nIndex);
end if;
end loop;
pltcredits(nIndex):=courses_rec.credits;
--Store credits data in variable newcredits
--If the newcredits is not null then put a '/' between each credits
loop
if newcredits is null then
newcredits:=pltcredits(nIndex);
else
newcredits:=newcredits||'/'||pltcredits(nIndex);
end if;
end loop;
-- Insert student id, newcourses, newcredits into NEW_STUDENT
INSERT INTO NEW_STUDENT
(student_id ,
course,
credits
) VALUES
(student_rec.student_id,
newcourses,
newcredits
COMMIT;
-- come out of the student id record and go to the next student --id record
END LOOP;
-- come out of the loop
END LOOP;
END;
While doing so I get an error message:
declare
ERROR at line 1:
ORA-06502: PL/SQL: numeric or value error
ORA-06512: at line 23.
The error is at the line:
newcourses:=newcourses||'/'||pltcourses(nIndex);
Can anyone help me by pointing out where the mistake is?
Thank you for reading this long mail.
Thank you.
Rama.Hi dude
there is lot of error in ur pl/sql.
and u have created table new_student with columns
student_id number(10),
courses varchar2(30),
credits number(10).
first u need to modify ur table.
student_id number(10),
courses varchar2(30),
credits varchar2(10).
Now i am writing whole pl/sql block for u. it will work fine.
DECLARE
CURSOR studentlist_cursor IS select distinct student_id from student ORDER BY student_id;
CURSOR courses_cursor(nstudentid number) is select course, credits from student
where student_id = nstudentid;
nIndex INTEGER;
pltcourses DBMS_SQL.VARCHAR2_TABLE;
pltcredits DBMS_SQL.NUMBER_TABLE;
newcourses varchar2(50);
newcredits varchar2(10);
BEGIN
FOR student_rec IN studentlist_cursor
LOOP
nIndex:=0;
newcourses := null;
newcredits := null;
FOR courses_rec in courses_cursor(student_rec.student_id)
LOOP
nIndex:=nIndex+1;
pltcourses(nIndex):=courses_rec.course;
if newcourses is null then
newcourses:=pltcourses(nIndex);
else
newcourses:=newcourses||'/'||pltcourses(nIndex);
end if;
pltcredits(nIndex):=courses_rec.credits;
if newcredits is null then
newcredits:=pltcredits(nIndex);
else
newcredits:=newcredits||'/'||pltcredits(nIndex);
end if;
end loop;
INSERT INTO NEW_STUDENT
(student_id,
course) VALUES
(student_rec.student_id,
newcourses);
END LOOP;
END;
and please revert back
Regards
Anil -
Insert data from one table to another.
I have two tables - T1 & T2.
T1 has columns A1,A2,A3,A4 (A1 & A2 are the primary keys)
T2 has columns B1,B2,B3,B4 (B1 & B2 are the primary keys)
I need to insert records from T1 to T2 with the conditions,
- A1,A2,A3 will have the same record for the multiple records of A4.
This is what I tried and got the error:-
SQL> INSERT INTO nego_prop_supp (nps_supp_cd, nps_enq_no, nps_supp_resp, nps_cs_rank)
2 SELECT DISTINCT tos_supp_code, tos_enq_no, tos_bid_seal_condn, csr_set_rank
3 FROM tender_opening_supp, cs_rate
4 WHERE tos_enq_no = '7211233E' AND
5 tos_supp_code = csr_scd AND
6 (tos_nature_of_bid = 'P' or tos_nature_of_bid = 'N') AND
7 csr_set_rank IS NOT NULL;
INSERT INTO nego_prop_supp (nps_supp_cd, nps_enq_no, nps_supp_resp, nps_cs_rank)
ERROR at line 1:
ORA-00001: unique constraint (DPURC.NEGO_PROP_SUPP_PK) violated
You could understand that T1 consists (data from 'tender_opening_supp' & cs_rate), while T2 is nego_prop_supp.
Pls. get me the soution for thi problem!!then this query
SELECT DISTINCT tos_supp_code, tos_enq_no, tos_bid_seal_condn, csr_set_rank
3 FROM tender_opening_supp, cs_rate
4 WHERE tos_enq_no = '7211233E' AND
5 tos_supp_code = csr_scd AND
6 (tos_nature_of_bid = 'P' or tos_nature_of_bid = 'N') AND
7 csr_set_rank IS NOT NULL
8 and not exists (select nps_supp_cd from nego_prop_supp,tender_opening_supp where tos_supp_code
= nps_supp_cd) ;
have more than one tos_supp_code (the same any times) with any different value from tos_enq_no, tos_bid_seal_condn, csr_set_rank
then anything is wrong or your key(on nego_prop_supp ) or the query retrieve rows that you not want
the join is ok?
why this join retrieve more than one value with the key of the other table? Do you need to filter any more? are you missing a filter? -
Inserting records from internal table to database table
Hi all,
i want to insert records from internal table to zDatabase table, can u plz guide me which statement is better in performance to insert the records.
1) insert one by one record from internal table
loop at itab.
insert ztable from wa.
endloop.
2) insert total records at a time
INSERT <dbtabname> CLIENT SPECIFIED FROM TABLE itab.
or let me know if any other statement is there with high performance.
i internal table contains nearly 40000 records.
thanks.Hi,
Insert the entire table at atime rather than a record so as to increase the performance.
you can use INSERT <dbtabname> CLIENT SPECIFIED FROM TABLE itab.
or
MODIFY ZPRODUCT FROM TABLE GI_AFPO.
Regards,
Raj. -
Inserting data from one table into another table using PL/SQL
HI,
I am trying to insert values from one table into another using PL procedure, the values I want to retrieve from the table riverside1 are charac_id and charac_type and insert these values into another table called riverside2 , the stored procedure zorgs_gorfs(x,y) accepts two parameters which are 2 charac_id's of d characters in riverside1 then using insert statements inserts these characters from riverside1 into riverside2.
CREATE OR REPLACE PROCEDURE zorgs_gorfs(x IN NUMBER, y IN NUMBER) AS
BEGIN
INSERT INTO riverside2
(charac_id)
VALUES
(x);
INSERT INTO riverside2
(charac_id)
VALUES
(y);
END zorgs_gorfs;
/This works but the problem im having is that when I also try to insert the charac_type as well as the charac_id it doesnt work below is the code:
CREATE OR REPLACE PROCEDURE zorgs_gorfs(x IN NUMBER, y IN NUMBER) AS
BEGIN
INSERT INTO riverside2
(charac_id,charac_tye)
VALUES
(Select
charac_id,
charc_type
FROM
riverside1
WHERE
charac_id = x);
END zorgs_gorfs;
/can someone kindly sort me outmodify this sql
INSERT INTO riverside2
(charac_id,charac_tye)
VALUES
(Select
charac_id,
charc_type
FROM
riverside1
WHERE
charac_id = x);as
INSERT INTO riverside2
(charac_id,charac_tye)
VALUES
(Select
charac_id,
charc_type
FROM
riverside1
WHERE
charac_id in ( x,y));But my suggestion would be consider revising your approach. It does not look that good.
Thanks,
karthick. -
How to move table from one tablespace to other tablespace?
how to move table from one tablespace to other tablespace?
887274 wrote:
how to move table from one tablespace to other tablespace?
alter table <table_name> move tablespace <new_tablespace_name>;
Rebuild the indexes; alter index <index_name> rebuild <new_tablespace_name> online;Example;:
SQL> create table ttt( ID NUMBER PRimary key);
Table created.
SQL> insert into ttt values (1);
1 row created.
SQL> commit;
Commit complete.
SQL> select index_name, status from dba_indexes where table_name='TTT';
INDEX_NAME STATUS
SYS_C0010863 VALID
SQL> alter table ttt move tablespace users;
Table altered.
SQL> select index_name, status from dba_indexes where table_name='TTT';
INDEX_NAME STATUS
SYS_C0010863 UNUSABLE
SQL> alter index SYS_C0010863 rebuild tablespace users online;
Index altered.
SQL> select index_name, status from dba_indexes where table_name='TTT';
INDEX_NAME STATUS
SYS_C0010863 VALID
SQL> -
How can we copy table from one schema to other schema
Hi,
I have create one table in one schema and i want to copy it to other schema.How we can copy table from one schema to other schemaHi,
You can try something like this :-
SQL> CONNECT SYS/SYS123@SERVER AS SYSDBA
Connected.
SQL> CREATE USER TEST_1 IDENTIFIED BY TEST_1;
User created.
SQL> CREATE USER TEST_2 IDENTIFIED BY TEST_2;
User created.
SQL> GRANT CONNECT,RESOURCE,DBA TO TEST_1;
Grant succeeded.
SQL> GRANT CONNECT,RESOURCE,DBA TO TEST_2;
Grant succeeded.
SQL> CONNECT TEST_1/TEST_1@SERVER
Connected.
SQL> CREATE TABLE TEST_COPY ( TEST_COL NUMBER );
Table created.
SQL> INSERT INTO TEST_COPY VALUES ( 1 );
1 row created.
SQL> INSERT INTO TEST_COPY VALUES ( 2 );
1 row created.
SQL> COMMIT;
Commit complete.
SQL> GRANT ALL ON TEST_COPY TO TEST_2;
Grant succeeded.
SQL> CONNECT TEST_2/TEST_2@SERVER
Connected.
SQL> CREATE TABLE TEST_COPY AS SELECT * FROM TEST_1.TEST_COPY;
Table created.
SQL> SELECT * FROM TEST_COPY;
TEST_COL
1
2Regards,
Sandeep -
How to exclude records from one table that is contained in a second table
I am trying to create a Crystal report that excludes records from one Table that is contained in a second table using the != link option and it is not working. I've tried all of the different enforce options, and it is still not excluding those records. Does anyone have any suggestions of what I'm doing wrong or any other suggestions how I can obtain the results I need?
Thanks in advance!Have you tried by Command ?
Thanks,
Gordon
Maybe you are looking for
-
Partner function for a team in Change Request Management
I have defined a new transaction type based on Urgent Correction. I have three partner functions: Change Manager, Team Member and Quality Assurance Team. The first two partner functions are represented by single business partner so I can define them
-
Is Bridge CC available on Single app Illustrator subscription for Individuals?
SIngle app subcriptions for Teams FAQs mentions bridge is available for Illustrator single app subscribers, but can't find the same Information for Individuals. If I purchase the Creative Cloud for teams single-app plan, will I have access to Adobe B
-
can i put a CRT monitor to a DVI that has a VGA converter?
-
Hello, As I tried out things on my mac I typed "uptime" in Terminal and in the resulting line there was the period it's been up for without a reboot AND it also said "2 users". But i'm strictly the only one using this computer and the only user accou
-
Prerequisites to install NW2004s WDP for ABAP
Hi SDN Gurus, I wanted to practice the WDP for ABAP in NW2004s in my PC. Could you please let me know how can I get the trial versions of these and the installation process. Thanks, David.