Using Escape character in UPDATE statement
SELECT REPLACE
( REPLACE
( REPLACE( REPLACE( REPLACE( REPLACE( BODY, '<STARTOFLINK>' )
, '<ENDOFLINK>' )
FROM ARTICLEI need to use the above in an UPDATE statement to remove some HTML tags from a CLOB column. However when I run the script it asks for the substitution variables for the '&' characters. I've tried "ESCAPE '\'" but I think you can only use that with a like operand.
Any suggestions?
Message was edited by:
Terrible
As you can see the HTML tags have been converted in this post!! I'm trying to remove:
& amp;
& quot;
& ndash;
& #039;
This may help;
SQL> create table t (col1 varchar2(200))
Table created.
SQL> insert into t values('<STARTOFLINK>')
PL/SQL executed.
SQL> insert into t values('<ENDOFLINK>')
PL/SQL executed.
SQL> insert into t values(chr(38) || 'amp;')
PL/SQL executed.
SQL> insert into t values(chr(38) || 'quot;')
PL/SQL executed.
SQL> insert into t values(chr(38) || 'ndash;')
PL/SQL executed.
SQL> insert into t values(chr(38) || '#039;')
PL/SQL executed.
SQL> insert into t values('<STARTOFLINK>link<ENDOFLINK> '
|| ' AMP:' || chr(38) || 'amp;'
|| ' DQT:' || chr(38) || 'quot;'
|| ' DASH:'|| chr(38) || 'ndash;'
|| ' SQT:' || chr(38) || '#039;')
PL/SQL executed.
SQL> select * from t
col1
<STARTOFLINK>
<ENDOFLINK>
<STARTOFLINK>link<ENDOFLINK> AMP:& DQT:" DASH:– SQT:'
7 rows selected.
SQL> select regexp_replace(
regexp_replace(
regexp_replace(
regexp_replace(
regexp_replace(col1, '<.*OFLINK>',NULL),
chr(38) || 'amp;', chr(38)),
chr(38) || 'quot;', chr(34)),
chr(38) || 'ndash;', chr(45)),
chr(38) || '#039;', chr(39))
new_col from t
NEW_COL
AMP:& DQT:" DASH:- SQT:'
7 rows selected.Message was edited by:
MScallion
The SELECT * values were not as they are displayed due to HTML conversions.
Similar Messages
-
How to use escape character in update statement.
Hi All,
I'm trying to update table using following sql update statement, but everytime it's asking me for the input due to the '&' value in below sql.
UPDATE xyz_xyz
SET NAME = 'ABC & PQR'
WHERE ID = (SELECT ID
FROM abc_abc
WHERE NAME = 'C & PQR');Please let me know how to use escape character syntax or let me know if there is any alternative solution.
Thanks,
VishwasHi,
By default, & marks a substitution variable name.
If you're not using substitution variables in that statement (or, if this is in PL/SQL, in that entire package or procedure) then the easiest thing to do is just diable substitution variables; then & will be a normal character:
SELECT DEFINE OFF
UPDATE xyz_xyz
SET NAME = 'ABC & PQR'
WHERE ID = (SELECT ID
FROM abc_abc
WHERE NAME = 'C & PQR');
SET DEFINE ONIf you can't do that, then & is always taken literally if it comes right before a single-quote, so you could say:
UPDATE xyz_xyz
SET NAME = 'ABC &' || ' PQR'
WHERE ID = (SELECT ID
FROM abc_abc
WHERE NAME = 'C &' || ' PQR');There is a SQL*Plus "SET ESCAPE" command, too, but if you use it, you have to worry about whether the escape character is to be taken literally or not.
SET ESCAPE \Yet another alternative is to make some other character, such as ~, mark the substitution variables:
SET DEFINE ~Read all about them in the SQL*Plus manual.
http://download.oracle.com/docs/cd/B28359_01/server.111/b31189/ch2.htm#sthref103 -
Urgent Help - in using Escape character
hai,
i have problem in using escape character..
can anyone help me out in the same...
sb.append(<jsp:getProperty name="resume_main" property="name"/>);
//error i am getting is -- Missing term, ')' expected.
pl help me out in using the escape character in the above statement.
thanx in advance
regards
koeltry
sb.append("<jsp:getProperty name='resume_main' property='name'/>");
or
sb.append("<jsp:getProperty name=\"resume_main\" property=\"name\"/>");
both will work -
Can I use a select and update statement in a single jsp file?
I want to update the BUY table everytime I would add a SELL transaction.....I want to minus the stocks that I sold to those that Ive bought before.....
note: I used a seperate table in BUY and SELL transaction
After I Have added a transaction, I want to update the buy table. This is my problem, can I used both SELECT and UPDATE statement at the same time in a single jsp file for example like this:
select * from test, test1;
update test
set total_shares=total_shares-Stotal;
where stock_code=Scode AND name_broker=Sbroker;
Can i have both of these statements in the same jsp file in oder to update the buy table?
Or can anyone suggest how can process that update?THANKS!
--------------------Can i have both of these statements in the same jsp file in oder to update the buy table?Yes. But wouldn't it have been easier just to try it?
-
How to escape & symbol in Update statement
Hi all,
How to escape & symbol in Update statement..
Below is my update statement which contains lot of & symbols...
UPDATE ContentItem SET ContentData =
'<:'
where ContentItemId = 398
if i run this query it asks input value for lt..
Can anyone give the suggestions please.. Its very urgent..
Cheers,
Moorthy.GSHey all,
Thanks for your reply.
But i am getting error for below statement
set define off;
UPDATE ContentItem SET ContentData =
'<?xml version="1.0" encoding="utf-16"?>
<contentItem xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" id="398" resizable="false" contentTypeId="15" parentContentTypeId="0" sortOrder="0" width="0" height="0" xsltFileId="" createDate="0001-01-01T00:00:00" startDate="2006-12-06T00:00:00" endDate="2010-12-31T00:00:00" publishedDate="0001-01-01T00:00:00" CategoryId="0" DotNetClassType="HPCi.OnlineContentDelivery.Core.ContentItem" DotNetAssVersion="1.0.0.0">
<title>Executive_Photos</title>
<CampaignName />
<files />
<textItems>
<textItem type="" linkName="" linkUrl="" identifier="Body" dataDocFileId=""><?xml version="1.0" encoding="utf-16"?>
<contentItem xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" id="40" contentTypeId="10" parentContentTypeId="0" sortOrder="0" createDate="0001-01-01T00:00:00" startDate="2006-04-04T00:00:00" endDate="2006-05-06T00:00:00" publishedDate="0001-01-01T00:00:00" DotNetClassType="HPCi.OnlineContentDelivery.Core.ContentItem" DotNetAssVersion="1.0.0.0">
<title>Image Gallery</title>
<files />
<textItems>
<textItem type="" linkName="" linkUrl="" identifier="Body" dataDocFileId="" xsltFileId=""><!-- BEGIN CODE FOR THE TOP CONTROL -->
<script language="javascript" type="text/javascript">
function showImage(sImgId, sTargetImgPath)
document.getElementById("imgLargeImage").src = sTargetImgPath;
</script>
<div id="topThumbContainer" style="float:left; width:100%;">
<div id="divThumbs" style="float:left;">
<table>
<tr>
<td width="84px" >
<div id="divThumbImage1" class="divThumbImage" onClick="javascript:showImage(''ThumbImg1'', ''Images/bio/BobMetz_lg.jpg'');">
<img id="ThumbImg1" src="Images/bio/BobMetz_sm.jpg" width="63" height="85" />
</div>
<div id="divThumbText1" style="text-align:center;">Bob Metz</div>
</td>
<td>
<div id="divThumbImage3" class="divThumbImage" onClick="javascript:showImage(''ThumbImg3'', ''Images/bio/Crawford_lg.jpg'');">
<img id="ThumbImg3" src="Images/bio/Crawford_sm.jpg" width="63" height="85" />
</div>
<div id="divThumbText3" style="text-align:center;">David Crawford</div>
</td>
</tr>
<tr>
<td width="84px" >
<div id="divThumbImage2" class="divThumbImage" onClick="javascript:showImage(''ThumbImg2'', ''Images/bio/JamieGallo_lg.jpg'');">
<img id="ThumbImg2" src="Images/bio/JamieGallo_sm.jpg" width="63" height="85"/>
</div>
<div id="divThumbText2" style="text-align:center;">Jamie Gallo</div>
</td>
<td >
<div id="divThumbImage4" class="divThumbImage" onClick="javascript:showImage(''ThumbImg4'', ''Images/bio/Mayfield_lg.jpg'');">
<img id="ThumbImg4" src="Images/bio/Mayfield_sm.jpg" width="63" height="85"/>
</div>
<div id="divThumbText4" style="text-align:center;">Arlene Mayfield</div>
</td>
</tr>
<tr>
<td width="84px" >
<div id="divThumbImage5" class="divThumbImage" onClick="javascript:showImage(''ThumbImg5'', ''Images/bio/Turnbull_lg.jpg'');">
<img id="ThumbImg5" src="Images/bio/Turnbull_sm.jpg" width="63" height="85" />
</div>
<div id="divThumbText5" style="text-align:center;">Robert Turnbull</div>
</td>
<td>
<div id="divThumbImage6" class="divThumbImage" onClick="javascript:showImage(''ThumbImg6'', ''Images/bio/hessels_lg2.jpg'');">
<img id="ThumbImg6" src="Images/bio/hessels_sm2.jpg" width="63" height="85" />
</div>
<div id="divThumbText6" style="text-align:center;">Jane T. Hessels</div>
</td>
</tr>
<tr>
<td width="84px" >
<div id="divThumbImage7" class="divThumbImage" onClick="javascript:showImage(''ThumbImg7'', ''Images/bio/bauz_lg.jpg'');">
<img id="ThumbImg7" src="Images/bio/bauz_biopic.jpg" width="63" height="85" />
</div>
<div id="divThumbText7" style="text-align:center;">Melanie Wernick</div>
</td>
<td>
<div id="divThumbImage8" class="divThumbImage" onClick="javascript:showImage(''ThumbImg8'', ''Images/bio/child_lg.jpg'');">
<img id="ThumbImg8" src="Images/bio/child_biopic.jpg" width="63" height="85" />
</div>
<div id="divThumbText8" style="text-align:center;">Mike Child</div>
</td>
</tr>
<!--<tr>
<td>
<div id="divThumbsRight">
<img src="Images/AG5_About_Us_Photo_Gallery_Camera.gif" alt="Image of Camera" border="0" height="150" />
</div>
</td> -->
</tr>
</table>
</div>
</div>
<!-- END CODE FOR THE TOP CONTROL --></textItem>
<textItem type="" linkName="" linkUrl="" identifier="NameTitle" dataDocFileId="" xsltFileId="">Images</textItem>
</textItems>
</contentItem></textItem>
</textItems>
</contentItem>'
where ContentItemId = 398
Error is "SQL Error: ORA-01704: string literal too long"
My contentdata column is CLOB datatype.
Pls help me....
Moorthy.GS -
Export Data Using Escape Character
Hi All
I have got a requirement where i need to export data from oracle with escape character.
eg. I am using a delimiter 237(í) and if the same character is present in data it should be escaped by escape character eg. /.
Once this file will get created i need to load this file in Netezza database which supports escape character.
Data in oracle table
FirstName Lastname Designation
abc xyz mnz
def ghío pqr
Data should be exported like below
FirstnameíLastnameíDesignation
abcíxyzímnz
defígh/íoípqr
Thanks.943994 wrote:
Thanks for the reply. I am new to Oracle and i am not able to find any command for exporting data in Oracle. I know we can do it manually using select statement but in that case we need to replace this delimiter with escape character and delimiter for all char fields.
In netezza we can directly do that without this. Please see below example and let me know if any such thing is present in Oracle.
SQL> CREATE EXTERNAL TABLE '/temp/test.csv' USING (REMOTESOURCE 'ODBC' DELIMITER 236 DATESTYLE 'YMD' DATEDELIM '-' TIMESTYLE '24HOUR' TIMEDELIM ':' MAXERRORS 0 ESCAPECHAR '\' NULLVALUE '' ) AS SELECT * FROM temp;
.CSV file created by above command:
abcíxyzímnz
defígh/íoípqr
Thankshttp://docs.oracle.com/cd/E11882_01/server.112/e22490/et_params.htm#sthref1293 -
How to use rownum=2 in update statement ?
Hi all,
we are migrating the data from mainframe to oracle. migration team extracted the data into flat file. we are using this flat file to load in oracle.Finacle have menu option to load data from flat file to corresponding oracle tables.whenever i given this flat file to Menu it will give error report like below if any rows have error.
here "A/c. Opening Matrix" is the error.
error report:-
A/c. Opening Matrix
The Above Error Was For record No: 1
A/c. Opening Matrix
The Above Error Was For record No: 2
we are extracting and storing all the error message and corresponding record no in shell script as below.
err_msg=`echo ${error_msg[i]}`
rec_num=`echo ${error_msg[i]}| cut -d: -f2`
we need to update the upload status either upload success or failure and error message in upload history table. iam writing the update statement as below.
update statement:-
update upld_hist set upld_status='ERR' ,upld_err='$err_msg' where rownum=$rec_num;
This is statement is updating only for rownum=1. other than this it is not updating the table. Please suggest me how to update the rows based on rownum?
Thanks,
Venkat Vadlamudi868591 wrote:
Hi all,
we are migrating the data from mainframe to oracle. migration team extracted the data into flat file. we are using this flat file to load in oracle.Finacle have menu option to load data from flat file to corresponding oracle tables.whenever i given this flat file to Menu it will give error report like below if any rows have error.
here "A/c. Opening Matrix" is the error.
error report:-
A/c. Opening Matrix
The Above Error Was For record No: 1
A/c. Opening Matrix
The Above Error Was For record No: 2
we are extracting and storing all the error message and corresponding record no in shell script as below.
err_msg=`echo ${error_msg[i]}`
rec_num=`echo ${error_msg[i]}| cut -d: -f2`
we need to update the upload status either upload success or failure and error message in upload history table. iam writing the update statement as below.
update statement:-
update upld_hist set upld_status='ERR' ,upld_err='$err_msg' where rownum=$rec_num;
This is statement is updating only for rownum=1. other than this it is not updating the table. Please suggest me how to update the rows based on rownum?
Thanks,
Venkat VadlamudiUse Analytic ROW_NUMBER() ..
http://docs.oracle.com/cd/E11882_01/server.112/e26088/functions156.htm#i86310 -
Using Escape character for Multi character delimiter for flat files in IKM
Hi
I have an IKM using Jython, it is working fine for single character delimiter. But as per requirement I have to use multicharacter delimiter ;" (semi colon and double quotes).
I am taking this into variable using
filesep = "<%=snpRef.getSrcTablesList("", "[SFILE_SEP_FIELD]", "", "")%>"
but it is giving lexical error.
Can anybody help me with the use of escape character in current scenario?
Any other suggestions are also appreciated.
Thanks
AnkitHello,
A small tweak may solve your problem:
Instead of :
CONCATENATE wa_condstr ' bukrs = ' pa_bukrs INTO wa_condstr SEPARATED BY space.
Use:
CONCATENATE wa_condstr ' bukrs = ' 'PA_BUKRS' INTO wa_condstr SEPARATED BY space.
Then use this in SELECT.
Anyways for your answer the escape character for apostrophe is an apostrophe )
Try this you will understand:
DATA:
V_STR TYPE STRING VALUE ''''.
WRITE: V_STR.
BR,
Suhas -
Updating a column using deleted/inserted during update statement execution
I need to capture the old value while update statement is executed. I can not insert into temp table (there are many samples online where you can use OUTPUT clause to insert data in same table or another temp table)
something like
declare @count table
id int,
changed varchar (50)
insert into @count (id,changed) values (2,'T')
insert into @count (id,changed) values (3,'T')
insert into @count (id,changed) values (4,'T')
select * from @count
UPDATE @count
SET id=5,
Changed = GETDATE() -- here instead of date, I want to get inserted.id and deleted.id
OUTPUT inserted.id,
deleted.id
where id = 2
SELECT *FROM @count
Any help on this will be very much appreciated....I am not sure to follow your question but you can get the old value just by doing:
UPDATE @count
SET id=5,
Changed = id
OUTPUT inserted.id,
deleted.id
WHERE id = 2;
since SQL Server uses all-at-once operations.
Microsoft SQL Server 2012 T-SQL Fundamentals
http://shop.oreilly.com/product/0790145321978.do
AMB
Some guidelines for posting questions... -
Use table name in UPDATE statement as variable
Hi All,
I am using ORACLE 9i AIX base. I want to write following procedure:
PROCEDURE update_header (
p_care_msg_nbr IN NUMBER,
p_care_msg_id IN NUMBER,
p_care_msg_gkey IN NUMBER,
p_old_status IN VARCHAR2,
p_new_status IN VARCHAR2
IS
l_table varchar2(50);
BEGIN
l_table := 'CARE_EDI_MESSAGES';
UPDATE '&l_table'
SET status = p_new_status,
changed = sysdate,
changer = user
WHERE care_msg_no = p_care_msg_nbr
AND care_msg_id = p_care_msg_id
AND gkey = p_care_msg_gkey
AND status = p_old_status;
END;
I want to give the table name by passing value in a variable or parameter. Is it the write way or can I do this function in any other way.
Pleae tell me in urgency.
Thanks & Regards
Hassan RazaThis implies that you have several tables with identical or near identical structures, otherwise you will get errors if any of the mentioned columns do not exist in the table passed but ...
You cannot use a substitution variable that way. Oracle will ask for a value when you try to create the procedure, and compile what ever value you supply into the procedure viz.
SQL> CREATE PROCEDURE p AS
2 l_id NUMBER;
3 BEGIN
4 SELECT id INTO l_id FROM &t;
5 END;
6 /
Enter value for t: T
old 4: SELECT id INTO l_id FROM &t;
new 4: SELECT id INTO l_id FROM T;
Procedure created.
SQL> SELECT text FROM user_source WHERE name = 'P'
2 ORDER BY line;
TEXT
PROCEDURE p AS
l_id NUMBER;
BEGIN
SELECT id INTO l_id FROM T;
END;Even if that is the effect you want, note that there are no quotes around the substitution variable in the CREATE statement.
If you want to be able to pass the name of the table to the procedure, then you need to make the table name a parameter, then build the sql statement and execute it using EXECUTE IMMEDIATE. Something more like:
PROCEDURE update_header (p_care_msg_nbr IN NUMBER,
p_care_msg_id IN NUMBER,
p_care_msg_gkey IN NUMBER,
p_old_status IN VARCHAR2,
p_new_status IN VARCHAR2,
p_table IN VARCHAR2) IS
l_sqlstr VARCHAR2(4000);
BEGIN
l_sqlstr := 'UPDATE '||p_table||' SET status = :b1 '||
'changed = sysdate, changer = user '||
'WHERE care_msg_no = :b1 and care_msg_id = :b3 and '||
'gkey = :b4 and status = :b5';
EXECUTE IMMEDIATE l_sqlstr
USING p_new_status, p_care_msg_nbr, p_care_msg_id, p_care_msg_gkey, p_old_status;
END;HTH
John -
CONTAINS Operator using ESCAPE character
I must to do a SELECT sentence with a column with a domain index using CONTAINS. I need to look for a text that includes "%", but I want that the query recognizes it like literal and not like joker. I proved using the escape characters "\" and "{}", but I do not know if it does consider to the character "%" or if it uses it like comodín. The query is the next (if i need to find "6%"):
SELECT v.campo1, v.campo2
FROM promo_busqueda_leyes.s_version_xml v
WHERE contains (v.campo_xml, '(6\%)', 1)>0
or
SELECT v.campo1, v.campo2
FROM promo_busqueda_leyes.s_version_xml v
WHERE contains (v.campo_xml, '(6{%})', 1)>0
what am I making wrong?if i understood correctly, try like this....
use INSTR instead of CONTAINS ie
WHERE contains (v.campo_xml, '(6\%)', 1)>0WHERE INSTR (v.campo_xml, '(6\%)', 1)>0 -
Using loop varibale in UPDATE statement
begin
for i in 1..31 loop
Update od_ebh_shift_schedule
Set i='Test'
where year=2010 and i='W' ;
end loop;
end;}
Here "i" is the column such as 01,02,03....31 in the table called od_ebh_shift_schedule
FYI-->Column type is varchar2
I want the column get updated as 'Test' when it is 'W', Kindly help he me with thisHi,
Yes, typo. Sorry.
And if your table columns have some prefix, PL/SQL might look something like this
DECLARE
l_sql VARCHAR2(32700);
l_col VARCHAR2(255);
BEGIN
FOR i IN 1 .. 31
LOOP
IF i < 10 THEN
l_col := '0' || i;
ELSE
l_col := i;
END IF;
l_sql :=
'UPDATE od_ebh_shift_schedule SET '
|| l_col
|| ' = ''Test'' WHERE year = 2010 AND '
|| l_col || ' = ''W'''
EXECUTE IMMEDIATE l_sql;
END LOOP;
END;But I just guess as OP do not provide details
Regards,
Jari -
How can i use multiple row subquery in update statement
Hai All
I using group function in my update statement.. and i need to update more rows so i need to use multiple row
subquery pls tell me how to use multiple row subquery in update statement
For example
while i am using this like this i got an error
update dail_att set outtime in (select max(r2.ptime) from temp_att where empcode=r2.enpno and
barcode=r2.cardn and attend_date=r2.pdate group by enpno,pdate,cardn);
Pls tell me how to use with example
Thanks & regards
Srikkanth.MHai Man
Thanks for ur response Let me clear what i need
First step Fetch the records as text file and stores into table T1
and the next step is i have seperated the text using substring and stores in different columns of a table
There are two shifts 0815 to 1645 and 1200 and 2000
Here I rep IN and O rep OUT
Empno date time inout
001 01-01-10 0815 I
002 01-01-10 0815 I
003 01-01-10 0818 I
001 01-01-10 1100 0
001 01-01-10 1130 I
002 01-01-10 1145 0
002 01-01-10 1215 I
004 01-01-10 1200 I
005 01-01-10 1215 I
004 01-01-10 1315 O
004 01-01-10 1345 I
001 01-01-10 1645 0
002 01-01-10 1715 0
003 01-01-10 1718 0
004 01-01-10 2010 0
005 01-01-10 2015 0
This is my T1 table i have taken data from text file and stored in this table from this table i need to move data to another table T2
T2 contains like this
Empno Intime Intrin Introut Outtime Date
001 0815 1100 1130 1645 01-01-10
002 0815 1145 1215 1715 01-01-10
003 0818 1718 01-01-10
004 1200 1315 1345 2010 01-01-10
005 1215 2015 01-01-10
This what i am trying to do man but i have little bit problems Pls give some solution with good example
And my coding is
declare
emp_code varchar2(25);
in_time varchar2(25);
out_time varchar2(25);
Cursor P1 is
Select REASON,ECODE,READMODE,EMPD,ENPNO,FILL,PDATE,PTIME,INOUT,CARDN,READERN
From temp_att
group by REASON,ECODE,READMODE,EMPD,ENPNO,FILL,PDATE,PTIME,INOUT,CARDN,READERN
ORDER BY enpno,pdate,ptime;
begin
for r2 in p1 loop
declare
bar_code varchar2(25);
begin
select barcode into bar_code from dail_att where empcode=r2.enpno and attend_date=r2.pdate;
For r3 in (select empcode,empname,barcode,intime,intrin,introut,addin,addout,outtime,attend_date from dail_att)loop
if r2.inout ='O' then
update dail_att set outtime =(select max(r2.ptime) from temp_att where empcode=r2.enpno and barcode=r2.cardn and attend_date=r2.pdate group by r2.cardn,r2.enpno,r2.pdate );
end if;
end loop;
exception
when no_data_found then
if r2.inout ='I' then
insert into dail_att(barcode,empcode,intime,attend_date)(select r2.cardn,r2.enpno,min(r2.ptime),r2.pdate from temp_att group by r2.cardn,r2.enpno,r2.pdate );
end if;
end;
end loop;
commit;
end;
Pls tell me what correction i need to do i the update statement i have used a subquery with group function but when i used it will return only one row but my need is to return many rows and i need to use multiple row subquery
and how can i use it in the update statement
Thanks In Advance
Srikkanth.M -
Updates using single SQL Update statement.
Hi Guys,
I had an interview... and was not able to give an answer of one of the question.
Given the emp table... need to update the salary with following requirement using one SQL statement...
1. Update salary+1000 for those employees who have salary between 500 and 1000
2. Update salary+500 for those employees who have salary between 1001 and 1500
Both above requirement should be done by using only one SQL update statement... can some one tell me how to do it?update emp
set salary = case when salary between 500 and 1000
then salary + 1000
when salary between 1001 and 1500
then salary + 500
end;Regards
Arun -
Update statement with Aggregate function
Hi All,
I would like to update the records with sum of SAL+COMM+DEPTNO into SALCOMDEPT column for each row. Can we use SUM function in Update statement. Please help me out this
See below:
Table
CREATE TABLE EMP
EMPNO NUMBER(4) NOT NULL,
ENAME VARCHAR2(10 CHAR),
JOB VARCHAR2(9 CHAR),
MGR NUMBER(4),
HIREDATE DATE,
SAL NUMBER(7,2),
COMM NUMBER(7,2),
DEPTNO NUMBER(2),
SALCOMDEPT NUMBER
Used update statement :
UPDATE emp e1
SET e1.salcomdept= (select sum(sumsal+comm+deptno) from emp e2 where e2.empno=e1.empno)
WHERE e1.deptno = 10
commit
Thanks,
UserAdding these columns makes no sense, so I'll assume this is just an exercise.
However, storing calculated columns like this is generally not a good idea. If one of the other columns is updated, your calculated column will be out of sync.
One way around this is to create a simple view
SQL> CREATE view EMP_v as
2 select EMPNO
3 ,ENAME
4 ,JOB
5 ,MGR
6 ,HIREDATE
7 ,SAL
8 ,COMM
9 ,DEPTNO
10 ,(nvl(sal,0) + nvl(comm,0) + nvl(deptno,0)) SALCOMDEPT
11 from emp;
View created.
SQL> select sal, comm, deptno, salcomdept from emp_v;
SAL COMM DEPTNO SALCOMDEPT
800 20 820
1600 300 30 1930
1250 500 30 1780
2975 20 2995
1250 1400 30 2680
2850 30 2880
2450 10 2460
3000 20 3020
5000 10 5010
1500 0 30 1530
1100 20 1120
950 30 980
3000 20 3020
1300 10 1310
14 rows selected.
Maybe you are looking for
-
How can I export a Video without making it darker than the original file?
Hi there! I'm working on a footage shot with the Canon 5D and since the first step in the post I exported the raw footage with Apple ProRes 422 (HQ) and worked with it in After Effects and later on FCP and then the usual Color and Compressor. But som
-
I have just installed v6.3 for Windows and am trying to run a hyperbuild simulation of a legacy (v6.2 UNIX) model. I suspect that I don't have everything configured right (path to C compiler???) I get the error message "can't find 'nmake'" during sim
-
HP 3050 Scanner not working with Windows 7
My HP 3050 worked fine with XP. Now that i have a computer with Windows 7, the scanner will not work. I called HP, and they do not have a fix, and their Windows 7 computer with HP 3050 scanner works the same way. Do you have any suggestions?
-
PDF attachments are showing up as WORD doc attachments
For some reason, my Gmail program shows PDF attachments (that were created using Adobe) as a WORD attachment? When I double click on the attachment, it tries to open in WORD and just shows gobbledygook. Yet, if I don't try to open it and save it to
-
One box in my house is not getting all channels and other channels are digitized. All other boxes are fine. Rebooting does not help. Ideas?