Home » Developer & Programmer » Forms » Getting data from one table and saving into a new table (Developer 6i, Oracle9i)
Getting data from one table and saving into a new table [message #359234] |
Fri, 14 November 2008 05:17 |
roome
Messages: 8 Registered: November 2008 Location: Muzaffarabad Kashmir
|
Junior Member |
|
|
Database table CASES carry all the records.
As few people have migrated from thier previos location. Now i wanna save thier new location and also want to have thier previous histroy.
I wanna to search record from this table CASES and then save with ammendments into a new table APPLICATION_RURAL.Now tell me some way that in new table APPLICATION_RURAL have both origional and ammended record.
FORM which i Use for this purpose is APPLICATION_REC_RURAL.
I have wrote this code for searching and then after ammendment i save it by SAVE BUTTON. I just mention the Search and ammendment programming here not Save Button Programming. Kindly help me.
DECLARE
V_FOUND NUMBER;
v_alert NUMBER;
V_mouno number :=NULL;
V_cnic number :=NULL;
BEGIN
--Search through NIC-------------------------
--=============================================
IF :CTRL_BLK.RG_SEARCH='N'THEN
SELECT COUNT(*) INTO V_FOUND FROM CASES WHERE C_NIC=:CTRL_BLK.V_SEARCH;
IF V_FOUND<>0 THEN
select nvl(count(*),0) into V_cnic from APLICATION_RURAL where C_NIC=:CTRL_BLK.V_SEARCH;
IF V_cnic <=0 then
INSERT INTO APLICATION_RURAL (ACC_NO, ACCT_TITLE, AMOUNT, APP_DATE,APP_ID, B_ADDRESS, B_BRANCH, BANK, C_NIC, COMMENTS, DISTRICT, ENTRY_BY, ENTRY_DATE, FATHER_NAME, PROVINCE, TEHSIL,UC, UPDATE_BY, UPDATE_DATE, VILLAGE)
SELECT ACC_NO, ACCT_TITLE, AMOUNT, APP_DATE,APP_ID, B_ADDRESS, B_BRANCH, BANK, C_NIC, COMMENTS, DISTRICT, ENTRY_BY, ENTRY_DATE, FATHER_NAME, PROVINCE, TEHSIL,UC, UPDATE_BY, UPDATE_DATE, VILLAGE FROM CASES
WHERE C_NIC=:CTRL_BLK.V_SEARCH;
COMMIT;
END IF;
END IF;
END IF;
|
|
|
|
Re: Getting data from one table and saving into a new table [message #359664 is a reply to message #359234] |
Mon, 17 November 2008 23:06 |
roome
Messages: 8 Registered: November 2008 Location: Muzaffarabad Kashmir
|
Junior Member |
|
|
Our Database table CASES is the main table and carry all the records.
I search record from this table CASES and then save with ammendments into a new table APPLICATION_RURAL.Now tell me some way that in new table APPLICATION_RURAL have both origional and ammended record.
e.g As few people have migrated from thier previos location. Now i wanna save thier new location and also want to have thier previous histroy.
FORM which i Use for this purpose is APPLICATION_REC_RURAL.
I have wrote this code for searching and then after ammendment i save it by SAVE BUTTON. I mentioned here the CODE of Search Button and Save Button .
THIS CODE COMPILE SUCCESFULLY, AND ALSO FORM RUN SUCCESSFULY, FETCH DATA FROM CASES AND SAVE IT TO APPLICATION_RURAL SUCCESFULLY, But the only problem is that when i make changes to desired fields and save it, It make changes to existing record, But i require to save record with changes as a new record as well as origional record alongwith in new table APPLICATION_RURAL . Kindly help me.
code for SEARCH BUTTON is as under
DECLARE
V_FOUND NUMBER;
v_alert NUMBER;
V_mouno number := NULL;
V_cnic number := NULL;
BEGIN
--Search through NIC-------------------------
--=============================================
IF :CTRL_BLK.RG_SEARCH = 'N' THEN
SELECT COUNT (*)
INTO V_FOUND
FROM CASES
WHERE C_NIC = :CTRL_BLK.V_SEARCH;
IF V_FOUND0 THEN
select nvl (count (*), 0)
into V_cnic
from APLICATION_RURAL
where C_NIC = :CTRL_BLK.V_SEARCH;
IF V_cnic <= 0 then
INSERT INTO APLICATION_RURAL
(ACC_NO, ACCT_TITLE, AMOUNT, APP_DATE, APP_ID, B_ADDRESS,
B_BRANCH, BANK, C_NIC, COMMENTS, DISTRICT, ENTRY_BY,
ENTRY_DATE, FATHER_NAME, PROVINCE, TEHSIL, UC, UPDATE_BY,
UPDATE_DATE, VILLAGE)
SELECT ACC_NO, ACCT_TITLE, AMOUNT, APP_DATE, APP_ID, B_ADDRESS,
B_BRANCH, BANK, C_NIC, COMMENTS, DISTRICT, ENTRY_BY,
ENTRY_DATE, FATHER_NAME, PROVINCE, TEHSIL, UC, UPDATE_BY,
UPDATE_DATE, VILLAGE
FROM CASES
WHERE C_NIC = :CTRL_BLK.V_SEARCH;
COMMIT;
END IF;
END IF;
END IF;
end;
code for SAVE BUTTON is as under
--Save Button Code--
====================
begin
IF :APLICATION_REC.APP_ID IS NULL THEN
SELECT NVL (MAX (APP_ID), 0)
INTO :APLICATION_REC.APP_ID
FROM APLICATION_RURAL;
:APLICATION_REC.APP_ID := :APLICATION_REC.APP_ID + 1;
:APLICATION_REC.STATUS := 'ARC';
SELECT TO_DATE (SYSDATE, 'DD-Mon-YYYY HH24:MI:SS')
INTO :APLICATION_REC.APP_DATE
FROM DUAL;
SELECT USERNAME
INTO :APLICATION_REC.UPDATE_BY
FROM USER_USERS;
UPDATE APLICATION_RURAL
SET APP_ID = :APLICATION_REC.APP_ID,
APP_DATE = :APLICATION_REC.APP_DATE,
UPDATE_BY = :APLICATION_REC.UPDATE_BY,
UPDATE_DATE = :APLICATION_REC.APP_DATE
WHERE C_NIC = :APLICATION_REC.C_NIC;
COMMIT;
else
MESSAGE ('You Cannt Save the record');
MESSAGE ('You Cannt Save the record');
RAISE Form_Trigger_Failure;
END IF;
end; [EDITED by DJM: formatted the code and applied [code] tags - please do that yourself in the future]
[Updated on: Tue, 18 November 2008 00:47] by Moderator Report message to a moderator
|
|
|
|
|
|
|
|
|
|
Goto Forum:
Current Time: Wed Dec 04 19:47:10 CST 2024
|