Best way to update a table with disinct values
Hi, i would really appreciate some advise:
I need to reguarly perform a task where i update 1 table with all the new data that has been entered from another table. I cant perform a complete insert as this will create duplicate data every time it runs so the only way i can think of is using cursors as per the script below:
CREATE OR REPLACE PROCEDURE update_new_mem IS
tmpVar NUMBER;
CURSOR c_mem IS
SELECT member_name,member_id
FROM gym.members;
crec c_mem%ROWTYPE;
BEGIN
OPEN c_mem;
LOOP
FETCH c_mem INTO crec;
EXIT WHEN c_mem%NOTFOUND;
BEGIN
UPDATE gym.lifts
SET name = crec.member_name
WHERE member_id = crec.member_id;
EXCEPTION
WHEN NO_DATA_FOUND THEN NULL;
END;
IF SQL%NOTFOUND THEN
BEGIN
INSERT INTO gym.lifts
(name,member_id)
VALUES (crec.member_name,crec.member_id);
END;
END IF;
END LOOP;
CLOSE c_mem;
END update_new_mem;
This method works but is there an easier (faster) way to update another table with new data only?
Many thanks
>
This method works but is there an easier (faster) way to update another table with new data only?
>
Almost anything would be better than that slow-by-slow loop processing.
You don't need a procedure you should just use MERGE for that. See the examples in the MERGE section of the SQL Language doc
http://docs.oracle.com/cd/B28359_01/server.111/b28286/statements_9016.htm
MERGE INTO bonuses D
USING (SELECT employee_id, salary, department_id FROM employees
WHERE department_id = 80) S
ON (D.employee_id = S.employee_id)
WHEN MATCHED THEN UPDATE SET D.bonus = D.bonus + S.salary*.01
DELETE WHERE (S.salary > 8000)
WHEN NOT MATCHED THEN INSERT (D.employee_id, D.bonus)
VALUES (S.employee_id, S.salary*.01)
WHERE (S.salary <= 8000);
Similar Messages
-
Best way to update RBSELBEST table for invoice
what is the best way to update RBSELBEST table for PO invoice? Is there any BAPI or FM for this?
Thanks. I tried this one also, but it does not update the table.
in case if someone used this, what parameters i need to pass for this to work? -
Best way to update custom table
Hello experts,
Iu2019m writing a report program and after pulling data from a custom table Iu2019m modifying certain fields within internal table and then eventually update custom table. The way Iu2019m updating custom table is working fine. However Iu2019m concern about performance issues because Iu2019m doing update on custom table within loop.
Here is my code for reference.
*& Form update_contracts
text
--> p1 text
<-- p2 text
FORM update_contracts .
Update record in an internal table first
loop at izsc_compliance into wa_zsc_compliance..
wa_zsc_compliance-zapproval = c_accepted.
wa_zsc_compliance-CHANGED_DT = sy-datum.
wa_zsc_compliance-CHANGED_TM = sy-uzeit.
wa_zsc_compliance-CHANGED_BY = sy-uname.
modify izsc_compliance from wa_zsc_compliance index sy-tabix.
write:/ sy-tabix, wa_zsc_compliance-vbeln_new, wa_zsc_compliance-zapproval.
if p_test is initial.
move wa_zsc_compliance to zsc_compliance.
update zsc_compliance.
endif..
endloop.
Write records to database
if p_test = 'X'.
skip.
write:/ 'Test mode'.
endif.
ENDFORM. " update_contracts
Iu2019m not certain if there is any better way by not doing update within loop and update custom table outside this loop.
Many thanks in advance.Hi,
Yes, there is a better way to update the custom table. That will be more performance oriented and will be a much cleaner approach. As, I am not much aware of the custom table structure which you have in your program, the best way that I can suggest is to remove the update statement from that check. I guess you are checking against the mode - test or production. Once you have done the check, put the selected entries in an internal table which is same as database table. And then in a single command - a single array operation as it is commonly called, you can update the custom table.
Have a look at the following link
[Overwriting Several Lines Using an Internal Table|http://help.sap.com/saphelp_bw33/helpdata/en/fc/eb3a94358411d1829f0000e829fbfe/content.htm]
[Inserting or Changing Lines|http://help.sap.com/saphelp_bw33/helpdata/en/fc/eb3ac8358411d1829f0000e829fbfe/content.htm]
You can also scan the forum for multiple links and references and sample examples.
Hope this will help. The above approach will be much more performance oriented and will help to optimize. Also, check where exactly you are providing the locking feature if at applicable in your business functionality.
Regards,
Samantak. -
What's the best way to update my Mac with the latest version of Adobe Flash Player?
I've been getting prompts whenever I look at certain websites to download the latest version of Adobe Flash Player. I'm skeptical as to responding to those prompts. What is the best way to update my Mac Pro with the latest version of Adobe Flash Player?
You might also want to consider uninstalling Adobe Flash... I currently don't have it installed and haven't needed to install it. Most websites are now coded in HTML 5 so that the iOS devices can actually visit them. I can still watch YouTube videos et al. About the only thing I can't do is play Flash games... but they're a resource hog anyways.
Try going without for a day or two and see just how many sites you visit no longer require it. A lot of people keep it installed out of habit, not out of necessity. If you have Flash installed, visit a site and it's out of date, it will tell you to update your Flash. What it won't do is tell you is that had Flash not been installed, it would have used the HTML 5 code instead. Think about it... if an iOS device can't run Flash at all... it can't visit this site if it were written only to use Flash. What site would eliminate such a huge portion of their market base? You'd be surprised at how many sites use HTML 5. Uninstall Flash and see for yourself. -
Best Way To Update Intersection Tables
Hi,
I'm surprised I haven't been able to find anything on this,
but I was wondering if I could get some advice as to the most
efficient way to update an intersection table, i.e. a M:N
resolution table.
My example...
Say I have a M:N relationship between tables Cars and Colors.
To resolve, I form table Cars_Colors with Car_ID and Color_ID as
PFK's from their respective table.
So on my form, say we're dealing with record "Ford Ranger,"
I'll have a bunch of checkboxes with colors, in which multiple
colors can be selected or de-selected. How should I handle this
update?
Currently, I just delete all the existing colors for the
specific car, and then re-add the list of colors from the form...
basically a delete then insert on the table... I don't use any
update sql. But this is a nightmare when trying to keep audit
history on data changes in the table.
Any advice? Thanks in advance,
MarkThanks everyone for your help. Your code samples gave me the
start to to get this working by using CF code that produced the
following query in Oracle 8i:
INSERT INTO Cars_Colors (Car_ID, Color_ID)
SELECT 2, AA.iNewColorID
FROM
SELECT 1 AS iNewColorID FROM dual UNION
SELECT 2 AS iNewColorID FROM dual UNION
SELECT 4 AS iNewColorID FROM dual
) AA
WHERE AA.iNewColorID not in (
select color_id from cars_colors where car_id =2
) -
Best Way to Update datbase table
Hi, I got a customer table ZTEST , and a internal table iTAB with same structure as ZTEST.
Currently there is 3 record for example.
Record 1: AAA, BBB, CCC
Record 2: DDD, EEE, FFFF
Record 3: GGG, HHH, III
At beginning of program iTAB is populated from ZTEST, so iTAB get the same 3 records as ZTEST. Then,
iTAB will possilbe get more new records/modify some old recrds/delete some old records, now iTAB is, for example.
Record 1: AAA, BBB, DDD (Changed)
Record 2: DDD, EEE, FFFF (no change)
Record 3: JJJ, KKK, LLL (new record, and the record GGG,HHH, III has been deleted)
So, now I'd the like to make same update tabel ZTEST to make it consistent with iTAB .
Is there any easier / quicker way to do this (combined with INSERT / DELETE / UPDATE)?
Thanks in advancedLeo,
At the beging of the program you are extractibng the records from ztest to itab.
DELETE ZTEST FROM TABLE ITAB.
After your changes .
INSERT ZTEST FROM TABLE itab.
Pls. mark if useful. -
Best way to to display tables with a select drop down
I have created many SQL query report portlets, but I need a way for the users to select a specific acct nbr in a drop down list and then update a table on the same page. What is the best way to do this? I had created a Frame Driver, but I can not find a way to publish it to a page. Any ideas would be great, thanks.
Hi,
You can use a form based on table to do this. Build the form and publish it on the same page. The form can have a combination of various form items like textbox, textarea and drop down list etc. The form allows to query on the table and update the table.
Thanks,
Sharmila -
What is the best way to update /101 Total Gross YTD values within CRT
Hello - Can someone please suggest the best way that I can update the current /101 YTD values within the CRT? We had a conversion effort take place earlier in the year that did not accumulate the amounts of one particular wage type to the /101 bucket. The wage type itself is currently in the CRT with the appropriate accumulators set up correctly but the /101 YTD values are too low due to the missing amounts. Any suggestions would be greatly appreciated.
Thanks!Hello Kristy,
Did you try RPUCRT00? This program is for Recreation of Payroll Cumulation tables and might help in this case.
Hopefully this information helps.
Kind regards,
Graziela Dondoni -
Best way to reuse a layout with different values?
I want to reuse the code of the <div id="placeInfo"> on the next page (place.xhtml). I simplified it's code for this question.
Of course I can use <ui:include> for <div id="placeInfo"> but on the next page I would need e.g. #{myBean.selectedPlace.name} instead of #{place.name}.
Any smart idea how to do this efficiently?
<ui:repeat value="#{myBean.places}" var="place">
<p:commandLink action="place?faces-redirect=true" ajax="false">
<f:setPropertyActionListener value="#{place}" target="#{myBean.selectedPlace}" />
<div id="placeInfo">
#{place.name}
#{place.openHours}
</div>
</p:commandLink>
</ui:repeat>Research composite components. Its a little cumbersome to do these things in jsf to be honest. I just copypaste the xhtml content most of the times. Its not like it will save you time to turn this into a reusable component.
-
Updating a table with billion rows
It was an interview question, what's the best way to update a table with 10 billion rows. Give me your suggestions. Thanks in advance.
svkThe best way to answer questions such as this is NOT with a absolute and specific answer. Instead, discuss your strategy for approaching the problem. The first step is to understand your exact requirement. It is surprising how often people
write update statements with an under-qualified where clause. NEVER update a row that does not need to be updated. For example, a statement like:
update mytable set cola = 'ABC' where id in (1, 45, 212);
Assuming id is unique for the table and the specified values exist in the table, we know 3 rows will be updated. Do all of those rows need to be updated? Think about it. If cola is already set to 'ABC' for any of those rows, we could ignore
those rows and make the update more efficient. To do that, you need to add "and cola <> 'ABC' " to the where clause. That is just one example of understanding exactly what you need to do - and doing only that which needs to be done.
Once you understand exactly what you need to do, you need to analyze the impact of the update and identify any potential issues. Updating a lot of rows can take a lot of time and consume large amounts of log and disk space. What else is using
the table? Can you afford to lock the table for the duration of the update? Are there concurrency issues, regardless of whether you update in batches or in one single statement? When using a batch approach, is there an issue if someone runs
a query against the table (i.e., the result is different from that of the same query run after all updates have been completed)? Are you changing something which is included in an index? Are you changing part of the clustered index?
Ultimately, every question you are asked is (or should be) designed to test your problem-solving skills and your skillset. IMO, it is relatively easy to improve your skillset of any particular tool, language, or environment. The other - not so much
and that is why they are more valuable IMO. -
Best way to update a PRA file with changes to P6 schedule?
Hello,
I've spent some time looking at user manuals and video tutorials to try and become familiar with how to use Primavera Risk Analysis. I come from an @RISK user background so there were some concepts that were a little different between the two applications.
One thing of particular interest to my company is how to use PRA with a constantly evolving and updating P6 project schedule? I know there are ways to import/export user defined fields to store the min/most likely/max values for each task. I also know that the risk register can be imported/exported from Excel. My concern can perhaps be demonstrated by this example (based on my current understanding of PRA and P6)
1. Start PRA and import a copy of a P6 schedule. This is not a "live" link but rather a copy made for use with PRA.
2. Set-up the risk register, link to project tasks. Set-up activity min/most likely/max, assign to a distribution (triangle)
3. Run Monte Carlo simulations, review results etc.
4. At this point I could export the min/most likely/max durations back to P6 as user defined fields and I could update the duration in P6 with the most likely. I'm not sure what would happen with risk activities that created new project activities but I assume they would import as new tasks to P6?
After going through steps 1-4, the P6 schedule might continue to evolve further with new tasks, new dependencies, new durations, etc. At some point, I may be asked again to perform another risk analysis on the project and here is where my question comes in: Do I have to start all over and import everything into a new PRA? I know that I could get the min/max most likely from P6 user defined fields, I know I could import the risk register from Excel but are there other things that I would lose by having to start over (for example, links between risks in the risk register and the tasks in the P6 schedule?) Or... is there a way to re-use an existing PRA file and update the P6 schedule while preserving the info (like risk register, etc.)?
Thank you for your reply>
This method works but is there an easier (faster) way to update another table with new data only?
>
Almost anything would be better than that slow-by-slow loop processing.
You don't need a procedure you should just use MERGE for that. See the examples in the MERGE section of the SQL Language doc
http://docs.oracle.com/cd/B28359_01/server.111/b28286/statements_9016.htm
MERGE INTO bonuses D
USING (SELECT employee_id, salary, department_id FROM employees
WHERE department_id = 80) S
ON (D.employee_id = S.employee_id)
WHEN MATCHED THEN UPDATE SET D.bonus = D.bonus + S.salary*.01
DELETE WHERE (S.salary > 8000)
WHEN NOT MATCHED THEN INSERT (D.employee_id, D.bonus)
VALUES (S.employee_id, S.salary*.01)
WHERE (S.salary <= 8000); -
Best way to calculate maximum of many columns/values per row
Hello,
for a new report with some joined tables I have to calculate the last change date. Since every table has a creation and a (last) modification date, I need to get the maximum value from 8 columns to display it.
Of course I can compare all values by pairs or create a PL/SQL function. But maybe there already exists a fast and easy way to gain this date?
My query so far. Each of the tables has a cr_date and mod_date column:
SELECT
egvg.baugruppe_nummer || egvg.anlagennummer || egvg.geraetenummer AS systemnummer
, '=' || egvg.baugruppe_nummer || egvg.anlagennummer || egvg.geraetenummer AS systemnr2
, egvg.gebrauchsname AS gebrauchsname
, NVL2(egvr.raumkode, '+' || egvr.raumkode, NULL) AS raumkode
, egvg.lieferant AS lieferant
, CASE egvgs.kabelanschluss WHEN 1 THEN 'ja' WHEN 0 THEN 'nein' ELSE NULL END AS kabelanschluss
, egvges.nennleistung_kva AS nennleistung
, NULL AS letzte_aenderung
, CASE WHEN egvg.status_id = -1 THEN 'GERÄT GELÖSCHT' WHEN egvges.status_id = -1 THEN 'EDATEN GELÖSCHT' ELSE NULL END AS status
FROM
egv_geraete egvg
LEFT JOIN egv_geraetestamm egvgs ON egvgs.id = egvg.geraetestamm_id
LEFT JOIN egv_geraetestamm_edatenstamm egvges ON egvges.geraetestamm_id = egvgs.id
LEFT JOIN egv_raeume egvr ON egvr.id = egvg.raum_id
LEFT JOIN egv_edaten_sfp egvsfp ON egvsfp.id = egvges.sfp_idThank you,
Stefan>
This method works but is there an easier (faster) way to update another table with new data only?
>
Almost anything would be better than that slow-by-slow loop processing.
You don't need a procedure you should just use MERGE for that. See the examples in the MERGE section of the SQL Language doc
http://docs.oracle.com/cd/B28359_01/server.111/b28286/statements_9016.htm
MERGE INTO bonuses D
USING (SELECT employee_id, salary, department_id FROM employees
WHERE department_id = 80) S
ON (D.employee_id = S.employee_id)
WHEN MATCHED THEN UPDATE SET D.bonus = D.bonus + S.salary*.01
DELETE WHERE (S.salary > 8000)
WHEN NOT MATCHED THEN INSERT (D.employee_id, D.bonus)
VALUES (S.employee_id, S.salary*.01)
WHERE (S.salary <= 8000); -
Best way to update individual rows of a Table?
I've taken a look at some examples, though haven't gotten any clarification on this. I am looking to have something close to a listbox or table to where I can update just a single column of row values at a 1 time per second pace. I am looking to display our data-acquisition values in a table or listbox. The single listbox seemed to work good for this, but I was unable to use row headers to list the channel names next to the channel values. I was thinking about connecting the cursor values of two list-boxes to do this, but didn't find any info on this for the single list-box.
I have a few questions:
1) I have a 1D array to where I want to use that array of data to constantly update the first column (with a multitude of rows) of a table. I am looking for the best route so as not to take up too much processing time in doing this.
What is the best way to update individual rows of a table? Invoke Node "Set Cell Value" ... or is there another method?
2) Why is it that after every other iteration the row values are erased?
Also, for adding additional strings to the original arrray ... is it best to use the "Array Subset" and then the "Build Array" function, or the "Array Subset" and "Insert Into Array" function?
See the attached example.
Thanks.
Solved!
Go to Solution.
Attachments:
Table Example.vi 19 KBJeff·Þ·Bohrer wrote:
2) Why is it that after every other iteration the row values are erased?
Classic race condition. dump the for loop and p-node and just wire the 2D array to the table terminal.!
I'm not seeing the race condition. What I am seeing is the table emptying after the last element was written to it on every other run. I saw watched this with highlight execution on.
But I'm in full agreement with just writing to the terminal. It is a 1D array, so you will need to use a build array and transpose 2D array in order for it to write properly.
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines -
I have an iPhone 4 with iOS 5.1. What is the best way to update my phone to the latest iOS platform?
you can update over the air with strong wireless signal, or by connecting to a computer running iTunes. Either works well. If you do the update over the air, be sure and attach your iPhone to a wall outlet so you have a solid power supply and don't risk the battery dying during the update.
The iTunes approach installs a much larger file because of the connection, but if you have not updated since 5.1 that might be a better approach...replace the entire operating system instead of patching.
Either way, backup the iPhone yourself just for your own protection in the off-chance something should go wrong...a little paranoia while updating is a good thing -
URGENT update a table with a text that has a single quote in it
Hello, I am trying to update a table with a text that has a single quote in it. I believe I need to use two singles quotes but I am not sure how.
For example:
UPDATE TEST
SET DESCRLONG='Aux fins d'exportations'
WHERE etc...
Should I put 2 singles quotes before the quote in the text?
UPDATE TEST
SET DESCRLONG='Aux fins d'''exportations'
WHERE etc...
Thank you very much :)The best way depends on the version of Oracle.
But, the quick and universal answer is to use two single quotes
SQL> connect test/test
Connected.
SQL> create table test (descrlong varchar2(128));
Table created.
SQL> insert into test values ('This is a string with a '' single quote');
1 row created.
SQL> select * from test;
DESCRLONG
This is a string with a ' single quote
SQL> update test set descrlong='Aux fins d''exportations'
2 where descrlong like 'T%';
1 row updated.
SQL> select * from test;
DESCRLONG
Aux fins d'exportations
SQL>
Maybe you are looking for
-
Hi, Am getting the below error in my wls console . please help how to resolve this. <Mar 20, 2012 2:44:38 AM PDT> <Warning> <JDBC> <BEA-001129> <Received exception while creating connection for pool "WebCenter-CustomPortalDS": IO Error: The Network A
-
my i phone 5c wont stop restarting!! sometimes it takes hours before the phone starts working again. Sometimes when it does this red lines go up and down the screen. Im so ready to go back to my 4s does anyone know how to fix this??? Should i mention
-
Can I upgrade my iPad 1 to the ios5, and can I upgrade my snowleapord to mountain lion on my Mac book pro so that I can icloud my iPad, Mac book and iPhone 4s.pls help
-
Infoobject 0doc_number not activating
Hi guru's could any one tell me how to activate 0doc_number , which is there in business content,i hv been treing to active in diff ways , but still i could not , plz tell me what could be the problem, how i can activate it thank u hari
-
Clear the field INFOUPDATE and UNLIMITED in Purchasing Order
Hi experts, I have a request to clear the 2 fields Infoupdate and Unlimited in the Purchasing Order. I understand that this can be done in the customizing. However I need to have some condition which the customizing cannot be fulfiled. For example, t