Every two charater of a column into a row
Hello everyone,
I am trying to convert every two characters of a column into a row.
Something like...
with t as
SELECT
'00112233445566778899' TN
FROM dual
--union all
--select 'xxyyzzaabbccddeeffgg' from
--dual
SELECT SUBSTR
( tn
, decode(n,0,0,(((n*2)+1)-2))
, 2
) AS token ,n
FROM ( select * from t
, ( SELECT LEVEL n
FROM (SELECT length(tn)/2 max_elements FROM t)
CONNECT BY LEVEL <= max_elements +30
WHERE n <= LENGTH(tn) /2
TO N
00 1
11 2
22 3
33 4
44 5
55 6
66 7
77 8
88 9
99 10The above query fails when I try to do it for multiple rows(It goes in an infinite loop).
Is there a way to convert ever two characters of a column into a row.
I am using Oracle 9i.
Thanks in Advance,
Jaggyam
jaggyam wrote:
Note : I am using 9i.It's usually a good idea to mention that at the beginning otherwise we have to assume you are using the latest/supported versions of oracle.
Does this work in 9i.... (I don't have an old version to try it on)
SQL> ed
Wrote file afiedt.buf
1 with t as (select '00112233445566778899' as txt from dual union all
2 select 'aabbccddeeff' from dual)
3 ,m as (select max(length(txt)/2) mx from t)
4 --
5 select txt
6 from (
7 select substr(txt, ((rn-1)*2)+1, 2) as txt
8 from t, (select rownum rn from m connect by rownum <= mx)
9 )
10* where txt is not null
SQL> /
TX
00
aa
11
bb
22
cc
33
dd
44
ee
55
ff
66
77
88
99
16 rows selected.
SQL>
Similar Messages
-
Need to Convert Comma separated data in a column into individual rows from
Hi,
I need to Convert Comma separated data in a column into individual rows from a table.
Eg: JOB1 SMITH,ALLEN,WARD,JONES
OUTPUT required ;-
JOB1 SMITH
JOB1 ALLEN
JOB1 WARD
JOB1 JONES
Got a solution using Oracle provided regexp_substr function, which comes handy for this scenario.
But I need to use a database independent solution
Thanks in advance for your valuable inputs.
GeorgeGo for ETL solution. There are couple of ways to implement.
If helps mark -
How to convert single column into single row
I need to convert single column into single row having n no.of.values in a column. without using case or decode. I need a query to display as below.
emp_id
100
101
102
102
103
200
I need output like 100,101,102,103,104.........200.I assume you want to convert 200 rows with one column into one row with 200 columns. If so, this is called pivot. If you know number of rows (max possible number of rows) and you are on 11G you can use PIVOT operator (on lower versions GROUP BY + CASE). Otherwise, if row number isn't known, you can use dynamic SQL or assemble select on clent side. Below is example emp_id = 1,2,..5 (to give you idea) and you are on 11G:
with emp as (
select level emp_id
from dual
connect by level <= 5
select *
from emp
pivot(
max(emp_id) for emp_id in (1 emp_id1,2 emp_id2,3 emp_id3,4 emp_id4,5 emp_id5)
EMP_ID1 EMP_ID2 EMP_ID3 EMP_ID4 EMP_ID5
1 2 3 4 5
SQL>
SY. -
To get all the required data in a column into a row
Hi,
I have a table T which contains columns Id,Name,Type
The structure of the table will be like
Id Name Type
1 ABC S
2 DEF F
1 ADR F
3 ASD D
1 DCH C
1 ADE S
2 CDF D
I need an output like this
Id Types
1 S,F,C
2 F,D
3 D
Can any one help me in this regard. It will be thankful.
Thank You
11081985Hi,
That's called String Aggregation . The following page shows several ways to do it:
http://www.oracle-base.com/articles/10g/StringAggregationTechniques.php
Which way is best for you? That depends on your requirements (e.g., Is order important? What to do about duyplicates?) and your version of Oracle.
I hope this answers your question.
If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) and the results you want from that data.
Explain, using specific examples, how you get those results from that data.
Always say what version of Oracle you're using (e.g. 11.2.0.2.0).
See the forum FAQ {message:id=9360002} -
Concat different rows column into single row field
Hi,
I have a table tblSite which has SiteID and SiteInvestigator. Can I concat different row base on siteID.
SiteID -- SiteInvestigator
1 -- x
1 -- y
2 -- z
2 -- x1
3 -- x2
Basicaly I want data look like this,
sitid --siteinvestigator
1 -- x,y
2 -- z,x1
3 -- x2
I want to use only sql query or create a view to get data like this. No stored procedure please.
Can somebody help?
Regards,
Vinaythis example might be of help.
SQL> select * from tab1;
COL1 COL2 COL3 COL4
Sofinummer 1 occupation 1
Sofinummer 1 occupation 2
Sofinummer 1 occupation 3
Sofinummer 2 occupation 1
SQL> select col1, col2,
2 substr(replace(max(substr(sys_connect_by_path (col3||' '||
3 col4, '-'),2)),'-',' '),1,60)
4 as col3
5 from tab1
6 start with col4 = 1
7 connect by col4 = prior col4 + 1
8 and prior col1 = col1
9 and prior col2 = col2
10 group by col1, col2;
COL1 COL2 COL3
Sofinummer 1 occupation 1 occupation 2 occupation 3
Sofinummer 2 occupation 1
SQL> -
Convert column values into a row with a delimiter
Hi Gurus,
This may be a trivial question to you. I have an internal table itab with a column called plant, internal table has 'n' records, by the end of loop, I need to convert the column into a row delimited by comma into one row (one field). This needs to be dynamic without hard-coding.
Plant
1000
2000
3000
4000
5000 ....
n....
Expected result of the field:
field1 value: 1000,2000,3000,4000,5000,...n
Let's set a limit to the field say it can hold upto 500 chars.
Thanks,
GP.Hi,
I've already tried this:
ELSEIF <fs_dms_cv>-zca_cv_attr_ind = c_multiple.
w_plant = <fs_plant_ele>-werks.
concatenate w_string w_plant
into w_string separated by c_delimiter.
IF w_end_fl = c_on.
w_tabname = <fs_dms_cv>-dbtabname.
ASSIGN (w_tabname) TO <fs_tabname>.
IF sy-subrc = 0.
ASSIGN COMPONENT <fs_dms_cv>-name_komp OF
STRUCTURE <fs_tabname> TO <fs_destination>.
IF sy-subrc = 0.
<fs_destination> = w_string.
ENDIF.
ENDIF.
There are 2 issues here: One is that after first plant there will be two commas inserted, after that it's consistent. Secondly the key word concatenate is against our code standards.
Please let me know if there is any other way of doing this.
Thanks. -
How to combine a one columns into 1?
I am using Oracle 8i,
I want to know that how to combine a one columns into 1 row:
For example:
ITEM_NO NAME
01 ABC
01 CDE
Result Set:
ITEM_NO NAME
01 ABC; CDE
I have try to use "SYS_CONNECT_BY_PATH" this function, however, that function can use in Oracle 9i or 10g, NOT 8i.
So please please help me to solve that. Many thanks.Check this thread
Re: column values separated by , -
2.1.0.62: Bug editing text columns in multiple rows using editor-window
Hello Forum,
I hope this is not a double post, but I did not come up with the right keywords to search for.
So here is the bug/strange annoying behavior:
When I edit multiple rows of a table using the extra edit-window, it shows the text of the previous row I edited and not the text of the actual row.
Well, sounds quit complicated so I'll give an example:
Suppose you have a table with two columns and two rows. One column is of type varchar2. Say it contains the values "one" and "two".
Now I click into the row containing "one", open the extra-edit-window and change the value to "one-1".
Then I click into the second row and also open the extra-edit-window. The window shows "one-1" instead of "two" as it should.
This is very annoying because I don't have autocommit activated and when I edit a couple of clob fields, the editor just shows the text of the previous field. I have to say commit for every row in order not to scramble the contents of multiple fields. I have to use the edit-window because the inplace editor is not very useful when editing large texts.
I observed this bug with varchar2 and clob fields but it may not be restricted to those.
I run Windows XP and conect to Oracle 10.2.0.4
Regards,
dhalekHello -K-,
setting "Post edits on row change" indeed does prevent this bug, but leads to another problem:
When I click the rollback-button, the table data is not reverted to its original state. In fact the changes are not commited, but rolling back, does not give the old data back. I can enter "rollback;" into the worksheet and then refresh the table data to show the old values but internally SQL Developer still thinks it has uncommitted changes in the table.
I, for now, uncheck "Post edits on row change" and use the inplace editor wherever possible. That has some strange cursor bugs (sometimes puts the cursor to the end making it impossible to enter text in the middle of the field) but that does not affect other rows.
Regards,
dhalek
Edited by: dhalek on 30.10.2009 15:08 -
Randomly when I plug my Iphone 4s into Itunes it will tell me that it can't detect my phone and that I need to restore it. It doesn't happen every time, but maybe every two weeks.I restore it and then it works for a while, but then a couple weeks later I'll plug it in and I get the same message again. It's very frustrating because even though I have all the settings to save to cloud, my apps and data don't all come back.
Thank you both. I suppose I should have prefaced my question with the concern that I've read a number of other posts from people who have had a similar issue and when they tried to follow the directions, they ran into a multitude of other problems. As you might imagine, I'm hoping to avoid the creation of new problems as I try to solve this one. Thanks again.
-
How to split list of columns into 2 tables in SSIS 2012?
Hi,
I have 200 columns in Source. Now i want to split these columns, few into Destination A and few more columns into
Destination B. Multi cast i tried to use, but it coping all the columns . Any help would be appreciated. Thanks in Advance.
Lets assume i have columns A,B,C,D,E..
i want to move Columns A,B,D into destination A and
columns A,C,D,E INTO Destination B. please help me to implement this logic?Hi vasu_479,
Based on your description, you want to split columns in source table into two destination tables.
After testing the scenario in my environment, we can use Multicast to achieve your requirement. Just as you said, the Multicast would return all columns. But we can use the method below to achieve the goal:
If the destination tables are existing tables, we can just map column A, B and D as Input Columns to the corresponding Destination Columns in the Mapping tab for destination A. Then map column A, C, D and E in destination B.
If the destination tables are created in the Destination component, we can modify the create table query to directly create A, B and D for destination table A, create A, C, D and E for destination table B. Then there columns would be automatically mapped
in the Mappings pane.
If there are any other questions, please feel free to ask.
Thanks,
Katherine Xiong
Katherine Xiong
TechNet Community Support -
Write data to serial port every two minutes
Hi,
I use VISA-Write to write data to serial port. I want to write a byte every two minutes. What should I do?
Thanks!hengfo,
that question is not connected to LV nor to VISA. Its more a systematic question....
So let's view at this a bit more abstract:
You want to "toogle" between two different messages sent to your interface. So you have to know:
- What was the last state i sent?
- When do i have top send the new state?
Even more abstract:
- How can i switch between the states?
Since the states are known before your program is executed, you can insert them into an array. Next, you have to read out the appropriate index from the array which contains your new state. Send the state and go to the next state. Propably you want to change timing, but that's easy too.
See attached screenshot for a possible solution:
hope this helps,
NorbertMessage Edited by Norbert B on 09-11-2007 07:57 AM
CEO: What exactly is stopping us from doing this?
Expert: Geometry
Marketing Manager: Just ignore it.
Attachments:
StateSwitching.PNG 8 KB -
Writing BLOB column into a csv or txt or sql files
Hi All,
I am having a requirement where i have to upload a file from user desktop and place that file into a unix directory. For this i am picking that file into a table using APEX and then writing that file in unix directory using UTL_FILE.
The problem which i am facing is that after this every line in my file is having ^M character at the end.
For this i modified my BLOB column into a CLOB column and then also i am facing the same problem.
Is there any way to get rid of this as i have to upload these csv or txt files into tables using sql loader programs. i can;t write any shell script to remove ^M character before uploading as this program will be merge with existing programs and then it will require lots of code change.
Kindly Help.
Thanks
AryanHi Helios,
Thanks again buddy for your reply and providing me different ways.... but still the situation is i can;t write any shell script for removing the ^M. I will be writing into a file from CLOB column.
Actually the scenrio is when i am writing a simple VARCHAR columns with 'W' mode then it is working fine, but i have a BLOB column which stores the data in binary format so i am converting that column into CLOB and then writing it into file with 'W' mode but then i am getting ^M characters. As per your suggestion i have to then again run a program for removing ^M or i have to modify all my previous programs for removing ^M logic.
I want to avoid all these, and just wanted a way so that while writing into a file itself it should not have ^M. Else i have to go for a java stored procedure for running a shell script from sql, and in this still i am having some problem.
Thanks Again Helios for your time and help.
Regards
Aryan -
Two suggestions regarding table columns in the Oracle database
Oracle,
I have two suggestions to make.
First, it would be of great value to be able to add a new column at an arbitrary position in a table and not simply add it to the end of the column list. Quite frequently we have to drop and recreate tables in order to accomplish this.
Second, we often add 4 columns to the end of every table's column list (and accompanying triggers in order to keep them updated) which would seem suitable as Oracle pseudo-columns (in the same fashion as ROWID, etc.) These 4 columns would be:
- Row created date
- Row created by Oracle user
- Row updated date
- Row updated by Oracle user
Regards,
Dan D'Andrea
[email protected]Dan,
I don't work for Oracle, but, just some thoughts/reactions to your ideas.
I don't think inserting a column in any arbitrary position is feasible, because it doesn't scale. It would require a reorganization of every block in the table. One reasonable workaround is to add the columns at the end of the table, then create a view on top of the table that has the columns in the desired order.
As to the second suggestion, yes, we do something similar, add the same 4 columns to every table. I think the reason that Oracle doesn't support these types of pseudocolummns, is the overhead this would incur. Not only in terms of the extra resources, to maintain the data, but also storage overhead.
So, just my unofficial opinion, but, I don't see how either of those suggestions would make it.
Also, FYI, if you want to officially enter an enhancement request, see Doc ID 214168.1 on MetaLink.
Hope that helps,
-Mark -
Update multiple rows based on two columns in same row
I have a 1000 rows in a table I would like to update with a unique value. This unique value is a cocatenation of two columns in teh same row.
Each row has a (i) date and a (ii) time and a (iii) date_time column. I would like to update the date_time (iii) column with a cocatenation of the (i) date and (ii) time columns.
I know how I would update a single row but how can I update multiple rows with a cocatenation of each of the two columns - i.e put a different value into the date_time column for each row?this?
update table tab_name
set date_time =date||time
where your_condition -
Add Extra Columns into Multi-Level Explode BOM (List Report) - CS12
Hi Experts,
I wish to add extra columns into the list report generated from program RCS12001 (calling from t-code: CS12). The current layout will be AS-IS and the only way i wish is to add-in few new columns in the report.Hi
declare select-options instead of parameters
for converting a report to ALV
create a field catalog.
for this two option declare a itab with
fcat TYPE slis_t_fieldcat_alv
and pass the field name,descr etc to fcat and append the same.
or create structur same as your itab and pass the same with FM
'REUSE_ALV_FIELDCATALOG_MERGE'
use either <b>reuse_alv_grid_display or reuse_alv_list_display</b> .
and pass the itab.
thanks
Shiva
Maybe you are looking for
-
Don't Send Error when playing movies with CL Entertaiment Cen
When I try to watch movies with the Creative Entertaiment Center (via remote) but I get the don't send error bellow. Music and photos have no issues, only movies give me errors. Any ideas? http://img399.imageshack.us/my.php?image=eroareey5.jpg? Messa
-
Restauration by SDCard doesn't work
Hello First sorry for my english , i'm french. I make the update 4.0726.2.0.1 on my N73, and i can't restore my contact and sms. The files backup.arc is on my SDCard, when i make the restore, this don't start and a popup tell me that my phone will st
-
RMAN Automatic Datafile Creation
Hi, Could anyone please explain me RMAN Automatic Datafile Creation in oracle 10g with example. Thanks in advance regards, Shaan
-
Project Files & Workspace Files
The 3rd demo on workspaces talks about keeping the project files separate from the workspace files. But it does not tell me why I would want to do that. Does anyone know where I could find more info on the topic? Thanks Mathias
-
UserParameter of RegisterEventCallback node
The help says that "User Parameter contains data that LabVIEW passes to the user through the callback VI when the ActiveX object generates the event." I understand that each time the ActiveX object generates the event, the data connected to the User