Update a column for a subset of data
Hi all,
I hope you can help me with some suggestions in how to solve the issue i have for the table below
SQL> select * from table1;
NAME ID CONCAT SAME_GR
A 10 100|200|300
B 11 100|200|300
C 12 100|200
D 10 100|200|300
SQL> What i need to do is to flag the rows which have the same ID & Concat value by updating the same_gr column with the same value, something like
SQL> select * from table1;
NAME ID CONCAT SAME_GR
A 10 100|200|300 GR1
B 11 100|200|300 GR2
C 12 100|200 GR3
D 10 100|200|300 GR1
SQL> One important note is that the value in SAME_GR column should have the form of GR<sequence>
I've been trying to use lag/lead functions but i can't succeed in updating the column with the same value for each group of rows where ID & CONCAT are the same.
I forgot to mention i'm on 11gR1.
Any help is very much appreciated.
Cheers,
Dani
Edited by: DanyC on Jun 18, 2010 10:40 AM
yes, you can.. all you need to do add is sum operation. after dense_Rank column sepecify + 254 and thus it will add up the value with dense rank output.
sample run...
PRAZY@11gR2> select ename,dense_rank() over (partition by deptno order by empno) from emp;
ENAME DENSE_RANK()OVER(PARTITIONBYDEPTNOORDERBYEMPNO)
CLARK 1
KING 2
MILLER 3
SMITH 1
JONES 2
SCOTT 3
ADAMS 4
FORD 5
ALLEN 1
WARD 2
MARTIN 3
BLAKE 4
TURNER 5
JAMES 6
14 rows selected.
Elapsed: 00:00:00.13
PRAZY@11gR2> select ename,dense_rank() over (partition by deptno order by empno)+300 from emp;
ENAME DENSE_RANK()OVER(PARTITIONBYDEPTNOORDERBYEMPNO)+300
CLARK 301
KING 302
MILLER 303
SMITH 301
JONES 302
SCOTT 303
ADAMS 304
FORD 305
ALLEN 301
WARD 302
MARTIN 303
BLAKE 304
TURNER 305
JAMES 306
14 rows selected.
Elapsed: 00:00:00.01Regards,
Prazy
Similar Messages
-
ADF Mobile updating a column for all the rows
Hi Every one,
This is My ADFMobile Usecase:
In My use case, I created DB Webservices and created a datContol on it .
I have few AMX pages in my Taskflow.
1st page: Authentication page with userid and p/w.
2nd page:Need to get DeptID as LOV and a submit button.
3rd Page:Need to get all Employees in that Department. Need to get Empl_name, Empl_Id, Empl_salary and Empl_ Attendence. and a SYNC Button.
Up to now every thing is fine.
But I need to change Empl_Attendence Column As absent or Present . I used SelectOneChoice. Default there will be PRESENT value in back end.So after Selecting SlectOneChoice the value (Absent) should Automatically update in DB for that row.
Requirement:
So How to write logic for the SYNC button to update the Empl_ Attendence for all the rows at a time.
Thanks In Advance
Regards
Varma.Hi Every one,
This is My ADFMobile Usecase:
In My use case, I created DB Webservices and created a datContol on it .
I have few AMX pages in my Taskflow.
1st page: Authentication page with userid and p/w.
2nd page:Need to get DeptID as LOV and a submit button.
3rd Page:Need to get all Employees in that Department. Need to get Empl_name, Empl_Id, Empl_salary and Empl_ Attendence. and a SYNC Button.
Up to now every thing is fine.
But I need to change Empl_Attendence Column As absent or Present . I used SelectOneChoice. Default there will be PRESENT value in back end.So after Selecting SlectOneChoice the value (Absent) should Automatically update in DB for that row.
Requirement:
So How to write logic for the SYNC button to update the Empl_ Attendence for all the rows at a time.
Thanks In Advance
Regards
Varma. -
Help needed in PL/SQL for updating the column for multiple records
Hi,
I am new to PL/SQL and need some help. What is the most effiecient way to update some field in a table as I may need to update thousands of records. I have a coulmn groupid can have multiple records tied to it. All the records attached to some groupid have a priority field also.
How can I update the prorityfield value for all the groupids in a profiecient way. Here is a sample data
GroupId Priority
1 1
1 2
1 3
1 4
1 5
2 1
2 2
2 3
3 1Here I have three groups 1, 2, 3. Now if any group contains only one record the priority remains same e.g. groupid=3 on top. If any group contains more than one record e.g. groupid=1 & 2 I want to re-arrange the priority fields e.g. If I want to update groupid=1 now if I change the priority of 2 to 5 (make it the last) I want to rearrange the remaing records priority i.e. if 2 becomes 5 as I have 5 rows for groupid=1 then 5 becomes 4, 4 becomes 3, 3 becomes 2 and 1 remains the same.
Same wya if I want to make the priority 1 to 3 for groupid=2 then need 2 to become 1 and 3 to become 2 etc....
Any help is appreciated.
ThanksHi,
You don't need PL/SQL to do this (though you can put the following in PL/SQL if you want to):
UPDATE table_x
SET priority = CASE
WHEN groupid = 1
AND priority = 2
THEN 5
WHEN groupod = 1
AND priority BETWEEN 3 AND 5
THEN priority - 1
WHEN groupid = 2
THEN
CASE
WHEN prioity = 1
THEN 3
ELSE priority - 1
END
END
WHERE groupId IN (1, 2)
AND ( priority BETWEEN 2 AND 5
OR groupid = 2
);There are lots of different techniques that can reduce your coidng: for example, the nested CASE statement used for groupid=2 above.
You could do several smaller UPDATEs (for example, one just for groupid=1). Execution will be slower, but coding and testing will be faster.
You could make the "magic numbers" 2 (for groupid=1) and 1 (for groupid=2) variables, even outside of PL/SQL.
If you need more help, post the information that Satyaki requested. -
How To Create Logical column For Lastyear To Till Date
Hi All,
I Have to calculate Lastyear to Till Date for Logical Column.
Ex:I have Time Dime and Fact column and Dimension columns.
jan 2011 to oct 2012.
Please Let me know.
Thanks,
AbhiLooks like you are not reading my messages
Since you are doing on logical columns getting this error.
Try this using physical columns then count from aggregate tab
CASE WHEN "Oracle Data Warehouse"."Catalog"."dbo"."Fact_W_SRVREQ_F_Open_Date"."OPEN_DT_WID" > 20110101 THEN "Oracle Data Warehouse"."Catalog"."dbo"."Fact_W_SRVREQ_F_Open_Date"."SR_WID" END
The same you can go with your variable
Or else the same can do by duplicating the existing Fact - CRM - Service Request"."# of SRs" and just add above code.
or just use the below you dont use sum since already aggregation is happend for # of SRs
CASE WHEN "Core"."Dim - Date"."Year" = VALUEOf("Warehouse Refresh Date Last Year"."CURRENT_CALENDAR_YEAR_LAST_YEAR") AND "Core"."Dim - Date"."Date" < VALUEOF("Warehouse Refresh Date Last Year"."LAST_REFRESH_DATE_LAST_YEAR") THEN "Core"."Fact - CRM - Service Request"."# of SRs" END
Hope this works, mark as correct -
Update a column for every 2000 records in the table
The table has 50,000 records. I want to update the process_id every 2000 rows. For example, 1 for the 1st 2000 rows, 2 for the next 2000 rows, 3 for the next 2000 rows, and etc. Is there a quick way to do it?
Thanks muchhey <[email protected]>
Two ways of doing this...
First: PL/SQL
By declaring a cursor on the table and using the cursor%rowcount method to update your field..something like this...
Declare
Begin
For rno in MyCursor
Loop
update <tablename> set process_id = lv_pid where rowid = rno.rowid
If mod(MyCur%rowcount,2000) = 0 then
lv_pid = lv_pid + 1;
End If;
End Loop;
End
I am sorry if u already knew this :-) !!
Second: SQL
let u know once (if)i crack it :-( !!
Goodluck...
Vasudev -
Need logic to update Varchar column in a table
Hi,
Could you give me logic for below.
I have a table xx_dbc where one of the column Attribute1 is varchar2(240).
Attribute1 has values like
==================
(AIN,PUP,GRI,NINE)
(AIN,PUP)
(AIN)
(GRI,NINE)
I have to update this column for every record with values AIN=10 , PUP=20 , GRI=30 , NINE=40
Columns should be updated like below
(10,20,30,40)
(10,20)
(10)
(30,40)
Thanks.Hi,
Here's one way:
WITH replacements AS
SELECT 'AIN' AS old_str, '10' AS new_str FROM dual UNION ALL
SELECT 'PUP', '20' FROM dual UNION ALL
SELECT 'GRI', '30' FROM dual UNION ALL
SELECT 'NINE', '40' FROM dual
, normalized_data AS
SELECT p_key
, LEVEL AS sort_key
, REGEXP_SUBSTR ( attribute1
, '[^(,)]+'
, 1
, LEVEL
) AS str
FROM xx_dbc
-- WHERE ... -- If you need any filtering, put it here
CONNECT BY LEVEL <= 1 + REGEXP_COUNT (attribute1, ',')
AND PRIOR p_key = p_key
AND PRIOR SYS_GUID () IS NOT NULL
SELECT '(' || LISTAGG ( NVL (r.new_str, n.str)
) WITHIN GROUP (ORDER BY sort_key)
|| ')' AS new_attribute1
, n.p_key -- If wanted
FROM normalized_data n
LEFT OUTER JOIN replacements r ON r.old_str = n.str
GROUP BY n.p_key
ORDER BY n.p_key
Like everything else, it depends on your Oracle version.
In the query above, p_key can be any unique key from xx_dbc, including attribute1 or ROWID.
Relational databases, like Oracle, work best when each column of each row contains only 1 piece of information, not a delimited list of any number of pieces. This is so fundamental to table design that it's called First Normal Form. Most of the work in this problem involves converting your denormalized data into First Normal Form, and then converting it back again. This problem, like many others, would be much simpler and more efficient if your table was in First Normal Form.
The query above assumes the replacement strings (such as 'AIN' and '10') are not already in a table. If they are, or if they can be derived from a table, then you don't need the replacements sub-query; use your real table instead. -
Update Flag Field for Same Day in a Given Month Every Year in a Flag Table.
Hi,
I am trying to formulate an update query for a flag table in our database which contains dates, and flag columns. Currently the system have dates for the next ten years. The flags are updated with values 0 or 1 if a particular date falls under the required criteria.
I need to update flag column for the same day of the month in every year. e.g. 2nd Sunday of October. The value should be updated to all years in the table. Currently I am using the following query to update the current year.
UPDATE FILTERCALENDAR SET YEAR_WINDOW=1 WHERE c_date = NEXT_DAY( TO_DATE('OCT-2013','MON-YYYY'), 'SUNDAY') + (2-1)*7;
and for next year Like
UPDATE FILTERCALENDAR SET YEAR_WINDOW=1 WHERE c_date = add_months(NEXT_DAY( TO_DATE('OCT-2013','MON-YYYY'), 'SUNDAY') + (2-1)*7,+12)-1;
This is not an excellent way to do it as it does not take care of leap years and it does not scan and update values in the whole table for all years correctly.
Can any one help me to resolve this please.
HamidchResolved by doing the following:
Just query the years from your table (list of distinct years) and use the above query on them.
SELECT DISTINCT TO_CHAR(c_date, 'yyyy') FROM FILTERCALENDAR
Or use this predicate
WHERE c_date = next_day(last_day(add_months (c_date, -1)), 'SUNDAY') + 7
AND TO_CHAR(c_date, 'mm') = '10' -
How can i update all column of table without know it's structure
hi to all
i want to make update to all columns of table with record type of this table
ex- consider the emp table and contain any number of columns
and you make record is row type of this table (emp) as emp_rec
and fech in it any record by select * from emp
and i want to update another record this the return record from data base as
update emp by using the emp_rec
i want to know how this will be acheiveIt is all written in the docs:
http://download-uk.oracle.com/docs/cd/B19306_01/appdev.102/b14261/collections.htm#i20479
Although updating all columns for a table is VERY, VERY BAD practice.
Gints Plivna
http://www.gplivna.eu -
Doubt about UPDATE STAT COLUMN
Hi,
I have a doubt of when to execute update stat:
i create this SQL to generate an SQL script to generate update stat for all my tables:
select 'UPDATE STAT ' || schemaname || '.' || tablename || ' ESTIMATE SAMPLE 20 PERCENT' from tables where schemaname = 'DBUSER' and not tablename like 'JDBC%' AND type = 'TABLE'
and created this SQL to generate an SQL script for update stat for all columns.
select 'UPDATE STAT COLUMN(*) FOR ' || schemaname || '.' || tablename || ' ESTIMATE SAMPLE 20 PERCENT' from tables where schemaname = 'DBUSER' and not tablename like 'JDBC%' AND type = 'TABLE'
my doubt is i really need run that second script? or the UPDATE STAT for table dont UPDATE STAT for all columns?
thanks for any insight
Clóvis> my doubt is i really need run that second script? or the UPDATE STAT for table dont UPDATE STAT for all columns?
Hi Clovis,
hmm... good question.
There are a few things to know about the UPDATE STAT command here.
1) It will always generate statistics for key or indexed columns.
2) The optimizer won't be able to generate a better plan when there are column statistics for non-indexed columns present.
3) The command will also collect column statistics for all columns that already have statistics.
The direct effect of 3) is that by running your second command just once - all column statistics will always be collected.
Since you can easily change the default sample size for your tables via
ALTER TABLE SAMPLE SIZE 20 PERCENT
I would say: drop your script and just use
UPDATE STAT DBUSER.* ESTIMATE
This single command would lead to the same statistics as your script does.
And if you really, really want to leave out the JDBC tables - then just set their default sample size to 0 and they will be ignored by the UPDATE STAT command.
regards,
Lars -
Received this error (The workflow could not update the item, possibly because one or more columns for the item require a different type of information.) recently on a workflow that was
working fine and no changes were made to the workflow.
I have tried a few suggestions, i.e. adding a pause before any ‘Update’ action (which didn’t help because the workflow past this action without incident); checked the data type being written
to the fields (the correct data types are being written); and we even checked the list schema to ensure the list names and the internal names are aligned (they
are), but we still cannot figure out why the workflow is still throwing this error.
We located the area within the workflow step where it is failing and we inserted a logging action to determine if the workflow would execute the logging action but it did not, but wrote the same error message.
The workflow is a Reusable Approval workflow designed in SharePoint Designer 2010 and attached to a content type.
The form associated with the list was modified in InfoPath 2010.
Approvers would provide their approval in the InfoPath form which is then read by the workflow.
Side note - items created after the workflow throws this Unknown Error some seem to be working fine.
We have deleted the item in question and re-added it with no effect.
Based on what we were able to determine there don’t seem to be any consistency with how this issue is behaving.
Any suggestions on how to further investigate this issue in order to find the root cause would be greatly appreciated?
CheersHi,
I understand that the reusable workflow doesn’t work properly now. Have you tried to remove the Update list item action to see whether the workflow can run without issue?
If the workflow runs perfectly when the Update list item action is removed, then you need to check whether there are errors in the update action. Check whether the values have been changed.
Thanks,
Entan Ming
Entan Ming
TechNet Community Support -
I got error "The workflow could not update the item, possibly because one or more columns for the item require a different type of information "I found out the cause is Update Item action
I need to update item in another List call Customer Report ,the field call "Issues" with data type "Choice" to yes
then the error arise . please help..Thanks for the quick response Nikhil.
Our SPF 2010 server is relatively small to many setups I am sure. The list with the issue only has 4456 items and there are a few associated lists, eg lookups, Tasks, etc see below for count.
Site Lists
Engagements = 4456 (Errors on this list, primary list for activity)
Tasks = 7711 (All workflow tasks from all site lists)
Clients = 4396 (Lookup from Engagements, Tslips, etc)
Workflow History = 584930 (I periodically run a cleanup on this and try to keep it under 400k)
Tslips = 3522 (Engagements list can create items here, but overall not much interaction between lists)
A few other lists that are used by workflows to lookup associations that are fairly static and under 50 items, eg "Parters Admin" used to lookup a partners executive admin to assign a task.
Stunpals - Disclaimer: This posting is provided "AS IS" with no warranties. -
Help! Update a column in LONG data type
I am looking for help on how to update a column with the long data type in a oracle 7.34 table on sun Solaris 2.6.:
SQL> desc searchengine;
Name Null? Type
ENGINE_ID NOT NULL NUMBER(38)
ENGINEHTML LONG
SQL> set long 10000
Then when I run the following update statement I always get the error
ERROR at line 1:
ORA-01489: result of string concatenation is too long
Here is the update statement:
SQL> update searchengine set enginehtml = '<FORM ACTION="../ndClickMe/pgSearchEng" METHOD="GET" target=_top><TR><TD COLSPAN=2>
<IMG SRC=/gifs/start/looksmart_websearch.gif width=85 height=25 ALIGN=BOTTOM BORDER=0><BR>
</TD></TR><TR><TD HEIGHT=20 VALIGN=TOP COLSPAN=2><INPUT TYPE=hidden NAME=URL VALUE=http://www.looksmart.com/r_search>
<input type=hidden name=search value=0><input type=hidden name=comefrom value="izbx-search">
<input type=hidden name=isp value=zbx><INPUT NAME=key SIZE="22"><br><center>
<INPUT TYPE="IMAGE" SRC=/gifs/start/search.gif WIDTH=53 HEIGHT=15 ALIGN=BOTTOM border=0 NAME=search
value="Search!"><br></center></TD></TR></FORM><FORM name="Go3"><tr><td>
<SELECT name="select" onChange="dropDown(document.Go3.select.options[Go3.select.selectedIndex].value);">
<option value="">...or select a category</option>
<option value="http://www.looksmart.com/eus1/eus53930/r?' | | '&' | | 'izbx' | | '&' | | 'comefrom=izbx-eus53930" target=_top>Automotive</option>
<option value="http://www.looksmart.com/eus1/eus65300/r?' | | '&' | | 'izbx' | | '&' | | 'comefrom=izbx-eus65300" target=_top>Business</option>
<option value="http://www.looksmart.com/eus1/eus151538/r?' | | '&' | | 'izbx' | | '&' | | 'comefrom=izbx-eus151538" target=_top>Chat</option>
<option value="http://www.looksmart.com/eus1/eus53832/r?' | | '&' | | 'izbx' | | '&' | | 'comefrom=izbx-eus53832" target=_top>Computing</option>
<option value="http://www.looksmart.com/eus1/eus52213/r?' | | '&' | | 'izbx' | | '&' | | 'comefrom=izbx-eus52213" target=_top>Entertainment</option>
<option value="http://www.looksmart.com/eus1/eus53671/r?' | | '&' | | 'izbx' | | '&' | | 'comefrom=izbx-eus53671" target=_top>Family</option>
<option value="http://www.looksmart.com/eus1/eus53940/r?' | | '&' | | 'izbx' | | '&' | | 'comefrom=izbx-eus53940" target=_top>Health</option>
<option value="http://www.looksmart.com/eus1/eus141561/r?' | | '&' | | 'izbx' | | '&' | | 'comefrom=izbx-eus141561" target=_top>Hobbies</option>
<option value="http://www.looksmart.com/eus1/eus53706/r?' | | '&' | | 'izbx' | | '&' | | 'comefrom=izbx-eus53706" target=_top>Reference</option>
<option value="http://www.looksmart.com/eus1/eus74544/r?' | | '&' | | 'izbx' | | '&' | | 'comefrom=izbx-eus74544" target=_top>Shopping</option>
<option value="http://www.looksmart.com/eus1/eus51605/r?' | | '&' | | 'izbx' | | '&' | | 'comefrom=izbx-eus51605" target=_top>Society</option>
<option value="http://www.looksmart.com/eus1/eus62704/r?' | | '&' | | 'izbx' | | '&' | | 'comefrom=izbx-eus62704" target=_top>Sports</option>
<option value="http://www.looksmart.com/eus1/eus62920/r?' | | '&' & #0124; | 'izbx' | | '&' | | 'comefrom=izbx-eus62920" target=_top>Travel</option>
</select><hr noshade size="1"></td></tr></form>' where engine_id = 0;
Is there any way to resolve it?
Thanks,
JudyYes Prathap, I need to update a single column of type number in the search results table.but each of that column value would be updated with different values like one row in that column will take a value 325 while another will take 500 etc based on user input.
Your help in this is very much appreciated, Thanks in advance ! -
My Apple ID was changed. It works fine on my IPad mini, my MAc and in Itunes Store, Yet when I try to update apps on my IPAD 1 I am asked to enter a password for the old ID user name which appears in the pop up window. When It still askes for the wrong ID data. I have uodated it in settings, and I have logged ontht the account to verify that it still works properly and it does. I reboot the IPAD and then attempt to update apps again but it still asked for the Old ID password and still shows the old ID username. The dame thing refuses to recognize my new Apple ID data. This is making my older IPAD unuseable.
You cannot change your Apple ID. You can get a new one if you want, but all of your Apps and media are linked to yoru old Apple ID. And no, Apple won't transfer your old ID purchases to yoru new ID.
-
i have an iphone 4, i connect it to my laptop using the usb and then when connecting to itunes it says my phone is not up to date with itunes yet i cannot find an update 11.1 for my phones itunes? someone please help me.. kind regards
Itunes 11.1 is for your computer, not your iphone
It is required in order to sync with ios 7. -
My 4th gen iPod touch says iOS 6.1.3 is the latest version of software. I've been updating it wirelessly for a while so I know that isn't the problem & I know I'm connected to the Internet; I typed & submitted it on my iPod. Please help/explain why it's doing this!
Also, my App Store also says I have an update but I don't. All my apps are up to date when I try to update... Why is that?That iPod touch model doesn't have enough RAM to run iOS 7.
(90990)
Maybe you are looking for
-
Hi all Could you please tell me which Account and Transaction Key when posting: Example: Goods Receipt for Purchase Order Dr Inventory Account (BSX) Cr GR/IR clearing Account (WRX) Could you please fill: Goods Issue for Se
-
Deselect after moving will delete content!
Hello! I have a huge problem with the selection tool and I need to know how to fix it because it totally destroys my workflow. (Photoshop CS6) If I move content of a selection and deselect a part, it will delete the part I deselected. How can I turn
-
hi i wrote a conenction class some time ago that used oracle's connection cache. this worked great, creating and releasing resources as required be it for jsp or a swing application. i am now trying to write a more generic connection pool class that
-
Cannot create additional Radio Button items
Hi. I am new to Appleworks database, so this my be a stupid question. When I try to add a field and define it as a radio button group, then try to customize the buttons via Options, it normally only shows 2 buttons "Item 1" and "Item 2". I can modify
-
I phone Music showing in Light Grey?
I've just SYNC my iPhone 4Gs. After doing so; in the music on the iPhone it is showing songs in Light Grey! I have re Sync the phone, restored and updated! But still no joy in removing the Light grey list. Any advice?