how to replace a string with new string after connecting to sql

Hi, I have a file which contains the following data

File.dat
<filenum>
W10
</filenum>
<hello>Heading </hello>
 

I need to replace the contents of file.dat with
database value inplace of W10

Can some one please tell me how to search this <filenum>
W10</filenum>

and replace this with by connecting to backend database get the sql value replace inplace of this 10
and write to the file

suppose if my database value returns 11
the output should be in file2.dat

<filenum>
11</filenum>
<hello>Heading </hello>
 

Thanks
Ramya

#!/bin/sh

ret=`sqlplus -s user@SID/passwrd<<SQL
     set feed off
     set head off
     set pages 0
     set verify off
     select '11' from dual;
     quit
SQL`

echo $ret
sed "s/W10/$ret/g" File.dat >  File2.dat