To update a record using rowid in duplicate row.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ganesh raj
    New Member
    • Mar 2008
    • 9

    To update a record using rowid in duplicate row.

    Hi,

    want to write an plsql code to update a single record using rowid where all the rows are duplicated could someone help me in this case.

    Prod_service_id Location feature ord
    ----------------------- ------------ ---------- ----
    PP23456 Chennai Fast2 B77
    PP23456 Chennai Fast2 B77

    Now I need to update one of the record to madurai.


    Thanks,
    Ganesh
  • chaarmann
    Recognized Expert Contributor
    • Nov 2007
    • 785

    #2
    update our_table
    set Location = 'madurai'
    WHERE rowid in
    (SELECT MIN(rowid)
    FROM our_table
    GROUP BY Prod_service_id , Location, feature, ord);

    Originally posted by ganesh raj
    Hi,

    want to write an plsql code to update a single record using rowid where all the rows are duplicated could someone help me in this case.

    Prod_service_id Location feature ord
    ----------------------- ------------ ---------- ----
    PP23456 Chennai Fast2 B77
    PP23456 Chennai Fast2 B77

    Now I need to update one of the record to madurai.


    Thanks,
    Ganesh

    Comment

    • ganesh raj
      New Member
      • Mar 2008
      • 9

      #3
      Thanks thats Perfect.....
      Is there any way to store the rowid before updating.
      Please guide me to get through the issue.

      Comment

      • amitpatel66
        Recognized Expert Top Contributor
        • Mar 2007
        • 2358

        #4
        Originally posted by ganesh raj
        Thanks thats Perfect.....
        Is there any way to store the rowid before updating.
        Please guide me to get through the issue.
        Could you please let us know if you would like to store the record that is getting updated in to some log table or something?

        Comment

        • ganesh raj
          New Member
          • Mar 2008
          • 9

          #5
          Yes we have to store the record in log table. Please clarify me.

          Comment

          • amitpatel66
            Recognized Expert Top Contributor
            • Mar 2007
            • 2358

            #6
            Originally posted by ganesh raj
            Yes we have to store the record in log table. Please clarify me.
            Create a trigger, before update on table1, take the old data and insert into a log table.

            Comment

            • ganesh raj
              New Member
              • Mar 2008
              • 9

              #7
              I tried creating but the result does not getting updated could you please help me out.

              Comment

              • amitpatel66
                Recognized Expert Top Contributor
                • Mar 2007
                • 2358

                #8
                Originally posted by ganesh raj
                I tried creating but the result does not getting updated could you please help me out.

                Could you please post what you tried for?

                Comment

                • ganesh raj
                  New Member
                  • Mar 2008
                  • 9

                  #9
                  Thanks its working now one more thing is that I have many columns and in that I want to access an single record with unique id and cut the first two letters using the number in the query is it possible.

                  eg:
                  emp_id
                  ----------
                  ABssCC123

                  I tried the below logic but its not working...
                  Trim(to_char(em p_id, 'A%'),2)

                  Comment

                  • amitpatel66
                    Recognized Expert Top Contributor
                    • Mar 2007
                    • 2358

                    #10
                    Originally posted by ganesh raj
                    Thanks its working now one more thing is that I have many columns and in that I want to access an single record with unique id and cut the first two letters using the number in the query is it possible.

                    eg:
                    emp_id
                    ----------
                    ABssCC123

                    I tried the below logic but its not working...
                    Trim(to_char(em p_id, 'A%'),2)
                    Try this Query:

                    [code=oracle]

                    SELECT SUBSTR('ABccSS1 23', 1,2) FROM dual;

                    SUBSTR('ABCCSS1 23',1,2)
                    ------------------------------------------
                    AB

                    [/code]

                    Comment

                    • ganesh raj
                      New Member
                      • Mar 2008
                      • 9

                      #11
                      This is the code Iam using in plsql where the emp_svce_id (employee service id) has to be printed which is CCDB00123. I want to cut the first two character and store DB00123 below is the script Iam trying can you please help me....
                      [code=oracle]

                      declare
                      a employee_master .emp_svce_id%ty pe;
                      b employee_master .emp_svce_id%ty pe;
                      begin
                      a:='&emp_svce_i d';
                      select emp_svce_id into a from employee_master where emp_code ='PRODCD';
                      dbms_output.put _line('The a is'||a); // prints CCDB00123
                      select substr('a',1,2) into b from employee_master where emp_code ='PRODCD';
                      dbms_output.put _line('b is'||b); // prints only a [ need DB00123 ]
                      end;
                      [/code]
                      Last edited by amitpatel66; Mar 28 '08, 10:09 AM. Reason: code tags

                      Comment

                      • amitpatel66
                        Recognized Expert Top Contributor
                        • Mar 2007
                        • 2358

                        #12
                        Try This:

                        [code=oracle]
                        DECLARE
                        --a employee_master .emp_svce_id%TY PE;
                        b employee_master .emp_svce_id%TY PE;
                        BEGIN
                        --a:='&emp_svce_i d';
                        --SELECT emp_svce_id INTO a FROM employee_master WHERE emp_code ='PRODCD';
                        --dbms_output.put _line('The a is'||a); // prints CCDB00123
                        SELECT SUBSTR(emp_svce _id,3) INTO b FROM employee_master WHERE emp_code ='PRODCD'; -- this will give you DB00123 in variable b
                        dbms_output.put _line('b is'||b); -- prints only a [ need DB00123 ]
                        END;
                        [/code]

                        NOTE: The single line Comment in PLSQL is -- and not //
                        Last edited by amitpatel66; Mar 28 '08, 10:13 AM. Reason: Removed Unnecessary use of variable a

                        Comment

                        • ganesh raj
                          New Member
                          • Mar 2008
                          • 9

                          #13
                          The mistake I did is passed 'a' instead of giving a. Thanks for guiding me...
                          Have a nice weekend..

                          Comment

                          • amitpatel66
                            Recognized Expert Top Contributor
                            • Mar 2007
                            • 2358

                            #14
                            Originally posted by ganesh raj
                            The mistake I did is passed 'a' instead of giving a. Thanks for guiding me...
                            Have a nice weekend..
                            Thats right. And the use of vairalbe a was not required as it will occupy space for no reason. The sample code that i have shown you is the ideal way.

                            Comment

                            • ganesh raj
                              New Member
                              • Mar 2008
                              • 9

                              #15
                              Here a is the unique id and this should be entered by the user so Iam using this and now one more thing is that I want to update the emp_value and for the particular emp_svce_id with the result from the below query

                              SELECT SUBSTR(emp_svce _id,3) INTO b FROM employee_master WHERE emp_code ='PRODCD'and emp_svce_id=a;

                              And want to print the emp_value and emp_code; will it be possible below is what I tried.
                              [code=oracle]

                              DECLARE
                              a employee_master .emp_svce_id%TY PE;
                              b employee_master .emp_svce_id%TY PE;
                              c product_feature _instance.featu re_code%type;
                              d product_feature _instance.featu re_value%type;
                              e product_feature _instance.featu re_value%type;
                              BEGIN
                              a:='&emp_svce_i d';
                              SELECT SUBSTR(emp_svce _id,3,10) INTO b FROM employee_master WHERE emp_code ='PRODCD'and emp_svce_id=a;
                              dbms_output.put _line('b is'||b);
                              e:=b;
                              update employee_master set emp_value =e where prod_svce_id =a and emp_code ='PRODCD' and order_line_func tion ='RG';
                              select emp_code, emp_value into c,d from employee_master where emp_svce_id =a and emp_code ='PRODCD' and order_line_func tion ='RG';
                              dbms_output.put _line('emp_code '||c||'emp_valu e'||d);
                              commit;
                              end;
                              [/code]
                              Last edited by amitpatel66; Mar 28 '08, 12:44 PM. Reason: code tags

                              Comment

                              Working...