How to replace the string of column value with other column value in same table
I have a temp table which contains
Id Name CTC Address Content
1 Ross $200 6th block Dear #Name your CTC is #CTC and your address is #address
2 Jhon $300 1oth cross Dear #Name your CTC is #CTC and your address is #address
Now i want to select content so that it should get replace with the respective columns and final output should come like this
Dear Ross your CTC is 200 and your address is 6th block
Dear Jhon your CTC is 300 and your address is 10th cross
Kindly suggest
I think RSingh suggestion is ok ... what do you mean by another way? ...maybe something more generic?
maybe build a table whith the list of col you need to "replace" and dinamically build the replace query ...
declare @colList table(colName varchar(100))
insert into @colList
select 'name'
union all select 'ctc'
union all select 'address'
declare @cmd varchar(2000)
select @cmd='select '+ (select 'replace(' from @colList for xml path('') +' content '+
(select ',''#'+ colName +''', '+ colName +')' from @colList for xml path(''))
+' from YOURTABLENAME '
exec (@cmd)
or your request was different ?
Similar Messages
-
How to replace the string in a file
Hi, I have a file which contains the following data
File.dat
<file>
<filenum>
W10
</filenum>
<hello>Heading </hello>
</file>
I need to replace the contents of file.dat
database sequence value (for example xx_seq.nextval)
Can some one please tell me how to search this <filenum>
W10</filenum>
and replace this with xx_seq.nextval
and write the entire contents of the file to new file
I am doing some thing like this
suppose if my database value returns 11 from the above sequence then
the output should be in file2.dat as
<file>
<filenum>
11</filenum>
<hello>Heading </hello>
</file>
declare f_in utl_file.file_type;
s_in varchar2(10000);
string1 varchar2(32000);
x number;
begin
f_in := utl_file.fopen('SAMPLEDIR','input.txt','R');
f_in1 := utl_file.fopen('SAMPLEDIR','input1.txt','W');
select xx_seq.nextval into x from dual;
loop
begin utl_file.get_line(f_in,s_in);
EXCEPTION
WHEN NO_DATA_FOUND THEN
EXIT;
string1:= string1 || s_in;
utl_file.put_line( (f_in1,s_in);
end;
end loop;
utl_file.fclose(f_in);
end;
In this case it is reading and writing as it is, but unable to replace the sequence value
Can some one please tell me how to do using replace function
ThanksHi, I have tried this but getting error
step 1: create table test_dept(dno number, dname varchar2(20))
insert into test_dept values(10,'10-Sourcing dept');
insert into test_dept values(20,'20-Audting dept');
insert into test_dept values(30,'30-Computer dept');
select * from test_dept;
DNO DNaME
10 10-Sourcing dept
30 30-Computer dept
20 20-Audting dept
step 2:
create table test_web (name varchar2(60), xml_col xmltype) ;
step 3:
create sequence test1_seq start with 100 increment by 1
step 4:
test.out has the following contents (it is not .xml file) and i dont have <?xml version="1.0" ?> tag at the begining
<File>
<File_Type>Type1</File_Type>
<File_Header_Record>
<file_num>WP10</file_num>
</File_Header_Record>
<Transaction>
<Transaction_Type>TR 1</Transaction_Type>
<Amount>
<Amounts>100</Amounts>
</Amount>
<Depts>
<Dept_Type>Sourcing</Dept_Type>
<Dept>10</Dept>
</Depts>
</Transaction>
<Transaction>
<Transaction_Type>TR 2</Transaction_Type>
<Amount>
<Amounts>200</Amounts>
</Amount>
<Depts>
<Dept_Type>Auditing</Dept_Type>
<Dept>20</Dept>
</Depts>
</Transaction>
<Transaction>
<Transaction_Type>TR 3</Transaction_Type>
<Amount>
<Amounts>300</Amounts>
</Amount>
<Depts>
<Dept_Type>Computer</Dept_Type>
<Dept>30</Dept>
</Depts>
</Transaction>
</File>
step 5:
DECLARE
v_check_file_exist BOOLEAN;
v_file_length NUMBER;
v_block_size NUMBER;
v_file_path VARCHAR2 (100);
v_file_name VARCHAR2 (100);
v_file_type UTL_FILE.FILE_TYPE;
v_str varchar2 (32760);
v_cnt number;
v_seq number;
--check whether file exists and has data in it
BEGIN
v_file_path := '/usr/tmp';
v_file_name := 'test.xml.out';
-- initailise the variables
v_cnt := 0;
UTL_FILE.FGETATTR (v_file_path,
v_file_name,
v_check_file_exist,
v_file_length,
v_block_size);
if v_check_file_exist
then
DBMS_OUTPUT.put_line (' File exists');
IF v_file_length > 0 AND v_block_size > 0
THEN
BEGIN
select test1_seq.nextval into v_seq from dual;
insert into test_web values(v_seq,v_file_name);
EXCEPTION
WHEN NO_DATA_FOUND
THEN
DBMS_OUTPUT.put_line ('No data found '||SQLERRM);
WHEN OTHERS
THEN
DBMS_OUTPUT.put_line ('others '||SQLERRM);
END;
commit;
ELSE
DBMS_OUTPUT.put_line ('No Data in File');
END IF;
ELSE
DBMS_OUTPUT.put_line (' File Not Available');
END IF;
END;
I am getting below error
File exists
others ORA-31011: XML parsing failed
ORA-19202: Error occurred in XML
processing
LPX-00210: expected '<' instead of 't'
Error at line 1
My requirement is to replace the
1. contents of the file WP10 from <file_num>WP10</file_num>
with sequence value 'WP101' because sequence is starting at 100
2. Replace all Dept tag <Dept>30</Dept> with Dname value from test_dept table
for example
<Dept>10</Dept> should be replaced with <Dept>10-Sourcing dept</Dept>
update the
when i say select * from test_web;
It should contain this row
101 <File>
<File_Type>Type1</File_Type>
<File_Header_Record>
<file_num>WP101</file_num>
</File_Header_Record>
<Transaction>
<Transaction_Type>TR 1</Transaction_Type>
<Amount>
<Amounts>100</Amounts>
</Amount>
<Depts>
<Dept_Type>Sourcing</Dept_Type>
<Dept>10-Sourcing dept</Dept>
</Depts>
</Transaction>
<Transaction>
<Transaction_Type>TR 2</Transaction_Type>
<Amount>
<Amounts>200</Amounts>
</Amount>
<Depts>
<Dept_Type>Auditing</Dept_Type>
<Dept>20-Audting dept</Dept>
</Depts>
</Transaction>
<Transaction>
<Transaction_Type>TR 3</Transaction_Type>
<Amount>
<Amounts>300</Amounts>
</Amount>
<Depts>
<Dept_Type>Computer</Dept_Type>
<Dept>30-Computer dept</Dept>
</Depts>
</Transaction>
</File>
Can you please check
Thanks -
[SOLVED] How to replace the source in a pkgbuild with a git repo?
I am trying to build csound (present in AUR: https://aur.archlinux.org/packages.php?ID=779), but compilation fails, as noted in the comments. One of the commenters says that he has successfully built the package by pulling the sources from the git repo.
How can I do that? I know how to use git. What I don't know is
(1) how to use git from within a PKGBUILD file,
or
(2) how to instruct the PKGBUILD file to use the locally pulled git repo
Cheers,
Stefano
Last edited by stefano (2012-10-06 15:11:14)Try csound-git https://aur.archlinux.org/packages.php?ID=48830 but see the comments - problems again.
You can see how to deal with git in the PKGBUILD.
Another way is to instal binary package from an unofficial user repository. archaudio-preview has csound 5.14.2-1.
https://wiki.archlinux.org/index.php/Un … positories
[archaudio-preview]
# unverified PKGBUILDs AND/OR untested packages
Server = http://repos.archaudio.org/$repo/$arch
Last edited by karol (2012-10-06 14:48:29) -
Columns merged with other columns?
how do I achieve the following?
I want to have a tabular form as following
The first line of the tabular form will only be 3 columns (eg. col1,col2,col3). those three columns will then be broken down into 9 columns (ed. col1 - no column, col2 will have col4,col5,col6, and col7, col3 wil have col8 to col12.) on the second line.
Any ideas? I know it is possible to do with html but i'm not sure how to process it in APEXWhat I typically do first is to look at a report template from the current theme and see what CSS classes they are using against the tables, headers and rows. I will copy the entries to a text document so I can easily reference them.
The you create a new report template from scratch and as a Named Column (row template).
This type template allows you to specify where each column goes by using a substitution variable for the selected column.
The query I used in the example was
select ename, job, sal
from emp
For the Row Template 1 field under Row Template section, I put
<tr><td>#ENAME#</td><td>#JOB#</td><td>#SAL#</td></tr>
In the Before first and after last row text section I put
1. in the Before rows field
<style type="text/css">
table.outln {border-collapse:collapse;}
table.outln td {border: solid #000 1px;padding:5px;}
</style>
<table cellpadding="0" border="0" cellspacing="0" summary="" class="t9standardalternatingrowcolors outln" border="1">
<tr><th class="t9header" colspan="2">Name / Job</th><th class="t9header">Salary</th></tr>
2. In the After Rows field
</table>
This type of template is REALLY powerful. The only issues that I have run into in the past is that the order of the columns in your query should be the same as the order in which they are used in your row template. I am not sure if it is still an issue, but I have experience issues in the past that when you later change the query and the order is different then the rows are actually put in by position and not by name. To fix that problem I just drop the report and recreate.
If you happen to have my book by Oracle Press, HTML DB Handbook, there is a good description of this type of template on pages 211- 215.
The book is a little old now (almost 2 years). Just happened that they renamed HTML DB to ApEx the month before the book was published. It covers ver 2.0, but still has some good info in it. -
How to find the list of applications registered with OID?
Could some one please help me?
how to find the list of applications registered with OID?Is there any table from which we would be able to see?
-
How to replace the char values into numeric in my string?
Hi Friends,
I would like to Replace the Charecter values with numeric value in my string.
Exp : first in my string I am having the value like this : 'ABCD1234' ( may be any char and num values ), and I want too get it by '99991234'.
I mean How to replace the char values into numeric in my string?
Thanks,
SridharHi Sridhar,
I would like to Replace the Charecter values with numeric value in my string.
Exp : first in my string I am having the value like this : 'ABCD1234' ( may be any char and num values ), and I want too get it by '99991234'.
So, if i understand you correctly, you want to replace all characters in a string with 9 as in the above example, irrespective of position of the character, if so try with the below code.
DATA: l_str TYPE string.
l_str = 'ASKHSIUDNSBDKJSDH124312431243124saasdfsf'.
REPLACE ALL OCCURRENCES OF REGEX '\D' IN l_str WITH '9'.
IF sy-subrc EQ 0.
WRITE: l_str. "Result will be 9999999999999999912431243124312499999999
ENDIF.
Regards,
Chen
Edited by: Chen K V on Jun 13, 2011 12:36 PM -
How can I replace column value with a particular value in SQL
Hi All,
Can anyone please tell me how can I format my output with replacing a column value with a specific value which actually depends on the present value of the column
I am executing the following SQL statement
select state,count(id) from <table_name> where composite_dn= <composite_dn_name> group by state;
My Present output is:
State No.Of Instance
1 3
3 28
I want to replace the value in the column state as follows
State No.OfInstances
Completed 3
Faulted 28
I want "1" to be reppaced by "Completed" and "3" to be replaced by "Faulted"
Is is possible with SQL or PL/SQL , if it is then how can I achieve this required result. Please help!!
Thanks in Advance!!
Edited by: Roshni Shankar on Oct 27, 2012 12:38 AMHi Roshni,
I guess this CASE clause can be simulated by a DECODE and also it is very easy to use.
Refer -- http://www.techonthenet.com/oracle/functions/decode.php
select decode(t1.state,t2.state_id,t2.state_name), t1.count_id
from <table_2> t2, (select state,count(id) count_id
from <table_name>
where composite_dn= <composite_dn_name>
group by state) t1
where t1.state = t2.state_id;HTH
Ranit B.
Edited by: ranit B on Oct 27, 2012 2:02 PM
-- link added
Edited by: ranit B on Oct 27, 2012 2:19 PM
-- sample code added -
How to capture the string values
Hi Gurus,
Could you plz suggest me how to capture the string value.
My requirement is.
I have a structure field called cnj_stat-sttxt_int and it is storing a value like "REL CDRT AVAC". AND the moddile value CDRT will change according to condtions. now i required to write a logic like if cnj_stat-sttxt_int field contain 'REL' and 'AVAC'. I HAVE TO THROW SOME ERROR.
SO please give some idea about on it...
Its urgent..
points will be rewarded...
Thanks in advance!!!!
Thanks & regards,
Kranthi.if cnj_stat-sttxt_int field contain 'REL' and 'AVAC'. I HAVE TO THROW SOME ERROR.
if cnj_stat-sttxt_int CS 'REL' and cnj_stat-sttxt_int CS 'AVAC'.
THROW SOME ERROR.
endif. -
How to Splilit The String Into Single Column using Comma As Delimiter ?
How to Splilit The String Into Single Column using Comma As Delimiter ?
using Functionrefer my thread ,code is also available see if that helps you
error while executing the sp ORA-21779: duration not active -
How to split the string by datetime in sql
Hi,
How to split the string by datetime in sql, I've a table with comments column stores comments by datetime, while selecting I want to split and show as in rows by each jobref.
can anyone help me in this please.
Thanks,declare @callcentre table (comments varchar(max),lbiref varchar(200))
insert into @callcentre
select '(28/10/2014 14:56:14) xyz ..... call logged (28/10/2014 14:56:58) xyz ..... call updated (28/10/2014 14:57:41)xyz ..... call updated','Vi2910201'
insert into @callcentre
select '(29/10/2014 14:56:14) xyz ..... call logged (29/10/2014 14:56:58) xyz ..... call updated (29/10/2014 14:57:41)xyz ..... call updated','Vi2910202'
insert into @callcentre
select '(30/10/2014 14:56:14) xyz ..... call logged (30/10/2014 14:56:58) xyz ..... call updated
output:
1) 28/10/2014 14:56:14, (28/10/2014 14:56:14) xyz ..... call logged ,'Vi2910201'
2) 28/10/2014 14:56:58 ,(28/10/2014 14:56:58) xyz ..... call updated ,'Vi2910201'
3) 28/10/2014 14:57:41, (28/10/2014 14:57:41)xyz ..... call updated,'Vi2910201'
4) 28/10/2014 14:56:14, (28/10/2014 14:56:14) xyz ..... call logged ,'Vi2910202'
5) 28/10/2014 14:56:58 ,(28/10/2014 14:56:58) xyz ..... call updated ,'Vi2910202'
6) 28/10/2014 14:57:41, (28/10/2014 14:57:41)xyz ..... call updated,'Vi2910202'
7) 28/10/2014 14:56:14, (28/10/2014 14:56:14) xyz ..... call logged ,'Vi2910203'
8) 28/10/2014 14:56:58 ,(28/10/2014 14:56:58) xyz ..... call updated ,'Vi2910203'
Thanks,
See this illustration
declare @callcentre table (comments varchar(max),lbiref varchar(200))
insert into @callcentre
select '(28/10/2014 14:56:14) xyz ..... call logged (28/10/2014 14:56:58) xyz ..... call updated (28/10/2014 14:57:41)xyz ..... call updated','Vi2910201'
insert into @callcentre
select '(29/10/2014 14:56:14) xyz ..... call logged (29/10/2014 14:56:58) xyz ..... call updated (29/10/2014 14:57:41)xyz ..... call updated','Vi2910202'
insert into @callcentre
select '(30/10/2014 14:56:14) xyz ..... call logged (30/10/2014 14:56:58) xyz ..... call updated','Vi2910203'
SELECT LEFT(p.u.value('.[1]','varchar(max)'),CHARINDEX(')',p.u.value('.[1]','varchar(max)'))-1) AS [Date],
'(' + p.u.value('.[1]','varchar(max)') AS comments,
lbiref
FROM
SELECT lbiref,CAST('<Root>' + STUFF(REPLACE(comments,'(','</Data><Data>'),1,7,'') + '</Data></Root>' AS XML) AS x
FROM @callcentre c
)t
CROSS APPLY x.nodes('/Root/Data')p(u)
and the output
Date comments lbiref
28/10/2014 14:56:14 (28/10/2014 14:56:14) xyz ..... call logged Vi2910201
28/10/2014 14:56:58 (28/10/2014 14:56:58) xyz ..... call updated Vi2910201
28/10/2014 14:57:41 (28/10/2014 14:57:41)xyz ..... call updated Vi2910201
29/10/2014 14:56:14 (29/10/2014 14:56:14) xyz ..... call logged Vi2910202
29/10/2014 14:56:58 (29/10/2014 14:56:58) xyz ..... call updated Vi2910202
29/10/2014 14:57:41 (29/10/2014 14:57:41)xyz ..... call updated Vi2910202
30/10/2014 14:56:14 (30/10/2014 14:56:14) xyz ..... call logged Vi2910203
30/10/2014 14:56:58 (30/10/2014 14:56:58) xyz ..... call updated Vi2910203
Please Mark This As Answer if it solved your issue
Please Mark This As Helpful if it helps to solve your issue
Visakh
My MSDN Page
My Personal Blog
My Facebook Page -
Can't change the connection string of SSIS package with derived columns?
We upgraded SQL server 2008 to 2012, copied and converted all SSIS packages from Visual Studio 2008 to 2010. When I opened a package in VS 2010 and tried to change the connection string, in the local connection managers, if the data source is another
SSIS package B(.dtsx file) with derived columns, I can't change the connection string of package B. When I opened the file connection manager editor for package B and tried to locate a dtsx file in another location, saved the change, reopened the project.
Package B still pointed to previous file. Other packages without derived columns work fine. Any thoughts?We are using the package deployment model and refer to other packages in the same project. If
we changed the path of package B (with derived columns) to "D:\Visual Studio 2010\xxxx", and refer it in package A, in the A's connection manager, the connection string of package B is still its previous location "D:\Visual
Studio 2008\xxxx". When we ran the package A in the SQL server agent, the data source is still
"D:\Visual
Studio 2008\xxxx", so how can I change it to "D:\Visual
Studio 2010\xxxx"? Why has the package C (without derived columns) no such problem? thanks. -
How to replace the root tag in ABAP Mapping
how to replace the root tag with the certain string in ABAP Mapping
just like
<?xml version="1.0" encoding="UTF-8"?>
<root>
<name>Lawrence</name>
</root>
into
<?xml version="1.0" encoding="UTF-8"?>
<myRootElement>
<name>Lawrence</name>
</myRootElement>
i don't want to implement it in message mapping
please give me the sample code
thanks in advanceUse below code
odocument = ixmlfactory->create_document( ).
msgtype = odocument->create_simple_element(
name = 'myRootElement'
parent = odocument ).
Thanks
Praveen -
How to insert some strings in a query with the clausule 'in' in a procedure
Hello fellows.
Do you know how to insert some strings in a query with the clausule 'in' in a procedure (with a variable)?.
I tell us my problem with an example:
I want to use this select but introducing a variable instead the 'value1', 'value2':
select * from table1 where field1 in ('value1', 'value2');
if I declare the variable var1 as:
TC_VAR1 CONSTANT VARCHAR2(50) := '''value1'',''value2'''
and I use it as:
select * from table1 where field1 in (TC_VAR1);
It doesn't work because Oracle takes TC_VAR1 as an all string. I think Oracle takes it as this:
select * from table1 where field1 in ('value1, value2');
If I use the data type TABLE, I don't know how to use well:
TYPE varchar2_table IS TABLE OF VARCHAR2(10);
tb_var varchar2_table;
select * from table1 where field1 in (tb_var);->It returns an error and there ins't an method that it returns all values.
A curious case is that if I have a sql script (for example script1.sh) with this query:
select * fromt able1 where field1 in (&1)
and I invoke this script as
script1.sh "'''value1'',''value2'''". It works
Can anybody helps me?.
Thanks.Thanks to all. Really.
First, sorry for my English. It's horrible. Thank to all for understand it (my English).
I've resolved my problem with these links:
ORA-22905: cannot access rows from a non-nested table item
and
http://stackoverflow.com/questions/896356/oracle-error-ora-22905-cannot-access-rows-from-a-non-nested-table-item
At last, I have used someting like this:
DECLARE
number_table_tmp NUM_ARRAY:=NUM_ARRAY(410673, 414303, 414454, 413977, 414042, 414115, 413972, 414104, 414062);
BEGIN
FOR c1 IN (SELECT par_id, 1 acc_vdo_id FROM SIG_VIS_CAM
WHERE par_id IN (SELECT * FROM TABLE(number_table_tmp))
UNION ALL
SELECT par_id, 2 acc_vdo_id FROM SIG_ACCAO a
WHERE par_id IN (SELECT * FROM TABLE(number_table_tmp))) LOOP
NULL;
END LOOP;
END;
but first I had to create the type NUM_ARRAY like this:
CREATE TYPE subjectid_tab AS TABLE OF NUMBER INDEX BY binary_integer;
THANK YOU, GUYS. YOU ARE THE BESTS. ;-)
Edited by: user12249099 on 08-sep-2011 7:37
Edited by: user12249099 on 08-sep-2011 7:37 -
How do I transfer music from my ipod to my computer without replacing the music on my ipod with the music on my computer?
You can't do that with iTunes (except for songs you purchased from the iTunes Store). However, there are third-party methods and utilities that can transfer songs files from iPod to computer. If you do a Google search on something like "ipod transfer," you should get some links.
Once the songs files are on your computer, add them to your iTunes library. Then, you can sync your iPod to that iTunes library, as desired. -
How to find the Date and Time of Modification of Column in aTable?
Hi all,
Do you know how to find the Date and Time of Addition of Column to a Particular Table?.
I know however, How to find the modification time of the Table. Using the below Query :
Select Object_Name, to_Char(Last_DDL_TIME, 'DD-Mon-YYYY HH24:MI:SS') Last_DDL from User_Objects where Object_Type = 'TABLE';
Object_Name
Last_DDL
Employee
20-Aug-2013 09:23:03
I wanted to know the Creation or Modification Date and Timestamp of all columns of Employee Table?. Is it possible at all. If possible, How to get it?.
Regards,
Bhaskar MI agree with you on that. Since its a development enviornment I can remove the column but that not my point here.
My whole purpose it to know whether we get the Column's Creation or Modification DateTime.
Maybe you are looking for
-
HI, i created a dc using webdynpro java ,when i'm buiding it is giving the following error plz help me Aug 31, 2007 4:07:27 PM /userOut/Development Component (com.sap.ide.eclipse.component.provider.listener.DevConfListener) [Thread[ModalContext,5,ma
-
Can I install Garageband from iLife 2008 on Macbook Pro 10.8?
Can I install Garageband from iLife 2008 onto a Macbook pro 10.8, recently bought?
-
Changing font size in cash flow report
Hello , How can I change the font size that diplayed in the PLD of cash flow report ? I tried to change the font size of single field and I cannot see the change in the printed report. If I would change the size of the field or the colour of it , the
-
Default format pattern for Date and Number
Hi everybody, I'm finding it very hard: my java app runs on Tomcat 5.5, I'd like to format dates and numbers with a specific format. For example: with Locale it_it date format is "dd-mm-yyyy", my wish is to display "dd/mm/yyyy" without changing the L
-
Oracle Management Server Service not created
Hello, I created a Management Server Repository using OEMCA and an existing SID. According to the details displayed at the end of the wizard I assume that the process was finished successfully: (NT-Service OracleOraHome81 ManagementServer is started.