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
17 11978
update our_table
set Location = 'madurai'
WHERE rowid in
(SELECT MIN(rowid)
FROM our_table
GROUP BY Prod_service_id, Location, feature, ord);
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
Thanks thats Perfect.....
Is there any way to store the rowid before updating.
Please guide me to get through the issue.
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?
Yes we have to store the record in log table. Please clarify me.
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.
I tried creating but the result does not getting updated could you please help me out.
I tried creating but the result does not getting updated could you please help me out.
Could you please post what you tried for?
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(emp_id, 'A%'),2)
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(emp_id, 'A%'),2)
Try this Query: -
-
SELECT SUBSTR('ABccSS123', 1,2) FROM dual;
-
-
SUBSTR('ABCCSS123',1,2)
-
------------------------------------------
-
AB
-
-
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.... -
-
declare
-
a employee_master.emp_svce_id%type;
-
b employee_master.emp_svce_id%type;
-
begin
-
a:='&emp_svce_id';
-
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;
-
Try This: -
DECLARE
-
--a employee_master.emp_svce_id%TYPE;
-
b employee_master.emp_svce_id%TYPE;
-
BEGIN
-
--a:='&emp_svce_id';
-
--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;
-
NOTE: The single line Comment in PLSQL is -- and not //
The mistake I did is passed 'a' instead of giving a. Thanks for guiding me...
Have a nice weekend..
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.
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. -
-
DECLARE
-
a employee_master.emp_svce_id%TYPE;
-
b employee_master.emp_svce_id%TYPE;
-
c product_feature_instance.feature_code%type;
-
d product_feature_instance.feature_value%type;
-
e product_feature_instance.feature_value%type;
-
BEGIN
-
a:='&emp_svce_id';
-
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_function ='RG';
-
select emp_code, emp_value into c,d from employee_master where emp_svce_id =a and emp_code ='PRODCD' and order_line_function ='RG';
-
dbms_output.put_line('emp_code'||c||'emp_value'||d);
-
commit;
-
end;
-
Small modifications to your code: -
-
DECLARE
-
a employee_master.emp_svce_id%TYPE;
-
b employee_master.emp_svce_id%TYPE;
-
c product_feature_instance.feature_code%TYPE;
-
d product_feature_instance.feature_value%TYPE;
-
--e product_feature_instance.feature_value%TYPE;
-
BEGIN
-
a:='&emp_svce_id';
-
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);
-
UPDATE employee_master SET emp_value =b WHERE prod_svce_id =a AND emp_code ='PRODCD' AND order_line_function ='RG' RETURNING emp_code,emp_value INTO c,d; -- This will work in case if only one record gets updated. Else you will need to use array for the RETURNING values
-
COMMIT;
-
--SELECT emp_code, emp_value INTO c,d FROM employee_master WHERE emp_svce_id =a AND emp_code ='PRODCD' AND order_line_function ='RG';
-
dbms_output.put_line('emp_code'||c||'emp_value'||d );
-
END;
-
Its throwing error. The error details is given below.
Error details:
declare
*
ERROR at line 1:
ORA-12899: value too large for column
"SCOTT"."EMP_MASTER"."EMP_VALUE" (actual: 10, maximum: 7)
ORA-06512: at line 13
Try This: -
-
DECLARE
-
a employee_master.emp_svce_id%TYPE;
-
b employee_master.emp_svce_id%TYPE;
-
c employee_master.emp_code%TYPE;
-
d employee_master.emp_value%TYPE;
-
BEGIN
-
a:='&emp_svce_id';
-
SELECT SUBSTR(emp_svce_id,3) INTO b FROM employee_master WHERE emp_code ='PRODCD'AND emp_svce_id=a;
-
dbms_output.put_line('b is'||b);
-
UPDATE employee_master SET emp_value =b WHERE prod_svce_id =a AND emp_code ='PRODCD' AND order_line_function ='RG' RETURNING emp_code,emp_value INTO c,d; -- This will work in case if only one record gets updated. Else you will need to use array for the RETURNING values
-
COMMIT;
-
dbms_output.put_line('emp_code'||c||'emp_value'||d );
-
END;
-
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Sandy |
last post by:
I am trying to do the following:
EXEC SQL
UPDATE MY TABLE
SET COL1 = :newValue
WHERE COL1 = 0
AND ROWNUM = 1
ORDER BY COL2;
(index on COL1, COL2)
|
by: Robert |
last post by:
How can I query an existing table and update a field in each record in the
table with the occurrence count of each record e.g. update field to 1 (=
first record occurrence), update field to 2 for...
|
by: Doug |
last post by:
I've got a strongly-typed dataset with 2 related tables in it ("Staff"
and "Roles"). I want to make a change to the parent Staff row and also
to its child Role row. I'm having difficulty figuring...
|
by: Louis LeBlanc |
last post by:
Hey folks. I'm new to the list, and not quite what you'd call a DB
Guru, so please be patient with me. I'm afraid the lead up here is a
bit verbose . . .
I am working on an application that...
|
by: Altemir |
last post by:
I want to create an UPDATE statement that updates a value in a table in
database A based on the results of an inner join between tables each
residing in deifferent databases.
What is the correct...
|
by: MLH |
last post by:
Fields in MyTable:
PostID
PostDate
RollQtyXfer
RollDenomination
RollCount37
RollCount23
|
by: FangQ |
last post by:
hi
I am very new to mysql. I have a question about using the "on duplicate
update" clause with insert command.
my table "data" has two columns, field1 and field2, where field1 is the
index...
|
by: Steve Richter |
last post by:
what is the standard way of using sql in C# to increment a counter
column in a shared control table? ( example: the next order number )
I would like to sql select a row in a table and lock it....
|
by: ARC |
last post by:
Hello all,
So I'm knee deep in this import utility program, and am coming up with all
sorts of "gotcha's!".
1st off. On a "Find Duplicates Query", does anyone have a good solution for...
|
by: Kemmylinns12 |
last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies...
|
by: Naresh1 |
last post by:
What is WebLogic Admin Training?
WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
|
by: Arjunsri |
last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and credentials and received a successful connection...
|
by: WisdomUfot |
last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific technical details, Gmail likely implements measures...
|
by: Matthew3360 |
last post by:
Hi,
I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web server and have made sure to enable curl. I get a...
|
by: BLUEPANDA |
last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...
|
by: Rahul1995seven |
last post by:
Introduction:
In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python has gained popularity among beginners and experts...
|
by: Ricardo de Mila |
last post by:
Dear people, good afternoon...
I have a form in msAccess with lots of controls and a specific routine must be triggered if the mouse_down event happens in any control.
Than I need to discover what...
|
by: ezappsrUS |
last post by:
Hi,
I wonder if someone knows where I am going wrong below. I have a continuous form and two labels where only one would be visible depending on the checkbox being checked or not. Below is the...
| |