Parsing a selected column into multiple returned values
I have a column in a table that contains a string of variable names seperated by commas. In my Select statement is it possible to break apart the string using the commas as a delimeter and get each item returned individually?
Here's my table:
SQL> create table myvars
2 (x number(1), vars varchar2(200));
Table created.
SQL> insert into myvars
2 values
3 (1, 'varA,varS,varY');
1 row created.
SQL> edit
Wrote file afiedt.buf
1 insert into myvars
2 values
3* (2, 'varX,varU,varB,var1')
SQL> /
1 row created.
SQL> edit
Wrote file afiedt.buf
1 insert into myvars
2 values
3* (3, 'varE,varI')
SQL> /
1 row created.
SQL> set linesize 250
SQL> /
X VARS
1 varA,varS,varY
2 varX,varU,varB,var1
3 varE,varI
So, would it be possible to somehow select the a row of text where X = 2 that ends up looking like this:
X
2 varX varU varB var1
...where the column VARS is broken into 4 smaller strings of text?
SQL> select ename from emp where empno = 7934 ;
ENAME
SMITH,ALLEN
1 row selected.
SQL> select * from TABLE(select cast(in_list(ename) as mytableType) from emp where empno = 7934) a ;
COLUMN_VALUE
SMITH
ALLEN
2 rows selected.
SQL>Message was edited by:
Kamal Kishore
Similar Messages
-
Pro C - Select abc into :cds returns value but strcpy(cds, 'test' did not
Dear All
I have a test.pc program at Unix as follow:
varchar cds [11];
varchar xyz [30];
varchar fxo [11]
main(argc, argv)
int argc;
char **argv;
find_sp_inv ();
ins_inv();
find_sp_inv()
EXEC SQL SELECT inv_no into :cds
FROM sup_inv
WHERE REF_NO = 12 ;
cds.arr[cds.len] = '\0';
EXEC SQL DECLARE cinvno CURSOR for select inv_type from inv_types
where ref_no = 12;
EXEC SQL OPEN cinvno;
for (i=0;i<3;i++) /* max three inv_type needed only against one reference */
/* invoice types may be one, two or three against one ref_no so need loop */
EXEC SQL WHENEVER NOT FOUND GOTO notfoundd;
EXEC SQL FETCH cinvno into :fxo;
fxo.arr[fxo.len] = '\0';
strcat((char*)xyz.arr,(char*)fxo.arr);
notfoundd:
printf("%-30sn\", xyz.arr) /* prints the value .. printing fine */
return;
ins_inv()
EXEC SQL
INSERT INTO inv_reference (ref_NO, ref_types)
SELECT :cds, :xyz from dual;
return;
} /* end my program */
**So it only picks Value of :cds an did not :xyz value? why please explain me ( i mean help me out).**
**Kind regards.**
**Saeed**Perhaps you have posted your problem in a wrong place - i guess.
Check from here ->
http://forums.oracle.com/forums/category.jspa?categoryID=18
Or,
http://forums.oracle.com/forums/main.jspa?categoryID=84
And, please close this thread by marked it as answered.
Regards.
Satyaki De. -
How can I separate one column into multiple column?
How can I separate one column into multiple column?
This is what I have:
BUYER_ID ATTRIBUTE_NAME ATTRIBUTE_VALUE
0001 PHONE_NUMBER 555-555-0001
0001 EMAIL [email protected]
0001 CURRENCY USD
0002 PHONE_NUMBER 555-555-0002
0002 EMAIL [email protected]
0002 CURRENCY USD
0003 PHONE_NUMBER 555-555-0003
0003 EMAIL [email protected]
0003 CURRENCY CAD
This is what I would like to have:
BUYER_ID PHONE_NUMBER EMAIL CURRENCY
0001 555-555-0001 [email protected] USD
0002 555-555-0002 [email protected] USD
0003 555-555-0003 [email protected] CAD
Any help would be greatly appreciated.This is another solution. Suppose your actual table's name is test(which has the redundant data). create a table like this:
CREATE TABLE test2 (BUYER_ID number(10),PHONE_NUMBER varchar2(50),EMAIL varchar2(50),CURRENCY varchar2(50));
then you will type this procedure:
declare
phone_number_v varchar2(50);
EMAIL_v varchar2(50);
CURRENCY_v varchar2(50);
cursor my_test is select * from test;
begin
for my_test_curs in my_test loop
select ATTRIBUTE_VALUE INTO phone_number_v from test
where person_id=my_test_curs.person_id
and attribute_name ='PHONE_NUMBER';
select ATTRIBUTE_VALUE INTO EMAIL_v from test
where person_id=my_test_curs.person_id
and attribute_name ='EMAIL';
select ATTRIBUTE_VALUE INTO CURRENCY_v from test
where person_id=my_test_curs.person_id
and attribute_name ='CURRENCY';
INSERT INTO test2
VALUES (my_test_curs.person_id,phone_number_v,EMAIL_v,CURRENCY_v);
END LOOP;
END;
Then you will create your final table like this:
create table final_table as select * from test2 where 1=2;
After that write this code:
INSERT ALL
into final_table
SELECT DISTINCT(BUYER_ID),PHONE_NUMBER,EMAIL,CURRENCY
FROM TEST2;
If you have a huge amount of data in your original table this solution may take a long time to do what you need. -
I need to divide selected row into multiple rows when i navigate ADF 11g
Hi
I'm using jdeveloper 11.1.1.2.0 with ADF 11g.
I need to divide selected row into multiple rows when i navigate to other page . Scenario - in first page i'm displaying some records with columns like empno , empstatus , empworkdepts ,curdepts
Here empworkdepts gives the numeric number like no of departments work shifts 3 or 4 or 5. when i select any particular employee and fire next button to navigate next page.I have to divide the selected employee with same information into multiple times based on the empworkdepts value.
empno empstatus empworkdepts curdept
001 eds 2 TS
002 hr 1 FO
003 eds 4 TS
*004 eds 3 TS*
now i selected employee 004 , when i navigate to next page.
Empno EmpStatus EmpWorkDepts CurDept
004 eds 3 TS
004 eds 3 TS
004 eds 3 TS
i did with java code in bean .but not stable .
any help............
thanks advance.............
Edited by: user9010551 on May 5, 2010 10:48 PM
Edited by: user9010551 on May 10, 2010 11:31 PMuser9086775 wrote:
Hi Experts,
I have a requirment where i need to fetch parts of a single row into multiple rows from a singlt Query, i am sure it is possible using Pivots but just cant figure out an approach. Any help on this is highly appriciapted.
Requirment:
This is a sample set record in a table
Product Sub Product Name Age
New Car Nissan Tom 49
New Car Nissan Jack 36
Old Car Audi Sam 24
Old Car Jaguar Pint 26
Old Car Audi Smith 41
I need to be able to fetch the above data in the below fashion
Product Sub Product Name Age
New Car
Nissan
Tom 49
Jack 36
Old Car
Audi
Sam 24
Smith 41
Jaguar Pint 26Please help with ideas as to how can i achive the above without using PLSQL.
Thanks in advance!You should be doing this in the client on not in the DB. Use the reporting tool that you use to do this.
For example if you are in SQL Plus you can use the BREAK command. -
Multiple return values (Bug-ID 4222792)
I had exactly the same request for the same 3 reasons: strong type safety and code correctness verification at compile-time, code readability and ease of mantenance, performance.
Here is what Sun replied to me:
Autoboxing and varargs are provided as part of
JSRs 14 and 201
http://jcp.org/en/jsr/detail?id=14
http://jcp.org/en/jsr/detail?id=201
See also:
http://forum.java.sun.com/forum.jsp?forum=316
http://developer.java.sun.com/developer/earlyAccess/adding_generics/index.html
Multiple return values is covered by Bug-ID 4222792
Typically this is done by returning an array.
http://developer.java.sun.com/developer/bugParade/bugs/4222792.html
That's exactly the problem: we dynamically create instances of array objects that would better fit well within the operand stack without stressing the garbage collector with temporary Array object instances (and with their backing store: 2 separate allocations that need to be recycled when it is clearly a pollution that the operand stack would clean up more efficiently)
If you would like to engage in a discussion with the Java Language developers, the Generics forum would be a better place:
http://forum.java.sun.com/forum.jsp?forum=316
I know that (my report was already refering to the JSR for language extension) Generics is not what I was refering to (even if a generic could handle multiple return values, it would still be an allocated Object
instance to pack them, i.e. just less convenient than using a static class for type safety.
The most common case of multiple return values involve values that have known static datatypes and that should be checked with strong typesafety.
The simple case that involves returning two ints then will require at least two object instances and will not solve the garbage collection overhead.
Using a array of variable objects is exactly similar, except that it requires two instances for the components and one instance for the generic array container. Using extra method parameters with Integer, Byte, ... boxing objects is more efficient, but for now the only practical solution (which causes the least pollution in the VM allocator and garbage collector) is to use a custom class to store the return values in a single instance.
This is not natural, and needlessly complexifies many interfaces.
So to avoid this pollution, some solutions are used such as packing two ints into a long and returning a long, depacking the long after return (not quite clean but still much faster at run-time for methods that need to be used with high frequencies within the application. In some case, the only way to cut down the overhead is to inline methods within the caller code, and this does not help code maintenance by splitting the implementation into small methods (something that C++ can do very easily, both because it supports native types parameters by reference, and because it also supports inline methods).
Finally, suppose we don't want to use tricky code, difficult to maintain, then we'll have to use boxing Object types to allow passing arguments by reference. Shamely boxed native types cannot be allocated on the operand stack as local variables, so we need to instanciate these local variables before call, and we loose the capacity to track the cases where these local variables are not really initialized by an effective call to the method that will assign them. This does not help debugging, and is against the concept of a strongly typed language like Java should be:
Java makes lots of efforts to track uninitialized variables, but has no way to determine if an already instanciated Object instance refered in a local variable has effectively received an effective assignment because only the instanciation is kept. A typical code will then need to be written like this:
Integer a = null;
Integer b = null;
if (some condition) {
//call.method(a, b, 0, 1, "dummy input arg");
// the method is supposed to have assigned a value to a and b,
// but can't if a and b have not been instanciated, so we perform:
call.method(a = new Integer(), b = new Integer(), 0, 1, "dummy input
arg");
// we must suppose that the method has modified (not initialized!)
the value
// of a and b instances.
now.use(a.value(), b.value())
// are we sure here that a and b have received a value????
// the code may be detected at run-time (a null exception)
// or completely undetected (the method() above was called but it
// forgot to assign a value to its referenced objects a and b, in which
// case we are calling in fact: now.use(0, 0); with the default values
// or a and b, assigned when they were instanciated)
Very tricky... Hard to debug. It would be much simpler if we just used:
int a;
int b;
if (some condition) {
(a, b) = call.method(0, 1, "dummy input arg");
now.use(a, b);
The compiler would immediately detect the case where a and b are in fact not always initialized (possible use bere initialization), and the first invoked call.method() would not have to check if its arguments are not null, it would not compile if it forgets to return two values in some code path...
There's no need to provide extra boxing objects in the source as well as at run-time, and there's no stress added to the VM allocator or garbage collector simply because return values are only allocated on the perand stack by the caller, directly instanciated within the callee which MUST (checked at compile-time) create such instances by using the return statement to instanciate them, and the caller now just needs to use directly the variables which were referenced before call (here a and b). Clean and mean. And it allows strong typechecking as well (so this is a real help for programmers.
Note that the signature of the method() above is:
class call {
(int, int) method(int, int, String) { ... }
id est:
class "call", member name "method", member type "(IILjava.lang.string;)II"
This last signature means that the method can only be called by returning the value into a pair of variables of type int, or using the return value as a pair of actual arguments for another method call such as:
call.method(call.method("dummy input arg"), "other dummy input arg")
This is strongly typed and convenient to write and debug and very efficient at run-time...Can anyone give me some real-world examples where
multiple return values aren't better captured in a
class that logically groups those values? I can of
course give hundreds of examples for why it's better
to capture method arguments as multiple values instead
of as one "logical object", but whenever I've hankered
for multiple return values, I end up rethinking my
strategy and rewriting my code to be better Object
Oriented.I'd personally say you're usually right. There's almost always a O-O way of avoiding the situation.
Sometimes though, you really do just want to return "two ints" from a function. There's no logical object you can think of to put them in. So you end up polluting the namespace:
public class MyUsefulClass {
public TwoInts calculateSomething(int a, int b, int c) {
public static class TwoInts {
//now, do I use two public int fields here, making it
//in essence a struct?
//or do I make my two ints private & final, which
//requires a constructor & two getters?
//and while I'm at it, is it worth implementing
//equals(), how about hashCode()? clone()?
//readResolve() ?
}The answer to most of the questions for something as simple as "TwoInts" is usually "no: its not worth implementing those methods", but I still have to think about them.
More to the point, the TwoInts class looks so ugly polluting the top level namespace like that, MyUsefulClass.TwoInts is public, that I don't think I've ever actually created that class. I always find some way to avoid it, even if the workaround is just as ugly.
For myself, I'd like to see some simple pass-by-value "Tuple" type. My fear is it'd be abused as a way for lazy programmers to avoid creating objects when they should have a logical type for readability & maintainability.
Anyone who has maintained code where someone has passed in all their arguments as (mutable!) Maps, Collections and/or Arrays and "returned" values by mutating those structures knows what a nightmare it can be. Which I suppose is an argument that cuts both ways: on the one hand you can say: "why add Tuples which would be another easy thing to abuse", on the other: "why not add Tuples, given Arrays and the Collections framework already allow bad programmers to produce unmainable mush. One more feature isn't going to make a difference either way".
Ho hum. -
Split column into multiple text and number columns
I'm trying to figure out how to split this column into multiple columns with power query. One column for the company name/person name, one for the address, one for the zip. Some of the addresses have a three or four digit code before the address, which
I would like in its own column too. It's the 170 on the lastname, firstname line. Does anyone have any pointers on this? I'm familiar with PQ advanced editor, but struggling with this one.
COMPANY INC. 195 MAIN ST MYCITY ST 12345
LASTNAME, FIRSTNAME 170 477 ANY STREET CIRCLE MYCITY ST 12345
Thanks for your help!HI Gil,
We have column with more than one numbers separated by space or comma or semicolon.
We need to add the row for each number by keeping all other column value same.
Here is a original table
Col1
Col2
Col3
A
B
11 22,33 44; 55
C
D
10 20
and expected output should be
Col1
Col2
Col3
A
B
11
A
B
22
A
B
33
A
B
44
A
B
55
C
D
10
C
D
20
Please let us know the best way to solve this... -
Multi-Select LOV with multiple return columns
Hi,
I'm wondering if it's possible (and how) to return more columns from the LOV page the calling page. Default only 1 column is displayed in the LOV and 1 column is returned.
However it's easy to display an additional column in the LOV: Just copy the column tag change the binding column to display and change the prompt.
Furthermore in my situation I don't have a FK between the calling page and LOV. It's just a LOV which returns values which can be edited after.
Regards,
MarcelMarcel,
In the upcoming release it will be possible to supply a comma-separated list in the 'Lookup Display Attributes' field, so that multiple fields are shown in the LOV.
When you use UIX and have an Entity Association to the Entity Object in the LOV, passing back multiple fields is already possible. But in your case, you will probably have to use your own javascript to implement this functionality.
Kind regards,
Peter Ebell
JHeadstart Team -
SSRS Column Chart Design Returning values in a format different from SSRS -SSAS Query Designer
Hi All,
I have an SSAS cube Measure Group with Multiple Measures that I am attempting to return on one SSRS report and reflect the
values using a ssrs column chart.
My Measure Group (Patients).
Measures:
PatientsOnMeds
PatientOnRelapse
PatientsCounseld
TotalNumberOfPatientsRegisterd
NewlyRegisteredPatients
HealthPersonelTrainef
Demension:
Time (Year) :filtered to 2012 & 2013
In my SSRS query designer I have filtered the above Measures with Time Dimesion year 2012 & 2013
and the data is returned as :
Year |PatientsOnMeds|PatientOnRelapse|TotalNumberOfPatientsRegisterd|NewlyRegisteredPatients|
2012 | 700 | 526 | 25 | 456
2013 | 245 | 245 | 15 | 70
Now the problem is when I return this data on the column Chart it's in messed up mesh
On the chart Data:
-Values :Measures
-Series Group: Dimension
The report values are returned in multiple columns for each value segmented by year i.e year 2012,Year 2013.
I want a single column for each Measure (value) for each single year and The chart axis to reflect the measures(values)
instead of grouping values according to series group.
instead the legend returns:
-Year A -PatientsOnMeds
-Year A -PatientOnRelapse
-Year B -PatientsOnMeds
-Year B -PatientOnRelapse
I would like the legend to reflect on -Year A,Year B in color code that will be highlighted in the column values.
Please point me in the right course if you can.Your insights are highly appreciated.Thank you in advance.Hi Charlie,
Thank you for your kind response.
In actual I want the legend to show:
-2012
-2013
And the bottom axis to show:
PatientsOnMeds
PatientOnRelapse
PatientsCounseld
TotalNumberOfPatientsRegisterd
NewlyRegisteredPatients
HealthPersonelTrained
Indicating in color code for Year 2012 and Year 2013.
This the challenge that I am struggling with.I hope you understand my scenario.
It aint easy. -
Inserting Selected Checkboxes into multiple rows
Problem Statement
Form Contains -
Project Name (Select List - Single)
Checklist (Checkboxes - Dynamic LOV, Values from Table - Master Checklist)
Now I have to Insert into ProjectChecklistTabel.
I select Project from list, select multiple checkboxes and click submitt. Now, data should be inserted into table as -
ProjectSelected Checkbox1Value
ProjectSelected Checkbox2Value
ProjectSelected Checkbox3Value
Can anyone explain how can I do this.Sure,
Use the following code in a page process on submit:
DECLARE
l_vc_arr2 htmldb_application_global.vc_arr2;
BEGIN
l_vc_arr2 := HTMLDB_UTIL.string_to_table (:p1_checkbox);
FOR i IN 1 .. l_vc_arr2.COUNT
LOOP
INSERT INTO checkbox_table
(checkbox_value
VALUES (l_vc_arr2 (i)
END LOOP;
END;Also, see numerous examples on that issue here:
http://htmldb.oracle.com/pls/otn/f?p=31517:84
Denes Kubicek
http://deneskubicek.blogspot.com/
http://www.opal-consulting.de/training
http://apex.oracle.com/pls/otn/f?p=31517:1
------------------------------------------------------------------- -
How to select data into multiple bind variables
Hi,
I need to load data into multiple bind variable how to do that
As of now i am using this
select a , b into :a, :b from dual
But i want even a to be loaded into both :a and :c also b to be loaded into :b and :d Please suggest
Thanks
Sudhir.Thanks much it worked
Thanks
Sudhir -
Multiple return values in Customized elementary search help
Hello,
I have a requirement when i select the value from F4 . It should populate the more than one return values in ALV grid in different rows .
Any FM or help search exit is available to do this .
Regards,
kevinHi Kevin,
About your first question, for filling several fields of an ALV from a single F4 search help, I think that you should register F4 event to call the search help yourself (F4IF_INT_TABLE_VALUE_REQUEST for instance), and fill the ALV fields inside your F4 handler method. If you used REUSE_ALV_GRID_DISPLAY, then I am not sure how you can handle F4, but you can do it using CL_GUI_ALV_GRID or SALV classes. See BCALV_TEST_GRID_F4_HELP.
About the second question, for filling automatically another field in the same row in the ALV grid, it should work automatically, as for normal dynpros, i.e. the search help must have these 2 fields defined as exporting, and these 2 fields of the ALV field catalog must refer to the same DDic structure, the search help must be assigned there to the field, and fill in the 2 exporting parameters too.
Sandra -
LOV problem with multiple return values.
I created a ViewObject and in it a transient attribute.
I create a ViewAccessor for another field and a LOV for it (default InputText with Lov Value).
In List Return Values I added also my tranient attribute in order to receive another attribute from the accesor VO.
When I run it from the Application browser I see my transient attribute emtpty even if the "source" attribute is not empty.
If I change the value from the LOV the source value changes bit the transient is still empty.
What's wrong ?
Tks
TullioRepost.
-
Regarding ssis - split multi value column into multiple records
Hi,
I have one scenario
Table
Col1. Col2
1. A,b,c,df,ghf
2. C,b
3. B
Output should be
Col1. Col2
1. A
1. B
1. C
1. Df
1. Ghf
2. C
2. B
3. B
please helpTry the below:
Create TVF as below:
CREATE FUNCTION [dbo].[split]
( @String NVARCHAR(4000), @Delimiter NCHAR(1) )
RETURNS TABLE
AS
RETURN
With Split(stpos, endpos)
AS (
SELECT 0 AS stpos, CHARINDEX(@Delimiter, @String) AS endpos
UNION ALL
SELECT endpos + 1, CHARINDEX(@Delimiter, @String, endpos + 1)
FROM Split
WHERE endpos > 0
SELECT 'Id' = ROW_NUMBER() OVER (ORDER BY (SELECT 1)),
'Data' = SUBSTRING(@String, stpos, COALESCE(NULLIF(endpos,0), LEN(@String)+1)-stpos)
FROM Split
Test script:
create Table Test_Table(id int, data varchar(4000))
Insert into Test_Table Values(1,'a,F,c, G'),(2,'LASD,wer,yy')
Select A.id,upper(Left(b.Data,1)) + lower(Right(b.data, Len(b.data) - 1)) From Test_Table A
Cross Apply dbo.split(A.data,',') B
Drop table Test_Table -
My lov results into the return value instead of the display value in APEX
Hi,
For 1 of the columns I'm representing in APEX, I choose 'Display as text, based on a lov'. I'm using:
select aan.id||', '||r.naam||', '||a.woonplaats d, aan.id r
from wmo_aanvragen aan
, wmo_dossiers d
, wmo_relaties r
, wmo_adressen a
where d.avg_1_id = aan.id
and d.rel_nummer = r.nummer
and a.rel_nummer = r.nummer
and a.id = (select min(e.id) from wmo_adressen e where e.REL_NUMMER = r.nummer
and e.EIND_DATUM is null)
and d.id = (select min(f.id) from wmo_dossiers f where f.AVG_1_ID = aan.id)
But somehow it displays the 'aan.id' value instead of the display value. Does anyone know howcome?? In TOAD it works fine
Niels
Edited by: user6394263 on 10-apr-2009 1:22Hello Niels,
Your LOV Displays your concatenated value, but returns the "aan.id" (into the Form field), just as expected. If you want to show the description on your Form, use a PopUp LOV - Displays Description Return Key value
Greetings,
Roel
http://roelhartman.blogspot.com/
You can reward this reply by marking it as either Helpful or Correct ;-) -
Rendered=false column is not returning value in simpleSearch Query Region.
Hi Guru's,
I have a simpleSearchPanel with two search columns Order Number (Rendered=true, i.e Visible to User in the form) and Order Id(Rendered=False, i.e Non visible to User in the form) which are getting values from LOV. The LOV selection Order Number and Order Id are getting values and Order Number column is rendered true(visible) query able to return the values, but Order Id is not getting values because Rendered=False/Not visible Field.
Unfortunately i can't make OrderId filed as "formValue" because of simpleSearchPanel (autoCustoomizationCritirea) query region.
I appreciate your help.
Regards
Pathiits not the problem with simpleSearchPanel, it is the messageComponentLayout within simpleSearchPanel which is restricting the formValue.
just change the region style to defaultDoubleColumn and create the formValue into it.
This should solve your problem..
--Prasanna
Maybe you are looking for
-
Extremely high memory usage on ideapad u310
Hi all, I've got a problem with my ideapad u310 touch running windows 8.1. When doing completely nothing (just staring at the desktop with no programs running) my laptop uses ~55% of ram. I find this extremely high, when i open a few chrome tabs and
-
4s: Cannot Restore iOS 6.01 through iTunes - no error code
Please accept my apologies if this has been covered elsewhere - I've spent hours now going through dozens of sites and cannot get anywhere. I'm having issues with battery life on a 4S (as well as FB not working, but that's minor) after updating to iO
-
i hav mde an application form thats connects with a php database uSING WAMP. now the problem i m facing is that i want to deploy this application in to my own server.... i dnt knw wat to put in webroot=? and rooturl=?...... in wamp i used to put webr
-
i know this is trivial code, that is simple yet i cant get it i have the following method public static void let(char x){ if (x == 'a') return; x = (char) ((int) let('a' + 1)); System.out.print(x + " "); here is the error i get "let(char) in lab7 can
-
MacBook Pro W/30-inch Cinema Display
Is there a working solution for this yet? is it possible to use the 30 inch or even a 23 inch? If so how?