Home » SQL & PL/SQL » SQL & PL/SQL » Table Updates (Oracle 11g)
Table Updates [message #633602] Mon, 23 February 2015 01:14 Go to next message
Genesys
Messages: 45
Registered: August 2010
Member
Hi,

here the below scenario and I could not provide the table struc & data because im working in remote system.

table struc & data.

uid type partition
abc 1 need to update
abc 2 need to update
xyz 3 need to update
xyz 1 need to update
asd 3
asd 1
fgh 3
fgh 1

by using the group by we can get the below data

uid type partition
abc 3 ?
xyz 4 ?
asd 4 ?
fgh 4 ?

here we need to update the partition value. if the sum of the TYPE for ABC,XYZ value is <=10 then partition value is 1 ,if its >10 then next partition i.e 2

uid type partition
abc 3 1
xyz 4 1
asd 4 2
fgh 4 2

Thanks
Gen




Re: Table Updates [message #633603 is a reply to message #633602] Mon, 23 February 2015 01:17 Go to previous messageGo to next message
John Watson
Messages: 9005
Registered: January 2010
Location: Global Village
Senior Member
Is this another college homework question?

You can provide the table structures. You can use DESCRIBE to show them.
You can also enclose your code in [code] tags, as you have been asked many times.

[Updated on: Mon, 23 February 2015 01:17]

Report message to a moderator

Re: Table Updates [message #633604 is a reply to message #633603] Mon, 23 February 2015 01:24 Go to previous messageGo to next message
Genesys
Messages: 45
Registered: August 2010
Member
Hi,

either its not college home work or interview question.

As mentioned Im working in remotely.more over need some logic to display the data rather than the table describe

Thanks
Gen
Re: Table Updates [message #633605 is a reply to message #633604] Mon, 23 February 2015 01:26 Go to previous messageGo to next message
John Watson
Messages: 9005
Registered: January 2010
Location: Global Village
Senior Member
Perhaps someone else is prepared to assist someone so intransigent. My life is too short for that.
Goodbye.
Re: Table Updates [message #633606 is a reply to message #633602] Mon, 23 February 2015 01:30 Go to previous messageGo to next message
Michel Cadot
Messages: 68777
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator

As already told to you:

Please read OraFAQ Forum Guide and How to use [code] tags and make your code easier to read.
Make sure that lines of code do not exceed 80 characters when you format.
Indent the code, use code tags and align the columns in result.
Use the "Preview Message" or "Preview Quick Reply" button to verify.
Also always post your Oracle version, with 4 decimals.

With any SQL or PL/SQL question, please, Post a working Test case: create table (including all constraints) and insert statements along with the result you want with these data then we will be able work with your table and data. Explain with words and sentences the rules that lead to this result.

Re: Table Updates [message #633613 is a reply to message #633606] Mon, 23 February 2015 03:40 Go to previous messageGo to next message
Genesys
Messages: 45
Registered: August 2010
Member
CREATE TABLE uid
(
a VARCHAR2(10),
b NUMBER,
c NUMBER
);

INSERT INTO uid
(a,
b)
VALUES ('p1',
4);

INSERT INTO uid
(a,
b)
VALUES ('p2',
5);

INSERT INTO uid
(a,
b)
VALUES ('p3',
5);

INSERT INTO uid
(a,
b)
VALUES ('p4',
5);

INSERT INTO uid
(a,
b)
VALUES ('p5',
3);

INSERT INTO uid
(a,
b)
VALUES ('p6',
5);

Excepted O/p

a b c
p1 4 1
p2 5 1 4+5=9 <10 then 1
p3 5 2 9+5=14 >10 then 2, p3 b value is 5 now
p4 5 3 (p3)5+(p4)5=10 not < 10 then 3 ,p4 b value is 5
p5 3 3 5+3=8 <10 then 3
p6 4 4 8+4=12 >10 then 4

Hope this is clear

Thanks
Gen
Re: Table Updates [message #633614 is a reply to message #633613] Mon, 23 February 2015 03:44 Go to previous messageGo to next message
gazzag
Messages: 1119
Registered: November 2010
Location: Bedwas, UK
Senior Member
Did you miss the bit about [code] tags?
Re: Table Updates [message #633622 is a reply to message #633614] Mon, 23 February 2015 04:33 Go to previous messageGo to next message
Genesys
Messages: 45
Registered: August 2010
Member
any updates please ?
Re: Table Updates [message #633624 is a reply to message #633622] Mon, 23 February 2015 05:02 Go to previous messageGo to next message
Michel Cadot
Messages: 68777
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator

Quote:
p3 b value is 5 now


Why now, it was also 5 before?

Quote:
p4 b value is 5


So no change, why do you specify?
Is there some change sometimes?
Re: Table Updates [message #633626 is a reply to message #633624] Mon, 23 February 2015 05:10 Go to previous messageGo to next message
Genesys
Messages: 45
Registered: August 2010
Member
a b c
p1 4 1
p2 5 1 4+5=9 <10 then 1
p3 5 2 9+5=14 >10 then 2, p3 b value is 5 now
p4 5 3 (p3)5+(p4)5=10 not < 10 then 3 ,p4 b value is 5
p5 3 3 5+3=8 <10 then 3
p6 4 4 8+4=12 >10 then 4


in third row:

9+5=14 its >10 then need to increment the C value from 1 to 2.if any changes in C value will carry the corresponding B value to next row

any How,I got the solution my self by creating some bit of pl/sql block.

Thanks
Gen
Re: Table Updates [message #633629 is a reply to message #633626] Mon, 23 February 2015 06:54 Go to previous messageGo to next message
Michel Cadot
Messages: 68777
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator

1/ You still don't expain what means "p3 b value is 5 now"
2/ If you have a solution then post it, and post it formatted.

Re: Table Updates [message #633635 is a reply to message #633629] Mon, 23 February 2015 08:54 Go to previous messageGo to next message
Lalit Kumar B
Messages: 3174
Registered: May 2013
Location: World Wide on the Web
Senior Member
@OP,

Is this link broken for you?

[Updated on: Mon, 23 February 2015 08:56]

Report message to a moderator

Re: Table Updates [message #633640 is a reply to message #633613] Mon, 23 February 2015 10:44 Go to previous messageGo to next message
Solomon Yakobson
Messages: 3312
Registered: January 2010
Location: Connecticut, USA
Senior Member
First of all, UID is reserved word - you shouldn't be naming table UID. Anyway, MODEL solution:

select  a,
        b,
        c
  from  uid_tbl
  model
    dimension by(row_number() over(order by a) rn)
    measures(a,b,1 c,b s)
    rules(
          s[rn > 1] order by rn = case
                                    when nvl(s[cv() - 1],b[cv() - 1]) + b[cv()] >= 10 then null
                                    else nvl(s[cv() - 1],b[cv() - 1]) + b[cv()]
                                  end,
          c[rn > 1] order by rn = case
                                    when s[cv()] is null then c[cv() - 1] + 1
                                    else c[cv() - 1]
                                  end
         )
/

A                   B          C
---------- ---------- ----------
p1                  4          1
p2                  5          1
p3                  5          2
p4                  5          3
p5                  3          3
p6                  5          4

6 rows selected.

SQL> 


SY.
Re: Table Updates [message #633644 is a reply to message #633640] Mon, 23 February 2015 23:19 Go to previous messageGo to next message
Genesys
Messages: 45
Registered: August 2010
Member
Hi Solomon,

Thank you so much

Thanks
Gen
Re: Table Updates [message #633647 is a reply to message #633644] Tue, 24 February 2015 00:05 Go to previous messageGo to next message
Michel Cadot
Messages: 68777
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator

And what was your solution?
Or you just want we do your job but don't want to help others?

Re: Table Updates [message #633653 is a reply to message #633647] Tue, 24 February 2015 00:39 Go to previous message
Genesys
Messages: 45
Registered: August 2010
Member
 DECLARE
  a NUMBER:=0;
  p NUMBER:1;
BEGIN
  FOR i IN
  (SELECT   UID,
           SUM(b)cnt from uid_tbl group by uid)
  

LOOP a:=a+i.cnt;
  
  IF a<10 THEN
    UPDATE uid_tbl
    SET    c=p
    WHERE  UID=i.UID;
  
  ELSIF a>=10 THEN
    p:=p+1;
    UPDATE uid_tbl
    SET    c=p
    WHERE  UID=i.UID;
    
    a:=i.cnt;
  END IF;
END LOOP;
END; 
Previous Topic: How to delete data from all the tables with one Query?
Next Topic: PL/SQL for Insert/Update
Goto Forum:
  


Current Time: Fri Sep 04 15:04:41 CDT 2026