Display data in the form of values separated by commas - need help
Hi allI have some data formatted in the way below. The ID of the drug are the primary keys of the table and the first 9 digits in the drug ID are the same. They can be separated based on the last two digits.
Type of drug drug ID
00603107554 respiratory
00603107556 cough and cold
Antitussive-00603107558
I want that data to be formatted as
Type of drug drug ID
006031075 respiratory, cough and colds, Antitussive
I want to cut the last two characters, and format data. And the types must be displayed in the form of values separated by commas. Can someone help me?
Thanks in advance
Rambeau
WITH t AS (SELECT '00603107554' Drug_ID, 'Respiratory' Drug_Type FROM DUAL
UNION
SELECT '00603107556', 'Cough and Cold' FROM DUAL
UNION
SELECT '00603107558', 'Antitussive' FROM DUAL)
SELECT Drug_id, SUBSTR (SYS_CONNECT_BY_PATH (Drug_Type, ','), 2) Drug_Types
FROM (SELECT SUBSTR (drug_id, 1, LENGTH (drug_id) - 2) drug_id,
Drug_Type,
ROW_NUMBER ()
OVER (PARTITION BY SUBSTR (drug_id, 1, LENGTH (drug_id) - 2)
ORDER BY Drug_Type)
rn
FROM t)
WHERE CONNECT_BY_ISLEAF = 1
START WITH rn = 1
CONNECT BY PRIOR rn = rn - 1 AND PRIOR drug_id = drug_id
DRUG_ID DRUG_TYPES
006031075 Antitussive,Cough and Cold,Respiratory
just a note, I wonder if blushadow could consider adding techniques agg string to its very useful faq section because it seems a good
request.
Published by: pollywog on April 14, 2011 06:42
Published by: pollywog on April 14, 2011 06:43
Tags: Database
Similar Questions
-
Timekeeper group does not display data from the former employee
When you set up a group of timekeeper, we cannot find any former employees.
If a employee leaves mi period... and if the timekeeper may not display former employees, how would (s) he enter/edit data?
Thank you
Alex
Hi Alex,
Yes, the final processing date should be later or null if you are not allowed to change the date of the final trial and you can try to change the date of entry into time guardian Group screen for before January 31, 2016 "and find the employee. "
Kind regards
-
How to search for a particular text values separated by commas
Hello
I have a table for example. TB_Fruits.
In that I have a FruitsName (Varchar) column
In this column I store the string of values separated by commas.
Select FruitsName in the tb_fruits;
Result: orange, banana, Apple
Now the question is suppose that if I try inserting one of these fruits once again name, then it must not allow me to insert.
Suppose that now if I try to insert ('grapes, banana')
or
(Apple, grape")
the orange, banana, Apple may be in any position.
How to check if one of these names exist already or not in the fruitsname column?
I can't use INstr function here as or. because the position is not fixed chain even not.
Appreciate any help.Hmm, OK, the BASIC_LEXER in the documentation is specified is useful to "spaces separate languages". So not really a good suggestion from my side ;-)
Okay, so a few different choices, you can play with:
SQL> create table tb_fruits ( 2 fruitsname varchar2(60) 3 ) 4 / Table created. SQL> begin 2 insert into tb_fruits values ('BANANA,APPLE'); 3 insert into tb_fruits values ('YELLOW BANANA,ORANGE'); 4 insert into tb_fruits values ('GREEN APPLE,YELLOW ORANGE'); 5 insert into tb_fruits values ('APPLE,GREEN BANANA'); 6 commit; 7 end; 8 / PL/SQL procedure successfully completed.
Option 1:
Make a outdated AS operator. It just won't be fast because it's more likely will be full table scan (or scan restricted index full).
SQL> select fruitsname 2 from tb_fruits 3 where ','||fruitsname||',' like '%,'||'APPLE'||',%' 4 / FRUITSNAME ------------------------------------------------------------ BANANA,APPLE APPLE,GREEN BANANA SQL> select fruitsname 2 from tb_fruits 3 where ','||fruitsname||',' like '%,'||'BANANA'||',%' 4 / FRUITSNAME ------------------------------------------------------------ BANANA,APPLE SQL> select fruitsname 2 from tb_fruits 3 where ','||fruitsname||',' like '%,'||'YELLOW BANANA'||',%' 4 / FRUITSNAME ------------------------------------------------------------ YELLOW BANANA,ORANGE
Option 2:
Transform your data and replace the spaces with underscores. Which may or may not be a possibility for you. If your other data contains no underscores, you might fool your user interface using a view that replaces underscores with spaces when you select and a trigger before insert that replaces spaces with underscores to insert or update. Then, you can use the TEXT index.
SQL> create table tb_fruits2 as 2 select replace(fruitsname,' ','_') fruitsname 3 from tb_fruits 4 / Table created. SQL> begin 2 ctx_ddl.create_preference('mylex', 'BASIC_LEXER'); 3 ctx_ddl.set_attribute('mylex', 'printjoins', '_-'); 4 end; 5 / PL/SQL procedure successfully completed. SQL> create index fruitsname_idx on tb_fruits2 (fruitsname) 2 indextype is ctxsys.ctxcat 3 parameters ( 4 'stoplist ctxsys.empty_stoplist 5 LEXER mylex' 6 ) 7 / Index created. SQL> select fruitsname 2 from tb_fruits2 3 where catsearch(fruitsname,replace('YELLOW BANANA',' ','_'),null) > 0 4 / FRUITSNAME ------------------------------------------------------------ YELLOW_BANANA,ORANGE
(I used CTXCAT rather then CONTEXT indexes to keep simple search syntax, avoid SYNCHRONIZATION problems and others. You can use CONTEXT or CTXCAT as desired.)
Option 3:
Transform your data in XML format instead of values separated by commas. Then create a XMLIndex.
SQL> create table tb_fruits3 as 2 select xmltype('
') fruitsname 3 from tb_fruits 4 / Table created. SQL> create index fruitsname_xmlidx on tb_fruits3 (fruitsname) 2 indextype is xdb.xmlindex 3 / Index created. SQL> select fruitsname 2 from tb_fruits3 3 where xmlexists('$f/l[w="YELLOW BANANA"]' passing fruitsname as "f") 4 / FRUITSNAME --------------------------------------------------------------------------------'||replace(fruitsname,',',' ')||' YELLOW BANANA ORANGE (I used just 'l' for 'list of the words' and 'w' for 'word').
Option 4:
Create your own [url http://docs.oracle.com/cd/E11882_01/text.112/e24436/cdatadic.htm#i1008347] USER_LEXER instead of a variant of BASIC_LEXER. This would require allows you to create your own stored procedures for the index to be used, in which case you have complete control over what you set in the form of a token.
That's the different options I can think of right now ;-)
-
Hi Experts,
JDeveloper 12.1.3.0.0
I have a VO based on entity object. With a column of the VO is transient attribute (I created).
I need to call a stored procedure for each row in the transitional attribute and display the data in the form of af: table. As well as other attributes.
So can anyone suggest how can I achieve this?
Thank you
AR
I think that you need a stored function (which returns the value) in this case, is not?
Take a look at:
https://docs.Oracle.com/CD/B31017_01/Web.1013/b25947/bcadvgen005.htm
and search for:
Invoking stored function with only Arguments in
call your function in the Get attribute and return value accessor...
-
Left join of the two tables and multiple values into a single value separated by commas
Hello
I have following tables with their structures and their data as below.
CREATE TABLE 'BETODI '. "" BETINFO ".
(
VARCHAR2 (8 BYTE) "CURRENTPRESS."
ENABLE 'TYPEIDCONTAINER' VARCHAR2 (30 BYTE) NOT NULL
)
INSERT INTO Betinfo (Currentpress, typeidcontainer) VALUES ('A24G', 'PMC');
INSERT INTO Betinfo (Currentpress, typeidcontainer) VALUES ('A24D', 'Pensky-MARTENS');
INSERT INTO Betinfo (Currentpress, typeidcontainer) VALUES ("A25D", "CMP");
INSERT INTO Betinfo (Currentpress, typeidcontainer) VALUES ('A25G', 'PMC');
INSERT INTO Betinfo (Currentpress, typeidcontainer) VALUES ('A26D', 'PMC');
INSERT INTO Betinfo (Currentpress, typeidcontainer) VALUES ('A26G', 'PMC');
INSERT INTO Betinfo (Currentpress, typeidcontainer) VALUES ("A32G", "V-BFC3");
INSERT INTO Betinfo (Currentpress, typeidcontainer) VALUES ('A32D', "V-BFC2");
CREATE TABLE 'BETODI '. "" BETMASTER ".
(
ACTIVATE THE "CUREPRESS" TANK (5 BYTES) NOT NULL,
ACTIVATE THE "TYPE" VARCHAR2 (5 BYTE) NOT NULL,
NUMBER (5.0) "LASTPCIRIM".
)
INSERT INTO BetMaster (Curepress, type, lastpcirim) VALUES ('A24', '45 M 8', 15);
INSERT INTO BetMaster (Curepress, type, lastpcirim) VALUES ('A25', 42 16', 15);
INSERT INTO BetMaster (Curepress, type, lastpcirim) VALUES ("A26", 16' 45, 15);
INSERT INTO BetMaster (Curepress, type, lastpcirim) VALUES ("A27", '45 M 34', 16);
INSERT INTO BetMaster (Curepress, type, lastpcirim) VALUES ('A28', '45 M 34', 16);
INSERT INTO BetMaster (Curepress, type, lastpcirim) VALUES ('A29', '45 M 34', 16);
INSERT INTO BetMaster (Curepress, type, lastpcirim) VALUES ('A30', '45MCH', 15);
INSERT INTO BetMaster (Curepress, type, lastpcirim) VALUES ("A31", "45MCH", 16);
INSERT INTO BetMaster (Curepress, type, lastpcirim) VALUES ('A32', '45MCH', 16);
INSERT INTO BetMaster (Curepress, type, lastpcirim) VALUES ('A33', '45MCH', 16);
INSERT INTO BetMaster (Curepress, type, lastpcirim) VALUES ("A34", "45MCH", 16);
These two tables have left join as
BETMASTER. CUREPRESS = substr (BETINFO. CURRENTPRESS, 1, 3)
now I want to have the data in the two tables with fields Curepress, Lastpcirim, typeidcontainer.
Also something like
Make a group of typeidcontainer if this value is greater than 1 by press separated the values of semicolon (;)
So, for example above, we should be given as
A24 PMC 15; PENSKY-MARTENS
A25 15 PMC
A26 15 PMC
A27 16 (NULL)
A28 16 (NULL)
A30 15 (NULL)
A31 16 (NULL)
A32 16 BFC2-V; V BFC3
A33 16 (NULL)
A34 16 (NULL)
How could do?
My current request is as
Select distinct Curepress, lastpcirim, typeidcontainer
BETMASTER STD left join INF BETINFO
on the trim (STD. CUREPRESS) = substr (trim (INF. CURRENTPRESS), 1, 3)
but I am unable to get the values separated by commas.
Any help would be appreciated.
Thank you
Mahesh.
Hi, Mahesh,
If you want to only 1 row of output for each distinct combination of currentpress and lastpcirim? This sounds like a job for GROUP BY.
And you want the row to contain a list of all different typidcontainers-delimited? This sounds like a job for the aggregate LISTAGG function.
WITH joined_data AS
(
SELECT DISTINCT
MST.curepress, mst.lastpcirim, inf.typeidcontainer
OF betmaster STD
LEFT JOIN betinfo ON TRIM (mst.curepress) inf = SUBSTR (TRIM (inf.currentpress)
1
3
)
)
SELECT curepress, lastpcirim
LISTAGG (typeidcontainer, ',')
THE Group (ORDER BY typeidcontainer) AS container_list
OF joined_data
Curepress GROUP, lastpcirim
;
Unfortunately, you can't say LISTAGG (DISTINCT ...), so you should always get the separate containers how you already are. (Note that the subquery is just what you posted).
Thanks for posting the CREATE TABLE and INSERT statements; It is very useful. Don't forget to tell what version of Oracle you are using. LISTAGG was new in Oracle 11.2.
Why not add CHECK constraints (and perhaps triggers) to your tables, so that curepress and currentpress are not stored with the head or trailing spaces? Then you wouldn't need to use the PAD in queries like this, and your code would be simpler and more effective.
-
How to store the values separated by commas
Hi all
I have a table named discount, with discount_id (number data type) as one of the columns.
The user gives an entry as the value separated by commas, (ex: '123,27890,3543')
I use built-in proc that separates the values separated by commas.
Result set is stored in a table.DECLARE l_input VARCHAR2 (4000) := '123,27890,3543'; l_count BINARY_INTEGER; l_array DBMS_UTILITY.lname_array; BEGIN DBMS_UTILITY.comma_to_table ( list => REGEXP_REPLACE (l_input, '(^|,)', '\1x'), tablen => l_count, tab => l_array); DBMS_OUTPUT.put_line (l_count); FOR i IN 1 .. l_count LOOP DBMS_OUTPUT.put_line ( 'Element ' || TO_CHAR (i) || ' of array contains: ' || SUBSTR (l_array (i), 2)); END LOOP; END; Result: 3 Element 1 of array contains: 123 Element 2 of array contains: 27890 Element 3 of array contains: 3543
I would like to do a select on the table of discounts
Select * discount where discount_id (123, 27890 3543).
I am looking for options,
I need to create a new physical table as
Create table new_table (identification number) and bulk insert in this table.
Select * discount where discount_id in (select distinct id of new_table).
or
Is there a better way?
THX
Rod.Hello, SamFisher.
May be the recursive subquery factoring help you?WITH test(f1, n) AS (select '12, 15, 235', 1 from dual UNION all select f1, n + 1 from test where n < regexp_count('12, 15, 235', ',') + 1) SELECT regexp_substr(f1, '[^, ]+', 1, n) f FROM test
-
How to NOT send some form data when the form is submitted
Hello
I created a PDF form with radio buttons in the Group and the boxes. When I the form of data, such as values using the submit by e-mail button to send form data as XML or merge data into a spreadsheet files, I'll see the data values for radio buttons and checkboxes.
What I want here is to don't get the data values for some controls such as the boxes option, but no other controls like check boxes, in the XML or Excel worksheet after submission of the form. I know how to hide the controls in the form, but I have to the visible and active boxes on the form.
Is there a way to hide or do not send form data when the form data is submitted?
Thank you
Sam
Hi Kyle,.
That's exactly what I want! Once I have not selected any data binding, the field is in shape and active, but when submitted as XML or it merge with a spreadsheet, the field is gone.
Forgive me if I didn't my self clear in my question. Answer you is straight to the point.
Thank you very much!
Sam
-
ORA-01843: not a valid month - no dates on the form
When I submit a form I get the error "ORA-01843: not one month valid." I've now removed all the date of the form fields, and there is no triggers or constraints on the table concerning the date fields, so I'm at a loss on how to solve this problem. Any help much appreciated.
Edited by: Waggers April 11, 2012 03:38in lspq? a default value? in a select with to_date?
-
the data in the form has expired
I have this program:
Altas.cfm '...
< cfform format = "flash" action = "decide.cfm" >
....""
in the program decide.cfm «...»
< cfinput type = "button" label = "Back" onclick = "< javascript > histoy.go(-1) < / javascript >" >
..."
in this moment I return to the altas.cfm form, but in the screen show this message
"The form data has expired, please reload this page in your browser. How to avoid this message, how can reload this page form automatically?I have the solution:
Add the option timeout = "10", where 10 is the second that the form contains values, variables and forms in the form tag.
the solution is:
-
Unable to display data for the date where there is no entry in the table
Hello
I need a urgent, described below:
I have a table named as 'dirty', consisting of three columns: empno, sale_amt and sale_date.
(Please ref. The table with data script as shown below)
Now, if I run the query:
"select trunc (sale_date) sale_date, sum (sale_amt) total_sale of the sales group by order trunc (sale_date) by 1.
It then displays the data for the dates there is an entry in this table. But it displays no data for the
date in which there is no entry in this table.
If you run the Table script with data in your schema, then u will see that there is no entry for the 28th. November 2009 in
sales table. Now the above query displays data for the rest as his dates are in the table of the sale with the exception of 28. November 2009.
But I need his presence in the result of the query with the value "sale_date' as '28. November 2009 "and that of"total_sale"as
« 0 ».
Y at - there no way to get the result I need?
Please help as soon as POSSIBLE.
Thanks in advance.
Create the table script that contains data:
------------------------------------------
CREATE TABLE SALE
(
NUMBER EMPNO,
NUMBER OF SALE_AMT
DATE OF SALE_DATE
);
TOGETHER TO DEFINE
Insert into SALES
(EMPNO, SALE_AMT, SALE_DATE)
Values
(100, 1000, TO_DATE (DECEMBER 1, 2009 10:20:10 ',' DD/MM/YYYY HH24:MI:SS'));))
Insert into SALES
(EMPNO, SALE_AMT, SALE_DATE)
Values
(100, 1000, TO_DATE (NOVEMBER 30, 2009 10:21:04 ',' DD/MM/YYYY HH24:MI:SS'));))
Insert into SALES
(EMPNO, SALE_AMT, SALE_DATE)
Values
(100, 1000, TO_DATE (NOVEMBER 29, 2009 10:21:05 ',' DD/MM/YYYY HH24:MI:SS'));))
Insert into SALES
(EMPNO, SALE_AMT, SALE_DATE)
Values
(100, 1000, TO_DATE (NOVEMBER 26, 2009 10:21:06 ',' DD/MM/YYYY HH24:MI:SS'));))
Insert into SALES
(EMPNO, SALE_AMT, SALE_DATE)
Values
(100, 1000, TO_DATE (NOVEMBER 25, 2009 10:21:07 ',' DD/MM/YYYY HH24:MI:SS'));))
Insert into SALES
(EMPNO, SALE_AMT, SALE_DATE)
Values
(200, 5000, TO_DATE (NOVEMBER 27, 2009 10:23:06 ',' DD/MM/YYYY HH24:MI:SS'));))
Insert into SALES
(EMPNO, SALE_AMT, SALE_DATE)
Values
(200, 4000, TO_DATE (NOVEMBER 29, 2009 10:23:08 ',' DD/MM/YYYY HH24:MI:SS'));))
Insert into SALES
(EMPNO, SALE_AMT, SALE_DATE)
Values
(200, 3000, TO_DATE (NOVEMBER 24, 2009 10:23:09 ',' DD/MM/YYYY HH24:MI:SS'));))
Insert into SALES
(EMPNO, SALE_AMT, SALE_DATE)
Values
(200, 2000, TO_DATE (NOVEMBER 30, 2009 10:23:10 ',' DD/MM/YYYY HH24:MI:SS'));))
Insert into SALES
(EMPNO, SALE_AMT, SALE_DATE)
Values
(300, 7000, TO_DATE (NOVEMBER 24, 2009 10:24:19 ',' DD/MM/YYYY HH24:MI:SS'));))
Insert into SALES
(EMPNO, SALE_AMT, SALE_DATE)
Values
(300, 5000, TO_DATE (NOVEMBER 25, 2009 10:24:20 ',' DD/MM/YYYY HH24:MI:SS'));))
Insert into SALES
(EMPNO, SALE_AMT, SALE_DATE)
Values
(300, 3000, TO_DATE (NOVEMBER 27, 2009 10:24:21 ',' DD/MM/YYYY HH24:MI:SS'));))
Insert into SALES
(EMPNO, SALE_AMT, SALE_DATE)
Values
(300, 2000, TO_DATE (NOVEMBER 29, 2009 10:24:22 ',' DD/MM/YYYY HH24:MI:SS'));))
Insert into SALES
(EMPNO, SALE_AMT, SALE_DATE)
Values
(300, 1000, TO_DATE (NOVEMBER 30, 2009 10:24:22 ',' DD/MM/YYYY HH24:MI:SS'));))
COMMIT;
Any help will be necessary for me
Kind regardsWITH tab AS (SELECT TRUNC(sale_date) sale_date, SUM(sale_amt) total_sale FROM sale GROUP BY TRUNC(sale_date) ORDER BY 1 ) SELECT sale_date, NVL(total_sale,0) total_sale FROM tab model REFERENCE refmodel ON (SELECT 1 indx, MAX(sale_date)-MIN(sale_date) AS daysdiff , MIN(sale_date) minsaledate FROM tab) dimension BY (indx) measures(daysdiff,minsaledate) main main_model dimension BY (sale_date) measures(total_sale) RULES upsert SEQUENTIAL ORDER ITERATE(1000) until (iteration_number>refmodel.daysdiff[1]-1) ( total_sale[refmodel.minsaledate[1]+iteration_number]=total_sale[cv()] ) ORDER BY sale_date
using a clause type
Ravi Kumar
-
Can what method/class/object I use to send data to the form variable to BradySoft? I have a basic configuration of BradySoft label and I want to send it data of variable shape (a serial number) from Labview ActiveX. I joined guide Brady ActiveX programmers, but can't understand what to use for that.
P.S. I would call Brady or TekLynx tech support on this issue, but they have a strict policy while BradySoft supports ActiveX, but does not provide technical support assistance programming with it. I thought I would try the Forums OR.
Just an update. I could get this to work myself after a few days of playing with it (I suppose that the best way to learn!). I have attached a sample VI for anyone interested. Can we Kudo ourselves?
-
Selection of the date on the forms online
Hello. I have a Xperia z5 compact Marshmallow. When you enter a date on the forms online (Chrome), a calendar just for me to choose a date of. I have to scroll through each month for the previous dates. This means enter my birth date takes an eternity that I have to scroll every month to the year 1990. Is there a faster way to do this? Thank you.
I finally (accidentally) figured this out. If I click on the year he allows me to scroll directly to the year I want
-
While closing a link to expedia.ca a message come to say: the page you requested was created using data from the form. This page is no longer available. If you resend the data, any action that has been specified by the form will be repeated. You want to resubmit the data? When I click Yes or no, nothing happens except that the message just reappears. I can't get rid of it so I can't do anything else on my phone, except to answer a call if someone calls me. How can I get rid of this message from my phone? I tried to turn it works... even by leaving off the coast for 5 minutes before turning turn it back on. I can't even check my OS because I do not what anyone on my phone. I hope someone can help me with this.
Have you tried a battery pull? This should fix a problem as you described.
With your phone, remove the battery, then replace a minute later. This will do all sorts of wonderful things to your phone for free unclaimed memory, delete no cited source points and make your phone run smoothly.
Try it and let us know if it does the trick.
-
On the forms send us and receive in return, data in the form of fields will be not print. We can view the data, but the fields to print Virgin. How can I fix it?
OK, it's different. These text boxes are (at least engineering point of view) not considered form data, they are annotations (or markup). On your print dialogue box, you will see a group of "Comments & Form". Make sure that the first control is set to "Document and annotations:
After this change, you should see the markup of your impressions.
-
Send a reminder using the Dates of the form
Hi all.
I don't know what is the best way to send reminders (email), verification of the dates of the form.
For example:
There is a task assignment when the user enters 5 dates (day 1, day 2, day 2... etc)
Then I need to send emails to 'Xpath user' when the date system is: "day 1" - 24 hours (for example). "." The same date 2, day 3... etc.
How can I do?
I write the dates in the database need?
Some ideas?
Thank you very much.
Maria
You can use a gateway with a branch for each email that will be sent. Put a holding Point before sending email. Set days to wait as an XPath expression using get-days-from-dateTime-difference(current-date (), Date of the form). Subtract 1 for your less 24 hours.
Maybe you are looking for
-
I'm trying to see if I can remove vpn apps from my phone.
-
Satellite Pro L850-1DV: manual driver installation repair md5 command
Technical support could please provide some details on the correct order to install the downloaded drivers from Toshiba for a Satellite Pro L850-1DV for Windows 7? Also, is there another method to install the drivers to download and unzip the 44 sepa
-
computer cannot send file to the phone via bluetooth
Since I had to take the laptop back to factory settings I can receive photos via Bluetooth from phone but I only receive empty files from computer to phone. I tried to uninstall and reinstall but nothing seems to work. I am running windows 7.
-
Problem with the version of Adobe Premiere test
Hello guys,.IM quite new to the cloud just creative thing and yesterday I wanted to test adobe first. Then first, I downloaded the cloud creative and in the application, I downloaded creation and enforcement me has said that its installed now. But th
-
I created a new site where I created a version of the Tablet and a version phone... when I exported it in the HTML code... it created separate index's for the Tablet and phone version... now when I open the site on chrome... I was unable to check the