Stored procedure to update the new table by using back up table
Hi all,
oracle version -10g
iam planning to do one time legacy conversion during the migration of one of the tables.
for that i took the back up of table , now i need to transfer all of the data from the backup table to the new table with some changes..
so please suggest me how to write the stored procedure?
back up table name: test t
new table: test n
new table will have extra one row .. in that i need to put the logic
so am planning to write a procedure like below
create or replace procedure test as
begin
insert into TEST T ( u
v
w
X
y
z) VALUES
SET T.U = O.U
T.V = O.V
T.W = DECODE(O.W, AD '01',
00 '01')
T.X = O.X
T.Y = IF O.W = 'AD' AND O.Y = 'YES' THAN PUT 'AD'
IF O.W = '00' AND O.Y = 'YES' THAN PUT 'PD'
IF O.W NOT IN ('AD','00') AND O.Y = 'YES' THEN PUT 'E'
O.Y= 'NO' THEN PUT 'D'.
'
10g is not an Oracle version number. Please run the following:
SELECT * FROM v$version;What about your situation indicates a requirement for a stored procedure? I wouldn't write one based on what you have posted. It seems, again from what little you posted, that all you need is:
INSERT INTO <new_table>
SELECT ... FROM <temp_table>;
Similar Messages
-
When I updated the new version IOS5 and used icloud, some of the apps are missing, how can i find those apps (but i was not using my account to download some apps before). Please advise.
They are free to iOS 7 users who have activated their NEW device on Sept 1 2013 or after. They are NOT automatically free with iOS 7.
AirDrop is only compatible with iPad 4th gen and iPad mini. iPad 3rd gen and below do contain the necessary hardware for AirDrop. Also, AirDrop is only compatible between iOS devices. You cannot AirDrop between iOS device and Mac OS. -
How to write a procedure for update the table
Hi all
can any body please tell me how to write a procedure to update the table......
I have a table with about 10,000 records...........Now I have add a new column and I want to add values for that like
registration Code Creidits
13213 BBA
1232 MCS
I had add the creidit now i want to update the table.........the new value want to get by SQL like
Creidit = select creidit from othere_table...........
Hope u can understand my problem
Thanks in advance
Regards
Shayan
[email protected]Please try the following --
update Program_reg a
set TotalCreidit = ( select tot_cr <Accroding to your logic>
from Program_reg b
where a.Registration = b.Registration
and a.Enrollment = b.Enrollment
and a.code = b.code
where a.Registration in ( select distinct Registration
from Program_reg );
N.B.: Not Tested....
Regards.
Satyaki De. -
Procedure to update the table records
I have to write a procedure to update the existing records.
I have one staging table and one decode table.
staging table is obtained from a interface with cross join of two tables X1 and X2 and
lookup with DECODE table.
DECODE
ITEM_ID ITEM_CODE STORE_ID STORE_CODE
101 C 7 77
100 A
100 B
In this table there is relation between item_id and item_code AND
store_id and store_code. Items and stores have no relationship here. Simply we insert values of both side by side.
Initial STAGING table
SNO RNO SCODE RCODE DECODE_STATUS
101 8 C NP
101 6 C NP
101 7 C 77 P
100 8 A NP
100 6 A NP
100 7 A 77 P
100 8 B NP
100 6 B NP
100 7 B 77 P
Joins:
SNO=ITEM_ID
RNO=STORE_ID
Now I want to update this according to my new decode where NP record will be updated with their new RCODE values
DECODE table now is
ITEM_ID ITEM_CODE STORE_ID STORE_CODE
101 C 8 88
100 A 7 77
100 B 6 66
Now I need my staging table with RCODE values corresponing to DECODE table.
My expected STAGING table.
SNO RNO SCODE RCODE DECODE_STATUS
101 8 C 88 NP
101 6 C 66 NP
101 7 C 77 P
100 8 A 88 NP
100 6 A 66 NP
100 7 A 77 P
100 8 B 88 NP
100 6 B 66 NP
100 7 B 77 P
Please help me to do this ...I have tried with interface where I kept source and target table same staging table and used DECODE for lookup but I didnt get the expected result.Hi Chattar ,
It clearly seems that issue is with Primary keys.
As you have said about the decode table "In this table there is relation between item_id and item_code AND store_id and store_code. Items and stores have no relationship here. Simply we insert values of both side by side."
It seems your final update query should be like this :
update staging1 T
set (T.rcode, T.scode)
=
Select
(select store_code from decode where store_id = T.RNO ) ,
(SELECT ITEM_CODe from decode where ITEM_id = T.SNO)
from dual
) where T.decode_status = 'NP';
If what i have said is right , then you can implement the same using an interface too But first you should decide the Key columns on the target table.
Hope it solves the issue.
Edited by: user8427112 on Sep 22, 2012 6:48 AM -
Trigger is not updateing the :new value in the table
Hi,
I've greated a row trigger that will trigger on insert statements.
The last thing the trigger will do is to update the :NEW.role_id value in the inserted row, see the trigger bellow.
The trigger was mutation so I had to add the 'PRAGMA AUTONOMOUS_TRANSACTION;' to avoid the mutation error.
When performing test with controlled insert statements the trigger is working without problems, but when I my J2EE application is inserting rows to the table the role_id value is nog updated, see the trigger below and the :NEW.role_id := nRole_id; part. The role_id for the new row is empty. What can be the problem?
CREATE OR REPLACE TRIGGER MSP_36.M2_USER_ALERT_INSERT_TRG_SCA
BEFORE INSERT
ON MSP_36.M2_USER_ALERT
REFERENCING NEW AS NEW OLD AS OLD
FOR EACH ROW
DECLARE
ex_not_valid_role_name EXCEPTION;
/* Variables */
nAlertTypeId M2_USER_ALERT.alert_type%TYPE;
isLogical boolean;
validRole boolean;
nRole_id M2_ROLE.role_id%TYPE;
PRAGMA AUTONOMOUS_TRANSACTION;
BEGIN
BEGIN
SELECT distinct at.alert_type INTO nAlertTypeId
FROM M2_USER_ALERT ua, M2_ALERT_TYPE at,M2_ALERT_TYPE_PROPERTIES atp
WHERE ua.alert_type = at.alert_type
AND at.alert_type = atp.ALERT_TYPE_ID
AND ua.alert_type = :NEW.alert_type
AND upper(atp.property_name) = 'LOGICAL'
AND upper(atp.property_value) = 'TRUE';
isLogical := true;
EXCEPTION
WHEN no_data_found THEN
isLogical := false;
NULL;
END;
IF (isLogical = true) THEN
BEGIN
SELECT distinct ro.role_id INTO nRole_id
FROM M2_ROLE ro, M2_USER_ALERT
WHERE ro.name = :NEW.name;
EXCEPTION
WHEN no_data_found THEN
validRole :=false;
RAISE_APPLICATION_ERROR(-20001,'LOGICAL UserAlert: Role with id'|| nRole_id || ' does not exist.');
NULL;
END;
validRole := true;
IF (isLogical = true AND validRole = true AND :NEW.status = 1) THEN
INSERT INTO M2_USER_ROLE (user_id,role_id)
VALUES (:NEW.user_id,nRole_id);
:NEW.role_id := nRole_id;
END IF;
END IF;
commit;
END;
Many thanks,
MichaelI only get a empty column that include now data. The first insert is working correct so I know that the role_id is valid and working. Can there be problem with commit or my AUTONOMOUS_TRANSACTION running this from JDBC ?
EXAMPLE data from
M2_USER_ROLE
===================
USER_ID = ROLE_ID =
===================
20 = 10040 =
1259756 = 10040 =
===================
Example partly data from
M2_USER_ALERT
=========================================================
USERALERT_ID = USER_ID = ALERT_TYPE = NAME = ROLE_ID =
=========================================================
3725 = 1259756 = 10288 = MG_Test = =
=========================================================
When inserted from the application the role_id is empty and I've taken the same SQL from the library cache and run it with same BIND variables and then it's working.
Michael -
How to use the Stored Procedure to update my UDF
I want to use the Stored Procedure to update my UDF U_InstokCS when the warehouse "OnHand" was changed. The UDF is display the stock by cases. I copied the query as follewing. I couldn't see any thing in the UDF after I made some transactions. Can anybody tell me why? How to continue it?
if @transaction_type in ('A','U','D') and @Object_type='64'
begin
Update OITW
Set U_InstokCS = OnHand/(Select T0.NumInBuy from [DBO].[OITM] T0
Where T0.ItemCode = @list_of_cols_val_tab_del)
Where ItemCode = @list_of_cols_val_tab_del
end
Thanks.
Ying ZhangYing,
The use of any stored procedures against the SAP Business One database is not allowed per SAP Support. There is not an instance where you can use SP's. The ONLY SP that you are allowed to use is the SBO_SP_TransactionNotification SP that comes with SAP Business One itself. You can read about the use of this SP from this article...
https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/e991e2b9-0901-0010-0395-ef5268b00aaf
Eddy -
Exit stored procedure after UPDATE
Hello,
I have written a LOOP that calls a second Stored Procedure.
In the second Stored Procedure I have 3 INSERTS each SELECT's values limited with a WHERE clause.
Example:
begin
dynsql:=INSERT INTO destinationtable (ID,DATE,NAME)
SELECT src.ID,src.DATE, dest.NAME FROM sourcetable src INNER JOIN destinationtable dest ON dest.ID=src.ID WHERE dest.date between '01.JAN.2012 and '03.JAN.2012' --if not condition not met, no insert
execute immediate dynsql;
dynsql:=UPDATE destinationtable SET DATE = dest.DATE FROM sourcetable src INNER JOIN destinationtable dest ON dest.ID=src.ID WHERE dest.date between '01.JAN.2012 and '03.JAN.2012'
execute immediate dynsql;
dynsql:=INSERT INTO destinationtable (ID,DATE,NAME)
SELECT src.ID,src.DATE, dest.NAME FROM sourcetable src INNER JOIN destinationtable dest ON dest.ID=src.ID WHERE dest.date between '01.APR.2012 and '01.MAY.2012' --if not condition not met, no insert
execute immediate dynsql
dynsql:=UPDATE destinationtable SET DATE = dest.DATE FROM sourcetable src INNER JOIN destinationtable dest ON dest.ID=src.ID WHERE dest.date between '01.APR.2012 and '01.MAY.2012'
execute immediate dynsql;
dynsql:=INSERT INTO destinationtable (ID,DATE,NAME)
SELECT src.ID,src.DATE, dest.NAME FROM sourcetable src INNER JOIN destinationtable dest ON dest.ID=src.ID WHERE dest.date between '01.JUN.2012 and '01.JUL.2012' --if not condition not met, no insert
execute immediate dynsql;
dynsql:=UPDATE destinationtable SET DATE = dest.DATE FROM sourcetable src INNER JOIN destinationtable dest ON dest.ID=src.ID WHERE dest.date between '01.JUN.2012 and '01.JUL.2012'
execute immediate dynsql;
end;
commit;What do I do?
I update the existing "old" row with a new date and then I am basically duplicating that row but adding it with a new DATE, the ID and NAME is "copied" as it is.
The big problem is that the rows result in recursive updates. if the first statement updates a date it might make the conditions for the second and first update become "true".
Which is not what I want. Initially, only one of the statements is true, ever. The problem with my code is that after the first update and date setting, another "might" become true.
This should stop. After one of the updates occured, I need to stop the stored procedure.
How do I stop it after upate?metalray wrote:
Hello BlueShadow, that makes sense. Thanks.
Can you tell me when sql&rowcount is reset, after an execute immediate, after a commit?It doesn't get 'reset' in the strict sense. When a PL/SQL program unit is initiated the implicit "SQL" cursor space is defined and exists in the scope of that program unit. At that point it is like any variable that is declared with it's value undefined (null). When you issue any DML statement (insert, update, delete, merge etc.), these will explicitly set the ROWCOUNT attribute within the SQL cursor space. Other SQL statements are also issued from PL/SQL through the SQL "space" (interface), and as such, they may (it's not defined anywhere) effect the values of attributes within it, including the ROWCOUNT, but we cannot say exactly in what way. Therefore, the only thing that can be definitely determined is that a) when it's first instantiated, the SQL%ROWCOUNT will be null, and also, )_immediately_ after any appropriate DML statement the SQL%ROWCOUNT will contain the number of rows effected. If the SQL%ROWCOUNT value is examined at any other point, the value is indeterminate so, for example, after a commit statement, we cannot be sure what value it has or what that value refers to.
I loop through each tax no. need to do either an update, update or delete, delete, each with different WHERE clauses. the danger is that
I update and then the where clause for the deletion becomes true, but my process should not do the deletion if an update happened. its a sequential check and ones true and update/deletion made, the loop stored procedure should terminate. right now I check for sql&rowcount to "not" get into a update or delete if one already happened but I fail to grasp the logic of when sql&rowcount gets which value . I have the feeling that the parent stored procedure that calls my second one with the update and deletes sets the sqlrowcount to 1 because it has an insert. (I use 11g)After your insert/update you should immediately get the value of SQL%ROWCOUNT into a variable, so that you have the value before it is effected by other statements.
You can then use that value in your variable to determine program logic e.g. whether the delete should process or not, regardless of whether you issued further code between the insert/update and the check to see if you should delete. Don't rely on things 'resetting' the ROWCOUNT attribute, only rely on things setting it. -
Stored Procedure to update Ids
Hi,
I want to write a stored procedure to update IDs in detail table by matching description from master table i.e.
TabMaster
Col1: 1 2 3 4 5 6 7 8
Col2: A B C D E F G H
TabDetail
Col:
Col2: D B C E D A A B G H C
Please Help!
Thanks in advanceNow sure what you are really after, but it looks like you may only need a correlated update statement. This statement can then be put inside a stored procedure:
UPDATE TabDetail TD
SET Col = (
SELECT Col1
FROM TabMaster TM
WHERE TD.Col2 = TM.Col2
)This will update ALL the rows in the TabDetail table. However if you need to restrict the rows to be updated you can always add on a WHERE clause. -
Stored procedure to update particular key column with increment of +1
Hi,
This is my table
EMPID,NAME
1 SSS
2 AAA
I NEED STORED PROCEDURE TO UPDATE EMPID WITH INCREMENT OF +1.BASED ON
MAX(EMPID).fOr example if i execute stored procedure once it will update empid 2 as 3,
if i run same procedure again it will take increment +1 then emp id should be 4 like that i want output.
Any one please help me on this scenario...937506 wrote:
Hi All,
I have two tables,one is date dimension table,one is fact table.
when we load data through informatica (source as csv file),then key will be populated in fact table based on lookup on
date dimension table.it will create corresponding date key in fact table.
My scenario:we load data in to fact table with etl with "n" number of records only once at a time.
But next time onwords we will update that datekey in fact table through stored procedure.stored procedure
will take only max(date_key) from fact table then update that key as like +1(logic n+1)
If i run stored procedure nextday it will update that record with increment +1.
we wil schedule this storedprocedure to run daily once.For this i need stored procedure..
I think you will clear now................
thxSo, are you saying you want to keep the same data you loaded "yesterday" but update the date_key so it appears as if it was from today?
Still seems strange: why aren't you loading today's data?
Also, you are assuming that the date_key in the date dimension table increments with no gaps: if it was sequence generated, that might not be true. -
How to refresh the data in a container and to update the new data
Hi,
I have created a Module Pool Program in which i have two containers to display the long text.
Initially this container is filled and based on some condition i want to update the text in the same conatiner.
I am using the below two classes to do all this.
cl_gui_textedit,
cl_gui_custom_container,
Could someone help me how to remove the long text in the container and update the new long text.
I am getting the new long text but not able display it in the same container. Please someone help me how to refresh and update the container.
Thanks in advance.Hi
Try this.
IF cl_gui_textedit IS INITIAL.
create control container
CREATE OBJECT cl_gui_custom_container
EXPORTING
container_name = 'Container Name''
EXCEPTIONS
cntl_error = 1
cntl_system_error = 2
create_error = 3
lifetime_error = 4
lifetime_dynpro_dynpro_link = 5.
create text_edit control
CREATE OBJECT cl_gui_textedit
EXPORTING
parent = cl_gui_custom_container
wordwrap_mode = cl_gui_textedit=>wordwrap_at_windowborder
wordwrap_to_linebreak_mode = cl_gui_textedit=>false
EXCEPTIONS
error_cntl_create = 1
error_cntl_init = 2
error_cntl_link = 3
error_dp_create = 4
gui_type_not_supported = 5.
ENDIF.
*--use method to set the text
CALL METHOD cl_text_edit->set_text_as_stream
EXPORTING
text = t_lines ( Internal table with long text).
EXCEPTIONS
error_dp = 1
error_dp_create = 2
OTHERS = 3.
regards,
Raghu. -
Stored procedure call returns null result set when using temp table in sp!
Here's a really odd problem...
SQL Server stored procedure called sp_Test takes 1 input INT. Here is the code I call it with
cStmt = connection.prepareCall("{call sp_Test(?)}");
cStmt.setInt(1, 44);
cStmt.execute();
rs = cStmt.getResultSet();When the body of the stored proc is
CREATE PROCEDURE sp_Test(@i_NodeID INT)
AS
BEGIN
SELECT node_id FROM tbl_NavTree
END
GOthe query works and I get all node_id back in rs
BUT when the body of the stored proc is
CREATE PROCEDURE sp_Test(@i_NodeID INT)
AS
BEGIN
CREATE TABLE #Descendants(
descendant_id INT
SELECT node_id FROM tbl_NavTree
DROP TABLE #Descendants
END
GOThe rs comes back as NULL. Really really weird if you ask me. I also tried removing the DROP TABLE line just in case the SELECT had to be the last statement but still NULL.
Final note is that BOTH the above stored proc bodies work when executed within SQL Server query analyser.
Must be JDBC .. what can it be!??DROP TABLE #DescendantsMS SQL Server - right?
Then don't drop the table.
From the MS docs for "create table"
Local temporary tables are visible only in the current session;
A local temporary table created in a stored procedure is dropped automatically when the stored procedure completes. The table can be referenced by any nested stored procedures executed by the stored procedure that created the table. The table cannot be referenced by the process which called the stored procedure that created the table. -
How to update the New Depreciation Area in Asset Master Data
Hi,
Please guide me
How to update the New Depreciation Area in the Asset Master Data.
Regards
SrinivasHi,
a) The procedure is as follows:
1. Create Depreciation area via OADB.
2. Activate Depreciation area via OAYZ.
3. Automatic opening of new depreciation are via AFBN and program
RAFABNEW :
3.1 Indicator: Leave values initial = not ticked.
Do not set this indicator if you want the system
to copy the values from depreciation area 01.
3.2 Indicator: Leave values initial = ticked.
Set this indicator if you want to open the newly created
depreciation area without any values i.e. blank.
4. Recalculate depreciation via AFAR and program RAAFAR00.
b) Helpful notes:
430618 (Procedure for setting up new depreciation area)
301113 (Restrictions of RAFABNEW)
421549 (RAFABNEW: Error with closed fiscal years)
c) A documenttation you find if you enter RAFABNEW in SE38 and press the butto "documentation"
regards Bernhard -
I have recently updated the new apps via creative cloud now photoshop and bridge no longer work, they open then say they have encountered a problem and close, I also tried opening the old version of photo shop but getting the same result
What OS version? What's the exact error? Exactly when does the error occur? What previous versions? What is on the screen when the error displays? Does Photoshop get fully open?
Try opening Photoshop holding down Shift key immediately to turn off plug-ins. Lots of good suggestions here: Photoshop: Basic Troubleshooting steps to fix most issues -
I have two apple id's because my hotmail account is no longer active. How can I delete the old one and use or update the new one? Every time I try it won't allow me and now my iPad thinks there are two accounts and they are arguing with each other. Help!
You can't merge accounts or copy content to a different account, so anything that you bought or downloaded via the old account is tied to that account - so any updates that those apps get you will only be able to download via that account. You can change which account is logged in on the iPad via Settings > Store
-
HT4623 How do I update my iphone 5 to the new ios7 software using itunes on my computer?
How do I update my iphone 5 to the new ios7 software using itunes on my computer?
Just for clarity, do you have iTunes 11.1 now on your computer? If yes, when you connect your iPhone via your USB / Lightning cable is your iTunes opening with a small box near the top right of screen that shows your iPhone connected? If yes then you can click through the various views of your iPhones content areas, such as Music, Photos, etc. You will eventually get to a screen that is Status. On that screen you should see the iOS Update option.
Maybe you are looking for
-
Firefox won't establish a connection. Please help
Hello, My Mozilla Firefox has worked for ages and all of a sudden when my father tried to open it, it came up with a message saying: 'Unable to connect Firefox can't establish a connection to the server at www.ebay.com.au. The site could be temporari
-
A problem with custom painting.
I was trying to make a bar chart from a given data. I used an extension JLabel (mentioned as inner class Leonardo) inside a scrollpane for the custom painting of the bars (rectangles). The problem I am facing is the component is not visible when I op
-
Hello 2 questions: How to upload my video to iCloud and share it? What format should it be before I upload?
-
hi all i have to develop a page in an enterprise portal where employees can upload files. but the provided "Add new item" wizard seems too complicated and user-unfriendly to them, since it is not IT personel and they don't have a proper command of en
-
How to sync Safari bookmarks from iMac to iPhone?
How to sync Safari bookmarks from iMac to iPhone? About my Safari bookmarks that are currently residing only on my iMac, I would like to see the same Safari bookmarks on my iPhone as well. Can I sync them from the iMac to the iPhone? Thanks.