Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I tested the code bellow with success over ifx 11.50 FC9.</p> <p><code>WARNING:</code> I used an undocumented function. I don't know if is safe use it over production... </p> <p>How works: I "transform" the row to ROW datatype ; use a internal function called collectionoutput to convert this ROW to lvarchar and then count how much comma have (columns separator).</p> <p>Pre-req : Permission to create/run the function; the temp table must have 1 line at least.</p> <pre><code>--drop function count_cols; create function count_cols ( cols lvarchar(4000) ) returning int ; define i int; define ncols int; define isstring int; let ncols = 1; let isstring = 0; for i = 1 to length(cols) if substr(cols,i,1) = "'" and isstring = 1 then let isstring = 0 ; continue for; end if ; if substr(cols,i,1) = "'" and isstring = 0 then let isstring = 1 ; continue for; end if ; if isstring = 0 and substr(cols,i,1) = ',' then let ncols = ncols+1 ; end if ; end for ; return ncols; end function ; --drop table t2; create temp table t2 ( cod int, desc char(100) default 'test', data datetime year to second default current year to second , number int); insert into t2 (cod)values (0); insert into t2 (cod)values (0); insert into t2 values (1,'teste,teste,teste,teste',current, 0); select * from t2; select collectionoutput(multiset(select first 1 * from t2 where cod = 1)) from sysmaster:sysdual ; select count_cols(collectionoutput(multiset(select first 1 * from t2 where cod = 1))) from sysmaster:sysdual; </code></pre> <p>my outputs (dbaccess)</p> <pre><code>cod 0 desc test data 2013-03-22 11:36:37 number cod 0 desc test data 2013-03-22 11:36:37 number cod 1 desc teste,teste,teste,teste data 2013-03-22 11:36:37 number 0 (expression) MULTISET{ROW(1 ,'teste,teste,teste,teste ','2 013-03-22 11:36:37',0 )} (expression) 4 </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload