Counting commas in list
I am trying to count the number of commas in a valuelist. The
data from the list looks something like this:
2098433-2B30-A2D9-8A6EC36EC7111351,875933-2B30-A2D9-8A6EC36EC7111351,84920E33-2B30-A2D9-8A 6EC36EC7111351,30958E33-2B30-A2D9-8A6EC36EC7111351
With the enclosed code I am getting numberIn = 0
EmmanuelRuiz wrote:
> I am trying to count the number of commas in a
valuelist. The data from the
> list looks something like this:
>
>
>
2098433-2B30-A2D9-8A6EC36EC7111351,875933-2B30-A2D9-8A6EC36EC7111351,84920E33-2B
>
30-A2D9-8A6EC36EC7111351,30958E33-2B30-A2D9-8A6EC36EC7111351
>
> With the enclosed code I am getting numberIn = 0
>
> <cfset myList = ValueList(getLoginHistoryAll.id)>
> <cfset numberIn = ListValueCount(myList,",")>
>
> #numberIn#
>
it will be 0, since listvaluecount function uses "," as
default list
delimiter, thus "," will not be part of the list and you
can't use it as
value you are looking for
use listlen() function instead: #listlen(mylist, ",")-1# will
give you
the number of commas in your valuelist
Azadi Saryev
Sabai-dee.com
Vientiane, Laos
http://www.sabai-dee.com
Similar Messages
-
Count the number of elements in comma seperated list of values
Hello Friends,
I have a string with comma seperated list of values say
String v = 34343,erere,ererere,sdfsdfsdfs,4454,5454,dsfsdfsfsd,fsdfsdfsdfs,dfdsfsdfsdfs,sdsfdsf,ererdsdsd45454,fsdfsdfs
Want to count how many elements are existing in this string .
Thanks/KumarHi, Kumar,
REGEXP_COUNT, which Hoek used, is handy, but it only works in Oracle 11. Which version of Oracle are you using?
In any version of Oracle, you can count the commas by seeing how much the string shrinks when you remove them.
LENGTH (str) + 1 - LENGTH (REPLACE (str, ',')) Can str have multiple commas in a row? What if there's nothing between consecutive commas, or nothing by whitespace? Can str begin or end with a comma? Can str consist of nothing but commas? Depending on your answers, you may have to change things. You might want
REGEXP_COUNT ( str
, '[^,]+'
I hope this answers your question.
If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all tables involved, and also post the results you want from that data.
Explain, using specific examples, how you get those results from that data.
Always say which version of Oracle you're using.
See the forum FAQ {message:id=9360002} -
How to get distinct values in a comma separated list of email addresses?
Hi Friends,
I have a cursor which fetches email address along with some other columns. More than one record can have same email address.
Ex
CURSOR C1 IS
SELECT 1 Buyer,'XX123' PO, '[email protected]' Buyer_email from dual
UNION ALL
SELECT 2 Buyer,'XX223' PO, '[email protected]' Buyer_email from dual
UNION ALL
SELECT 1 Buyer,'XX124' PO, '[email protected]' Buyer_email from dual
UNION ALL
SELECT 2 Buyer,'XX224' PO, '[email protected]' Buyer_email from dualNow, i open the cursor write the contents into a file and also form a comma separated list of buyer emails as follows
for cur_rec in c1
LOOP
--write contents into a file
l_buyer_email_list := l_buyer_email_list||cur_rec.buyer_email||',';
END LOOP
l_buyer_email_list := RTRIM(l_buyer_email_list,',');
The buyer email list will be like: '[email protected],[email protected],[email protected],[email protected]'
Inorder to avoid duplicate email address in the list, i can store each of this value is a table type variable and compare in each iteration whether the email already exist in the list or not.
Is there any other simpler way to achieve this?
Regards,
Sreekanth Munagala.If you are using oracle version 11, you can use listagg function
with c as
(SELECT 1 Buyer,'XX123' PO, '[email protected]' Buyer_email from dual
UNION ALL
SELECT 2 Buyer,'XX223' PO, '[email protected]' Buyer_email from dual
UNION ALL
SELECT 1 Buyer,'XX124' PO, '[email protected]' Buyer_email from dual
UNION ALL
SELECT 2 Buyer,'XX224' PO, '[email protected]' Buyer_email from dual
select buyer, listagg(buyer_email,',') within group (order by buyer)
from c
group by buyer
order by buyerFor prior versions
{cod}
with c as
(SELECT 1 Buyer,'XX123' PO, '[email protected]' Buyer_email from dual
UNION ALL
SELECT 2 Buyer,'XX223' PO, '[email protected]' Buyer_email from dual
UNION ALL
SELECT 1 Buyer,'XX124' PO, '[email protected]' Buyer_email from dual
UNION ALL
SELECT 2 Buyer,'XX224' PO, '[email protected]' Buyer_email from dual
select buyer, rtrim(xmlagg(xmlelement(e,buyer_email||',').extract('//text()')),',')
from c
group by buyer
order by buyer -
Obtaining comma-separated list of text values associated with bitwise flag column
In the table msdb.dbo.sysjobsteps, there is a [flags] column, which is a bit array with the following possible values:
0: Overwrite output file
2: Append to output file
4: Write Transact-SQL job step output to step history
8: Write log to table (overwrite existing history)
16: Write log to table (append to existing history)
32: Include step output in history
64: Create a Windows event to use as a signal for the Cmd jobstep to abort
I want to display a comma-separated list of the text values for a row. For example, if [flags] = 12, I want to display 'Write Transact-SQL job step output to step history, Write log to table (overwrite existing history)'.
What is the most efficient way to accomplish this?Here is a query that gives the pattern:
DECLARE @val int = 43
;WITH numbers AS (
SELECT power(2, n) AS exp2 FROM (VALUES(0), (1), (2), (3), (4), (5), (6)) AS n(n)
), list(list) AS (
SELECT
(SELECT CASE WHEN exp2 = 1 THEN 'First flag'
WHEN exp2 = 2 THEN 'Flag 2'
WHEN exp2 = 4 THEN 'Third flag'
WHEN exp2 = 8 THEN 'IV Flag'
WHEN exp2 = 16 THEN 'Flag #5'
WHEN exp2 = 32 THEN 'Another flag'
WHEN exp2 = 64 THEN 'My lucky flag'
END + ', '
FROM numbers
WHERE exp2 & @val = exp2
ORDER BY exp2
FOR XML PATH(''), TYPE).value('.', 'nvarchar(MAX)')
SELECT substring(list, 1, len(list) - 1)
FROM list
Here I'm creating the numbers on the fly, but it is better to have a table of numbers in your database. It can be used in many places, see here for a short discussion:
http://www.sommarskog.se/arrays-in-sql-2005.html#numbersasconcept
(Only read down to the next header.)
For FOR XML PATH thing is the somewhat obscure way we create concatenated lists. There is not really any using trying to explain how it works; it just works. The one thing to keep in mind is that it adds an extra comma at the end and the final query strips
it off.
This query does not handle that 0 has a special meaning - that is left as an exercise to the reader.
Erland Sommarskog, SQL Server MVP, [email protected] -
Cycle Count Entries Form not showing specific employee name in "Counted By" LOV List
Cycle Count Entries Form not showing specific employee name in "Counted By" LOV List.But the Employee is active . Is there any setup for this activity?
Hi,
This is because the query is excluding the current site you are trying to modify since it is actually in the report.
You can include in your query:
or site_id = :Pxx_SITE_ID
Where Pxx_SITE_ID is the item holding the site_id value and xx is your page number.
Thank you,
Erick -
How to display the count of a list item in Sharepoint Designer?
How to display the count of a list item in Sharepoint Designer? please reply with the proper code line to add for this.
Hello,
What version of sharepoint you are using? Try below approach:
http://sharepointlogics.com/2010/03/total-count-of-items-in-list-in.html
Hope it could help
Hemendra: "Yesterday is just a memory,Tomorrow we may never see"
Whenever you see a reply and if you think is helpful, click "Vote As Helpful"! And whenever
you see a reply being an answer to the question of the thread, click "Mark As Answer
Please feel free to unmark answer if does not resolves your problem. -
Powershell script to count number of list and library items in site collection
We are identifying large lists in our 2010 SP environment and I'm attempting to write code to output the total number of list items in a site collection. I'm using the code below but it only displays column data for title and url.
What do I need to add so it can count the number of items in each sharepoint list and library?
Get-SPSite -WebApplication http://sharepoint -Limit All |
Select -ExpandProperty AllWebs |
Select -ExpandProperty Lists |
Select ParentWebUrl, Title
I'm referencing
http://sharepointpromag.com/sharepoint/windows-powershell-scripts-sharepoint-info-files-pagesweb-partsPlease find belwo script, it will iterarte through all the folder/Subfoder to get the item counts from all list and library, you can modify this script to run this at site collection scope:
Note: save the script in .ps1 file and execute the script as described below to get log file, it will save the log file out.txt in seleted directory:
e.g.PS D:\PowershellScripts> .\ListItemCount.ps1 > out.txt
$SPWebApp = Get-SPWebApplication "http://weburl.com/"
foreach ($SPSite in $SPWebApp.Sites)
if ($SPSite -ne $null)
foreach ($SPWeb in $SPSite.AllWebs)
foreach ($list in $SPWeb.Lists)
$ListURL = $SPWeb.url + "/" + $list.RootFolder.Url
Write-Output $ListURL
[Microsoft.SharePoint.SPQuery]$query = New-Object Microsoft.SharePoint.SPQuery
#$query.Folder = fldr;
#Recursive Scope....
$query.ViewAttributes = "Scope='Recursive'"
$allitems = $list.GetItems($query);
$filecount = $allitems.Count;
Write-Output " No of item: " $filecount
if ($SPWeb -ne $null)
$SPWeb.Dispose()
if ($SPSite -ne $null)
$SPSite.Dispose()
You can update the code to get any specific list type item count, using if($list.BaseType -eq "DocumentLibrary") condition:
if($list.BaseType -eq "DocumentLibrary")
$ListURL = $SPWeb.url + "/" + $list.RootFolder.Url
Write-Output $ListURL
[Microsoft.SharePoint.SPQuery]$query = New-Object Microsoft.SharePoint.SPQuery
#$query.Folder = fldr;
#Recursive Scope....
$query.ViewAttributes = "Scope='Recursive'"
$allitems = $list.GetItems($query);
$filecount = $allitems.Count;
Write-Output " No of item: " $filecount
if ($SPWeb -ne $null)
$SPWeb.Dispose()
If my contribution helps you, please click Mark As Answer on that post and Vote as Helpful
Thanks, ShankarSingh -
PL/SQL CLOB and comma seperated list
Hi,
i´am beginner!
I have a table with a clob field with a comma separeted list. The content can be '', '44' or '44,55...' as an example.
So how can i get the values in clob and search another table?
Something like...
select clob from table1
each clob
select * from table2
where table2.id = (clob value)
... do somtheing further
Thank you,
JochenOk... it depends...
If you know your CLOB is going to hold a list of values that are less than 4000 characters, you can simply treat the CLOB as a VARCHAR2 and perform one of the many techniques for splitting that string to give a varying IN list...
e.g.
SQL> ed
Wrote file afiedt.buf
1 select *
2 from emp
3 where ename in (
4 with t as (select '&input_string' as txt from dual)
5 select REGEXP_SUBSTR (txt, '[^,]+', 1, level)
6 from t
7 connect by level <= length(regexp_replace(txt,'[^,]*'))+1
8* )
SQL> /
Enter value for input_string: SCOTT,JAMES
old 4: with t as (select '&input_string' as txt from dual)
new 4: with t as (select 'SCOTT,JAMES' as txt from dual)
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
7788 SCOTT ANALYST 7566 19-04-1987 00:00:00 3000 20
7900 JAMES CLERK 7698 03-12-1981 00:00:00 950 30
SQL>(or alternatively read here: http://tkyte.blogspot.com/2006/06/varying-in-lists.html)
If it's going to exceed the SQL VARCHAR2 limit of 4000 characters then you would most likely need to create a Pipelined function to split your CLOB into it's component values and return each one, thus allowing you to treat the results as a table of their own... e.g.
Note: this example is for a pipelined function that splits a varchar2 string, but you could adapt it to use the DBMS_LOB package to split a CLOB in the same manner...
SQL> CREATE OR REPLACE TYPE split_tbl IS TABLE OF VARCHAR2(4000);
2 /
Type created.
SQL> CREATE OR REPLACE FUNCTION split (p_list VARCHAR2, p_delim VARCHAR2:=' ') RETURN SPLIT_TBL PIPELINED IS
2 l_idx PLS_INTEGER;
3 l_list VARCHAR2(4000) := p_list;
4 l_value VARCHAR2(4000);
5 BEGIN
6 LOOP
7 l_idx := INSTR(l_list, p_delim);
8 IF l_idx > 0 THEN
9 PIPE ROW(SUBSTR(l_list, 1, l_idx-1));
10 l_list := SUBSTR(l_list, l_idx+LENGTH(p_delim));
11 ELSE
12 PIPE ROW(l_list);
13 EXIT;
14 END IF;
15 END LOOP;
16 RETURN;
17 END SPLIT;
18 /
Function created.
SQL> SELECT column_value
2 FROM TABLE(split('FRED,JIM,BOB,TED,MARK',','));
COLUMN_VALUE
FRED
JIM
BOB
TED
MARK
SQL> create table mytable (val VARCHAR2(20));
Table created.
SQL> insert into mytable
2 select column_value
3 from TABLE(split('FRED,JIM,BOB,TED,MARK',','));
5 rows created.
SQL> select * from mytable;
VAL
FRED
JIM
BOB
TED
MARK
SQL>... and once you can treat the values like a table it's just a case of using it like you would any table of values i.e. join on it or use it in an IN statment with a subselect etc. -
Problem using comma separated list with nested table element
Hi,
I have a comma separated list like that:
H23004,H24005,T7231,T8231,T9231And want to create a function which is creating a where clause for each element with an output like that:
UPPER('H23004') IN (UPPER(charge))
OR UPPER('H23005') IN (UPPER(charge))
OR UPPER('T7231') IN (UPPER(charge))
OR UPPER('T8231') IN (UPPER(charge))
OR UPPER('T9231') IN (UPPER(charge))Here is my test function which doesn't work correctly:
create or replace function FNC_LIST_TO_WHERE_CLAUSE(v_list in VARCHAR2) return varchar2 is
-- declaration of list type
TYPE batch_type IS TABLE OF pr_stamm.charge%TYPE;
-- variable for Batches
v_batch batch_type := batch_type('''' || replace(v_list,',',''',''') || '''');
return_script varchar2(1000);
BEGIN
-- loop as long as there are objects left
FOR i IN v_batch.FIRST .. v_batch.LAST
LOOP
--DBMS_OUTPUT.PUT_LINE(offices(i));
-- create where clause
IF i = 1 THEN
return_script := 'UPPER(' || v_batch(i) || ') IN (UPPER(charge))';
ELSE
return_script := return_script || ' OR UPPER(' || v_batch(i) || ') IN (UPPER(charge))';
END IF;
END LOOP;
return (return_script);
end;The out put looks like that:
UPPER('H23004','H24005','T7231','T8231','T9231') IN (UPPER(charge))I have no idea what I do wrong? It calculates the amount of array element wrong! (v_batch.LAST should be 5.)
v_batch.FIRST = 1
v_batch.LAST = 1
Regards,
Tobiastry this....
declare
text varchar2(1000) := 'H23004,H24005,T7231,T8231,T9231';
v_where varchar2(1000);
begin
text := text||',';
while instr(text,',') <> 0
loop
v_where := v_where || 'UPPER('''||substr(text,1,instr(text,',',1)-1)||''' IN (UPPER(charge)) OR ';
text := substr(text,instr(text,',',1)+1);
end loop;
v_where := substr(v_where,1,length(v_where)-3);
dbms_output.put_line(v_where);
end;
convert this one into function ... -
Get particular item count in sharepoint list using designer Workflow
How to get specific item count in sharepoint list using designer Workflow 2013.
For Example
Title Count
x 1
y 1
x 2
x 3HI Thiru,
Can you please elaborate your problem. Is that Title and count are your list columns you want to fetch the value of count column based on title?
If my interpretation in not wrong, then it's not possible in SPD with the case you have mentioned in your question as Title='x' is having 3 different entries and SPD activity will always return first matching item and ignore the rest with warning message.
Regards,
Brij K -
Suppliers is a field containing a comma delimited list of
Supplier ID's.
When a supplier logs in they should be able to view all the
auctions that they have been registered for
i.e if their supplierID is in the suppliers field.
have tried this and get an error:
<CFQUERY NAME="GetAuctions"
DATASOURCE="#Application.Datasource#">
SELECT * FROM Auctions
WHERE '#Session.SupplierID#' IN 'Auctions.Suppliers'
</CFQUERY>
have tried this and recordcount is 0 when it should be 3:
<CFQUERY NAME="GetAuctions"
DATASOURCE="#Application.Datasource#">
SELECT * FROM Auctions
WHERE '#Session.SupplierID#' LIKE 'Auctions.Suppliers'
</CFQUERY>You should avoid having a list value in a field and normalise
your table. But if you want to stick with your style(which is not
advisable), maybe you can do this. I believe your supplier id is a
string so the code below may cause slowness in your system:
<CFQUERY NAME="GetAuctions1"
DATASOURCE="#Application.Datasource#">
SELECT Suppliers FROM Auctions
</CFQUERY>
<cfoutput query="GetAuctions1">
<CFQUERY NAME="GetAuctions2"
DATASOURCE="#Application.Datasource#">
SELECT * FROM Auctions
WHERE '#Session.SupplierID#' IN(<cfqueryparam
values="#Suppliers#" cfsqltype="CF_SQL_VARCHAR" list="Yes">)
</CFQUERY>
</cfoutput>
But if your supplier id is a numeric value. then you can do
this:
<CFQUERY NAME="GetAuctions"
DATASOURCE="#Application.Datasource#">
SELECT A1.* FROM Auctions A1
WHERE #Session.SupplierID# IN(SELECT A2.Suppliers FROM
Auctions A2 WHERE A2.your_primary_key_for_table_Auctions =
A1.your_primary_key_for_table_Auctions)
</CFQUERY> -
Too many commas in my comma delimited list
I'm trying to merge several pdf files into one by using the cfpdf tag (action="merge"). In the source attribute, you can enter a comma delimited list of file paths to merge the pdf files together. I'm thinking that Adobe could have picked a better delimiter though because it breaks if there is a comma any one of the file names. I've tried using replace() to replace the commas in my filenames with chr(44) before passing it to the cfpdf tag, but it still breaks. Any ideas on how to accommodate this? I'm trying to prevent having to copy hundreds of files to a temp directory, then use the directory attribute instead, then delete the temp directory. That just seems like such a waste of resources...
Thanks!cfpdfparam is a WIN! Thanks for the heads up, i had no idea that you could use the tag like that.
<cfpdf
action = "merge"
destination = "C:\Inetpub\mydir\secure\test\output_merge.pdf"
overwrite = "yes">
<cfpdfparam source = "C:\Inetpub\mydir\secure\test\0003. A-001 - Restaurant, Floor Plan.pdf">
<cfpdfparam source = "#expandPath('/secure/test/0001. G-001 - General.pdf')#">
<cfpdfparam source = "#expandPath('/secure/test/0002. G-101 - General Information.pdf')#"></cfpdf>
Works Great, Thanks! -
String Array to Comma spearated list
Hey Guys,
I have a struts application that receives a string[] array of product numbers corresponding to those that a user has selected. I need to put these into a SQL query in the form of "PRODUCTS.PRODUCT_NAME IN ('product1','product2','product3')" -- in otherwords, a comma separated list, with each item wrapped in apostrophes.
I can successfully drop in individual items using notation like the following:
<c:set var="where" value="and PRODUCTS.PRODUCT_NAME IN ('${formChecker4.selectedProductListForm2[0]}')" />What I'm not sure about is the best way to create my comma separated list. In my formChecker4 class, I have getSelectedProductListForm2() and setSelectedProductListForm2() methods, but these expect and return a string[] array, not a plain string. Does anyone have any handy suggestions for converting my array into a string, either within my class or within my EL tags?
Here's some of my formChecker4 class:
private String[] selectedProductListForm2;
public String[] getSelectedProductListForm2() {
return this.selectedProductListForm2;
public void setSelectedProductListForm2(String[] selectedProductListForm2) {
if (selectedProductListForm2.length == 0) {
this.selectedProductListForm2 = null;
} else {
this.selectedProductListForm2 = selectedProductListForm2;
}1) don't do it in JSP
2) [Use a prepared statement. |http://java.sun.com/docs/books/tutorial/jdbc/basics/prepared.html] -
Is it possible to convert a table of values into a comma-delimited-list?
Hi,
I'd like to turn the following dataset:
Parent | Child
Charles | William
Charles | Harry
Anne | Peter
Anne | Zara
Andrew | Beatrice
Andrew | Eugenie
into this:
Parent | Children
Charles | Diana,Camilla
Anne | Peter,Zara
Andrew | Beatrice,Eugenie
In other words, I'd like to take a list of values pertaining to some key and produce them as a comma-delimited-list.
I know its is possible in T-SQL although the method is a bit of a nasty hack. Is it possible in PL-SQL?
Thaks in advance
JamieHi,
With model clause (10g)
with t as(
select 'Charles' parent, 'William' child from dual union
select 'Charles', 'Harry' from dual union
select 'Anne', 'Peter' from dual union
select 'Anne', 'Zara' from dual union
select 'Andrew', 'Beatrice' from dual union
select 'Andrew', 'Eugenie' from dual
select parent,substr(res,2) res
from t
model
return updated rows
partition by ( parent)
dimension by ( row_number()over(partition by parent order by child) rn)
measures(child, cast( null as varchar2(4000)) as res)
rules
iterate(100000)
until(presentv(res[iteration_number+2],1,0)=0)
( res[0]=res[0]||','||child[iteration_number+1]);
PARENT RES
Anne Peter,Zara
Andrew Beatrice,Eugenie
Charles Harry,William
3 rows selected. -
Comma separated list for in ()
I am trying get a comma separated list of numbers (123,345,332,645) from a text field and pass it to a select statement that has in condition. The code looks something like
select a,b,c from tab1
where a in (:P1_SEARCH)
This works when I put only one value in the field. if I put two values like 345,453 it doesn't.
Can someone please explain this behaviour?
Thank you,
Kirtan DesaiKirtan,
Lots of info here: Re: Search on a typed in list of values .
Scott
Maybe you are looking for
-
I have 2 SLM 2008. One of the bought in 2008 still under Linksys while the second is already Cisco labeled I got in 2010 to extend my home network. Both are firmwared to 2.0.0.10. The first one yesterday failed to work. When I switch it off nad in a
-
Error 11222 after installing itunes 7.7 and i can'st connect to itunes.
is there a simple solution?
-
Worklist Integration in Peoplesoft Portal
Hello Everyone, I am exploring integration of worklist from HCM\ELM\CRM into PS Portal. As per the documentation, there is a delivered message WORKLIST_MSG for this integration and a delivered Application engine WL_REPLICATE for triggerring the Messa
-
I am on the road and need to make space to download pictures friom my camea
I am shooting RAW and jpeg and on this vacation trip I have taken a lot of pictures so I need to delete several to accommodate the new ones. This appears to be easier said than done. I have Camera roll pictures, Photo Stream pictures plus some Albums
-
Profit Center & Segment: difference?
Thanks in advance! Ferdinando