Count of elements in pipe delimited string
Hi,
Is there a way to count the number of elements produced by LISTAGG?
For instance, if LISTAGG produces:
Jan, Feb, Mar: output should be 3
Jan, Mar, Apr, Dec: output should be 4
LISTAGG is causing the confusion; I updated thread title and removed it.
Here is an example:
create table tmp_table (
delim_str varchar2(100 byte)
insert into tmp_table values ('Jan|Feb|Mar|Apr');
insert into tmp_table values ('Jan|Feb|Mar|Apr|May');
insert into tmp_table values ('Jan|Feb|Mar|Apr|May|June');
insert into tmp_table values ('Jan|Feb|Mar|Apr|May|June|July');
Commit;
Desired Output
Num_of_months
Delimited_Months
4
Jan|Feb|Mar|Apr
5
Jan|Feb|Mar|Apr|May
6
Jan|Feb|Mar|Apr|May|June
7
Jan|Feb|Mar|Apr|May|June|July
Similar Messages
-
How to Identify the count , If multiple parameters are passed using Pipe Delimited string
Hi,
We are passing Pipe delimited string to the parameter and I want to know how many values we are passing to the parameter.
Here is the example
Parameter.Grant: 24|34|54|67
I am using below expression, but it is not giving the right values. Please let me know if I am missing anything or is it possible.
=iif(parameters!Grant.Count>1,"Multiple value selected",parameters!Grant.Value)Hi NaveenCR,
According to your description, you used pipe delimited multi-value parameter in the report, you want to know how many values passed to the parameter. If that is the case, please refer to the following steps:
In Design view, click Text Box in the Toolbox.
On the design surface, click and then drag a box to the desired size of the text box.
Right-click inside of the text box, then click Expression.
In Expression text box, type the expression like below:
=iif(split(Parameters! Grant.Value,"|").Length>1," Multiple value selected",Parameters!Grant.Value)
The following screenshots are for your reference:
If you have any more questions, please feel free to ask.
Thanks,
Wendy Fu
If you have any feedback on our support, please click
here.
Wendy Fu
TechNet Community Support -
Pipe delimiter string into rows using regular expression
hi Can anyone please help writing pipe' l 'delimiter values to rows
sample data 'something1|something2|something3'
i tried with below query
SELECT LEVEL,
TRIM ('"' FROM RTRIM (REGEXP_SUBSTR ('something1|something2|something3' || '|',
'".*?"||[^|]*|',
1,
LEVEL
'|'
) sub_str
FROM dual
CONNECT BY LEVEL <= LENGTH (REGEXP_REPLACE ('something1|something2|something3' , '".*?"|[^|]*')) + 1SQL> ed
Wrote file afiedt.buf
1 with t as (select 'something1|something2|something3' as txt from dual)
2 -- end of sample data
3 select REGEXP_SUBSTR (txt, '[^|]+', 1, level)
4 from t
5* connect by level <= length(regexp_replace(txt,'[^|]*'))+1
SQL> /
REGEXP_SUBSTR(TXT,'[^|]+',1,LEVE
something1
something2
something3
SQL> -
Converting Delimited string to XML message
Hi,
We are trying to convert pipe delimited string into a xml schema using a XSD and BPEL funtion. Consider a scenario in which message has 5 fields with last as 2 optional fields. So the incoming string message can be like "1|2|3" or "1|2|3|4|5". In this case how the XSD should look like, since for each field we have to give "terminatedby" option in the XSD. So the issue is coming for element 3 where the delimiter can be "|" or "eol" (end of line). How to specify that ? Is there any option to use like "optionally terminated by?"
Any help will be appreciated.
Thanks,
Ramesh
Edited by: rameshchandra85 on 2 Aug, 2010 10:00 AMHi Ramesh,
You can use below XSD for input file of kind
1|2|3
1|2|3|4|5
1|2|3|4
1|2|3|4|5|6
<?xml version="1.0" encoding="UTF-8" ?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:nxsd="http://xmlns.oracle.com/pcbpel/nxsd"
targetNamespace="http://TargetNamespace.com/InboundService"
xmlns:tns="http://TargetNamespace.com/InboundService"
elementFormDefault="qualified"
attributeFormDefault="unqualified" nxsd:encoding="ASCII" nxsd:stream="chars" nxsd:version="NXSD">
<xsd:element name="Root-Element">
<xsd:complexType>
<xsd:choice minOccurs="1" maxOccurs="unbounded" nxsd:choiceCondition="terminated" nxsd:terminatedBy="|">
<xsd:element name="RECORD1" nxsd:conditionValue="1">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="C2" type="xsd:int" nxsd:style="terminated" nxsd:terminatedBy="|" nxsd:quotedBy=""">
</xsd:element>
<xsd:element name="C3" type="xsd:int" nxsd:style="terminated" nxsd:terminatedBy="${eol}" nxsd:quotedBy=""">
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="RECORD2" nxsd:conditionValue="2">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="C2" type="xsd:int" nxsd:style="terminated" nxsd:terminatedBy="|" nxsd:quotedBy=""">
</xsd:element>
<xsd:element name="C3" type="xsd:int" nxsd:style="terminated" nxsd:terminatedBy="|" nxsd:quotedBy=""">
</xsd:element>
<xsd:element name="C4" type="xsd:int" nxsd:style="terminated" nxsd:terminatedBy="|" nxsd:quotedBy=""">
</xsd:element>
<xsd:element name="C5" type="xsd:int" nxsd:style="terminated" nxsd:terminatedBy="${eol}" nxsd:quotedBy=""">
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="RECORD3" nxsd:conditionValue="3">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="C2" type="xsd:int" nxsd:style="terminated" nxsd:terminatedBy="|" nxsd:quotedBy=""">
</xsd:element>
<xsd:element name="C3" type="xsd:int" nxsd:style="terminated" nxsd:terminatedBy="|" nxsd:quotedBy=""">
</xsd:element>
<xsd:element name="C4" type="xsd:int" nxsd:style="terminated" nxsd:terminatedBy="${eol}" nxsd:quotedBy=""">
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="RECORD4" nxsd:conditionValue="4">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="C2" type="xsd:int" nxsd:style="terminated" nxsd:terminatedBy="|" nxsd:quotedBy=""">
</xsd:element>
<xsd:element name="C3" type="xsd:int" nxsd:style="terminated" nxsd:terminatedBy="|" nxsd:quotedBy=""">
</xsd:element>
<xsd:element name="C4" type="xsd:int" nxsd:style="terminated" nxsd:terminatedBy="|" nxsd:quotedBy=""">
</xsd:element>
<xsd:element name="C5" type="xsd:int" nxsd:style="terminated" nxsd:terminatedBy="|" nxsd:quotedBy=""">
</xsd:element>
<xsd:element name="C6" type="xsd:int" nxsd:style="terminated" nxsd:terminatedBy="${eol}" nxsd:quotedBy=""">
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<!--NXSDWIZ:D:\DBIN\ReadFile.txt:-->
<!--USE-HEADER:false:-->But in your case if you are getting 5 elements instead of 3 elements in some other file....Use the same and maipulate the last element afterwards.
I think we can not have an element definition for two scenarios.
Update you if i get any..
Regards
PavanKumar.M -
How to convert a delimited string to XML?
Hi there,
Please help me to convert a pipe delimited string into XML, e.g.
string -------SubName:abc|SuvValue:123|
required XML:
<ROWS>
<ROW>
<SubName>abc</SubName>
<SubValue>123</SubValue>
</ROW>
</ROWS>
or
string -------abc|123|
required XML:
<ROWS>
<ROW>
<SubName>abc</SubName>
<SubValue>123</SubValue>
</ROW>
</ROWS>
-----i am trying to first parse the string into a table type and then using the DBMS_XMLGen.getXML function but unable to get values from table type...
any prompt response is highly appriciated...
Regards, HassanHi Hassan,
If your version supports it (ie 10gR2 and upwards), you can use XQuery to directly parse the string and generate the XML :
SQL> SELECT XMLQuery(
2 '<ROWS>
3 <ROW> {
4 for $i in ora:tokenize($str,"\|")
5 return
6 if ($i) then element {substring-before($i,":")} {substring-after($i,":")}
7 else ()
8 } </ROW>
9 </ROWS>'
10 passing sys_xmlgen('SubName:abc|SubValue:123|') as "str"
11 returning content
12 ).getClobVal()
13 FROM dual;
XMLQUERY('<ROWS><ROW>{FOR$IINO
<ROWS><ROW><SubName>abc</SubName><SubValue>123</SubValue></ROW></ROWS>
Each element is built based on its name from the input string. -
Pipe delimited file on application server.
Hi , i m creating a text file on application server, i have written below code and file is getting created correctly. however, i want to create pipe delimited file. is there any method for this?
DATA : lv_line(173).
DATA : l_wa_itab_length(4) TYPE c VALUE '173'.
IF NOT p_tab[] IS INITIAL.
SORT p_tab.
OPEN DATASET p_file FOR OUTPUT IN TEXT MODE ENCODING NON-UNICODE.
IF sy-subrc NE 0.
MESSAGE 'Error on output file read' TYPE 'E'.
ELSE.
LOOP AT p_tab.
lv_line = p_tab.
TRANSFER lv_line TO p_file LENGTH l_wa_itab_length.
CLEAR p_tab.
CLEAR lv_line.
ENDLOOP.
CLOSE DATASET p_file.
ENDIF.
ENDIF.
REFRESH p_tab.i m pasting below my entire code.
REPORT zmigration_data_download.
FIELD-SYMBOLS: <fs_table> TYPE STANDARD TABLE.
DATA: d_table_ref TYPE REF TO data.
DATA: d_rfc_db_opt TYPE rfc_db_opt.
DATA: it_opt LIKE rfc_db_opt OCCURS 0 WITH HEADER LINE.
DATA: d_file TYPE string.
PARAMETERS: p_tab TYPE dd02l-tabname OBLIGATORY.
PARAMETERS: p_file LIKE rlgrap-filename OBLIGATORY DEFAULT '/usr/sap/tmp/test.txt'.
SELECT-OPTIONS: s_opt FOR d_rfc_db_opt NO INTERVALS.
START-OF-SELECTION.
REFRESH it_opt.
LOOP AT s_opt WHERE sign = 'I' OR option = 'EQ'.
it_opt-text = s_opt-low.
APPEND it_opt.
ENDLOOP.
CREATE DATA d_table_ref TYPE TABLE OF (p_tab).
UNASSIGN <fs_table>.
ASSIGN d_table_ref->* TO <fs_table>.
IF <fs_table> IS ASSIGNED.
CLEAR <fs_table>.
SELECT * FROM (p_tab) INTO TABLE <fs_table>
WHERE (it_opt).
IF sy-subrc EQ 0.
PERFORM download_file TABLES <fs_table> USING p_file.
MESSAGE i398(00) WITH 'Upload from SAP Successfull'.
ENDIF.
ENDIF.
*& Form download_file
text
-->P_<FS_TABLE> text
-->P_P_FILE text
FORM download_file TABLES p_tab USING p_file.
DATA : lv_line(173).
DATA : l_wa_itab_length(4) TYPE c VALUE '173'.
IF NOT p_tab[] IS INITIAL.
SORT p_tab.
OPEN DATASET p_file FOR OUTPUT IN TEXT MODE ENCODING NON-UNICODE.
IF sy-subrc NE 0.
MESSAGE 'Error on output file read' TYPE 'E'.
ELSE.
LOOP AT p_tab.
lv_line = p_tab.
TRANSFER lv_line TO p_file LENGTH l_wa_itab_length.
CLEAR p_tab.
CLEAR lv_line.
ENDLOOP.
CLOSE DATASET p_file.
ENDIF.
ENDIF.
REFRESH p_tab.
ENDFORM. " download_file -
Need file on Application server to be pipe delimited
Hi,
I want the file in the application server with headings and pipe delimited... I have used
IF NOT T_OUTPUT[] IS INITIAL.
Transfer the changed T_INPUTFILE data to application server.
OPEN DATASET V_FILEPATH FOR OUTPUT IN TEXT MODE ENCODING DEFAULT
MESSAGE V_MSG.
IF SY-SUBRC <> 0.
MESSAGE I008. " File could not be opened.
EXIT.
ENDIF.
Transferring Data
LOOP AT T_OUTPUT.
TRANSFER T_OUTPUT TO V_FILEPATH.
ENDLOOP.
CLOSE DATASET V_FILEPATH.
ENDIF.
But this is not giving me output like below...
RefDoc.No.
Text
Period
Year
9
Dummy Text
002
2006
How do I get a pipe delimited file on the application server ... ??Hi,
Check this..
DATA: V_STRING TYPE STRING.
LOOP AT T_OUTPUT.
DO.
ASSIGN COMPONENT SY-INDEX OF STRUCTURE T_OUTPUT TO <FS>.
IF SY-SUBRC <> 0 .EXIT .ENDIF.
IF SY-INDEX = 1.
V_STRING = <FS>.
ELSE.
CONCATENATE V_STRING '|' <FS> INTO V_STRING.
ENDIF.
ENDDO.
TRANSFER V_STRING TO V_FILEPATH.
ENDLOOP.
Thanks,
Naren -
Need a pipe delimiter after every field in the file on application server
Hi ,
i have to transport data in internal table to a file on application server.
I have done this successfully. But the problem is i have to put a pipe
delimiter after every field in the file on application server.
Could yoe plz help in this issue.
Thanks & Regards
Suresh kumar DHi Should,
I think the below code should solve your problem as i also had a similar type of requirement and this was the code i had used in my program.
FIELD-SYMBOLS: <FS> TYPE ANY.
DATA: L_FLINE TYPE STRING.
Open file for output
M_CHECK_SELSCR_FNMS O1 O.
LOOP AT I_TARGET.
Write records to file
DO.
ASSIGN COMPONENT SY-INDEX OF STRUCTURE I_TARGET TO <FS>.
IF SY-SUBRC EQ 0.
IF SY-INDEX EQ 1.
MOVE <FS> TO L_FLINE.
ELSEIF <FS> NE C_PIPE.
CONCATENATE L_FLINE C_PIPE <FS> INTO L_FLINE.
ELSE.
CONCATENATE L_FLINE <FS> INTO L_FLINE.
ENDIF.
ELSE.
TRANSFER L_FLINE TO W_SRVR_NM_O_O1.
EXIT.
ENDIF.
ENDDO.
ENDLOOP.
Close file
CLOSE DATASET W_SRVR_NM_O_O1.
IF SY-SUBRC EQ 0.
MESSAGE S208(00) WITH TEXT-M02.
ENDIF.
Regards
Sikha -
Extract data from Pipe Delimited file
Hi everybody,
Could someone provide me the command to extract data from a pipe delimited file ("|") using Open/Read Data set.
I mean eliminating the delimiter ("|") and just picking the data.
Thanks
MHere you go.. this code snippet parses the input file record by using pipe (variable lv_pipe) as separator, for tab separated file you can use lv_tab like wise...
TYPES: BEGIN OF ts_field,
field(50) TYPE c,
END OF ts_field,
tt_field TYPE TABLE OF ts_field.
DATA: ls_record TYPE string,
ls_input_data TYPE ts_input_data,
lv_tab TYPE x VALUE '09',
lv_pipe TYPE C VALUE '|',
ls_field TYPE ts_field,
lt_field_tab TYPE tt_field,
lv_field_index TYPE syindex,
lv_record_no TYPE syindex.
FIELD-SYMBOLS: <fs_field> TYPE ANY.
OPEN DATASET fv_file_path IN TEXT MODE FOR INPUT.
IF sy-subrc = 0.
DO.
lv_record_no = lv_record_no + 1.
READ DATASET fv_file_path INTO ls_record.
IF sy-subrc NE 0.
EXIT.
ELSE.
SPLIT ls_record AT lv_pipe INTO TABLE lt_field_tab.
CLEAR: lv_field_index, ls_input_data.
LOOP AT lt_field_tab INTO ls_field.
lv_field_index = lv_field_index + 1.
ASSIGN COMPONENT lv_field_index OF STRUCTURE
ls_input_data TO <fs_field>.
IF sy-subrc = 0.
<fs_field> = ls_field-field.
ENDIF.
ENDLOOP.
APPEND ls_input_data TO ft_input_data.
ENDIF.
ENDDO.
CLOSE DATASET fv_file_path. -
Hi guys,
I am uploading the data from a file which is in the application server and in pipe delimiter format.
This file in the format like .... let us take 100 records among those one record is header, 98 data records and one trailer record. These are seperated by the record locater like header with 0, data record with 1 and trailer with 9.
So what i am doing is uploading that file first of all into one internal table I_ARFILE, then splitting the data at pipe into 3 different internal tables. In the mean time I am doing the validations also for the number of records...
like there should not be more than one header, and one trailer........
here I am pasting my code.....
IF l_subrc = 0.
LOOP AT I_ARFILE.
READ TABLE I_ARFILE INTO WA_ARFILE.
SPLIT WA_ARFILE AT C_PIPE INTO WA_ARHEADER-P_RECTYPE
WA_ARHEADER-P_PRCID
WA_ARHEADER-P_SENDR
WA_ARHEADER-P_CDATE
WA_ARHEADER-P_CTIME
WA_ARHEADER-P_OBTYP
WA_ARHEADER-P_SEQNO
WA_ARHEADER-P_FRTXT.
IF WA_ARHEADER-P_RECTYPE = 0.
APPEND WA_ARHEADER TO I_ARHEADER.
DESCRIBE TABLE I_ARHEADER LINES V_ITABLINES.
VALIDATION FOR NUMBER OF HEADER RECORDS
IF V_ITABLINES <> 1.
MESSAGE 'NUMBER OF LINES READ ARE NOT SAME' TYPE 'E'.
LEAVE PROGRAM.
ENDIF.
CLEAR V_ITABLINES.
ELSE.
SPLIT I_ARFILE AT C_PIPE
INTO WA_ARITEM-P_RECTYPE
WA_ARITEM-p_xblnr
WA_ARITEM-p_bldat
WA_ARITEM-p_budat
WA_ARITEM-p_blart
WA_ARITEM-p_awkey
WA_ARITEM-p_kunnr
WA_ARITEM-p_xref1
WA_ARITEM-p_xref2
WA_ARITEM-p_xref3
WA_ARITEM-p_wrbtr
WA_ARITEM-p_zterm
WA_ARITEM-p_zuonr
WA_ARITEM-p_rstgr
WA_ARITEM-p_wskto
WA_ARITEM-p_sgtxt.
IF WA_ARITEM-P_RECTYPE = 1.
APPEND WA_ARITEM TO I_ARITEM.
ENDIF.
VALIDAITON FOR THE NUMBER OF DATA RECORDS.
DESCRIBE TABLE I_ARITEM LINES V_ITABLINES.
DESCRIBE TABLE I_ARFILE LINES V_ITABLINES1.
V_ITABLINES1 = V_ITABLINES1 - 2.
IF V_ITABLINES1 <> V_ITABLINES.
MESSAGE 'NUMBER OF LINES READ ARE NOT SAME' TYPE 'E'.
LEAVE PROGRAM.
ENDIF.
LOOP AT I_ARITEM.
V_BAL1 = V_BAL1 + I_ARITEM-P_WRBTR.
V_DIS = V_DIS + I_ARITEM-P_WSKTO.
ENDLOOP.
CHECKING THE SUM OF THE BALANCE AMOUNT OF ALL THE RECORDS AND BALANCE AMOUNT IN TRAILER RECORD
IF V_BAL1 <> WA_ARTRAILER-TOBAL.
MESSAGE 'TOTAL AMOUNT IS NOT EQUAL TO THE SUM OF ALL THE AMOUNTS' TYPE 'E'.
ELSE.
CHECKING THE SUM OF THE DISCOUNT AMOUNT OF ALL THE RECORDS AND BALANCE AMOUNT IN TRAILER RECORD
IF V_DIS <> WA_ARTRAILER-TODIS.
MESSAGE 'TOTAL DISCOUNT AMOUNT IS NOT EQUAL TO THE SUM OF ALL THE DISCOUNT AMOUNTS' TYPE 'E'.
ENDIF.
CLEAR V_BAL1.
APPEND WA_ARITEM TO I_ARITEM.
CLEAR WA_ARITEM.
CLEAR WA_ARFILE.
CLEAR V_ITABLINES.
CLEAR V_ITABLINES1.
ENDIF.
ENDLOOP.
ENDLOOP.
ENDIF.
ELSE.
READ TABLE I_ARFILE INTO WA_ARFILE INDEX V_ITABLINES.
SPLIT WA_ARFILE AT C_PIPE INTO WA_ARTRAILER-P_RECTYPE
WA_ARTRAILER-COUNT
WA_ARTRAILER-TOBAL
WA_ARTRAILER-TODIS.
IF WA_ARTRAILER-P_RECTYPE = 9.
APPEND WA_ARTRAILER TO I_ARTRAILER.
ENDIF.
DESCRIBE TABLE I_ARTRAILER LINES V_ITABLINES.
IF V_ITABLINES <> 1.
MESSAGE 'NUMBER OF LINES READ ARE NOT SAME' TYPE 'E'.
LEAVE PROGRAM.
ENDIF.
CLEAR WA_ARFILE.
CLEAR V_ITABLINES.
ENDIF.
*CLEAR WA_ARFILE.
CLEAR V_ITABLINES.
CLEAR V_ITABLINES1.
ENDIF.
ENDLOOP.
In this code something wrong like....
I have to modify this code so that i can split the file based on the record indicator to different internal tables.
if you see my code I am going wrong after i split the data into header internal table... did the validations then I put the else condition and split the same record again into 2nd internal table. But I have to take the second record once the first one is filled..........
Can any one guide me how to do that plz...... I am bit confused with this
SRIHi,
Please check , first you need to split the file and move header, item, trailer , then using these internal tables do your validations
DESCRIBE TABLE I_ARFILE LINES V_LIN
READ TABLE I_ARFILE INTO WA_ARFILE INDEX 1.
IF SY-SUBRC EQ 0.
SPLIT WA_ARFILE AT C_PIPE INTO WA_ARHEADER-P_RECTYPE
WA_ARHEADER-P_PRCID
WA_ARHEADER-P_SENDR
WA_ARHEADER-P_CDATE
WA_ARHEADER-P_CTIME
WA_ARHEADER-P_OBTYP
WA_ARHEADER-P_SEQNO
WA_ARHEADER-P_FRTXT.
APPEND WA_ARHEADER TO I_HEADER.
ENDIF.
READ TABLE I_ARFILE INTO WA_ARFILE INDEX v_LIN.
IF SY-SUBRC EQ 0.
SPLIT WA_ARFILE AT C_PIPE INTO WA_ARTRAILER-P_RECTYPE
WA_ARTRAILER-COUNT
WA_ARTRAILER-TOBAL
WA_ARTRAILER-TODIS.
APPEND WA_ARTRAILER TO I_TRAILER.
ENDIF.
* FIRST DELETE TRAILER THEN GO FOR HEADER
READ TABLE I_ARFILE INTO WA_ARFILE INDEX V_LIN.
DELETE I_ARFILE INDEX SY-TABIX
READ TABLE I_ARFILE INTO WA_ARFILE INDEX 1.
DELETE I_ARFILE INDEX SY-TABIX.
LOOP AT I_ARFILE INTO WA_ARFILE.
SPLIT I_ARFILE AT C_PIPE
INTO WA_ARITEM-P_RECTYPE
WA_ARITEM-p_xblnr
WA_ARITEM-p_bldat
WA_ARITEM-p_budat
WA_ARITEM-p_blart
WA_ARITEM-p_awkey
WA_ARITEM-p_kunnr
WA_ARITEM-p_xref1
WA_ARITEM-p_xref2
WA_ARITEM-p_xref3
WA_ARITEM-p_wrbtr
WA_ARITEM-p_zterm
WA_ARITEM-p_zuonr
WA_ARITEM-p_rstgr
WA_ARITEM-p_wskto
WA_ARITEM-p_sgtxt.
APPEND WA_ARITEM TO I_ITEM.
ENDLOOP.
aRs -
Using a comma-delimited string in Dynamic SQL
Hi --
If I receive a comma-delimited string as an in parameter, can I simply use that (in string format) when building my dynamic sql?
Thanks,
ChristineThe problem is, that you can not use bind variables
here, only literals. This causes
eventual performance problems.And to avoid the inevitable database performance problems Dmytro mentions you can use a function to convert the string to a varray and select from that. This also avoids having to use dynamic sql.
First you create a varray and conversion function.
SQL> create or replace type tabstr_t as table of varchar2(255)
2 /
Type created.
SQL> create or replace function tabstr (
2 p_str in varchar2,
3 p_sep in varchar2 default ','
4 )
5 return tabstr_t
6 as
7 l_str long default p_str || p_sep;
8 l_tabstr tabstr_t := tabstr_t();
9 begin
10 while l_str is not null loop
11 l_tabstr.extend(1);
12 l_tabstr(l_tabstr.count) := rtrim(substr(
13 l_str,1,instr(l_str,p_sep)),p_sep);
14 l_str := substr(l_str,instr(l_str,p_sep)+1);
15 end loop;
16 return l_tabstr;
17 end;
18 /
Function created.Then you can use these in either regular sql.
SQL> var s varchar2(100)
SQL> exec :s := 'Smith,Scott,Miller'
PL/SQL procedure successfully completed.
SQL>
SQL> select * from emp where ename in
2 (select upper(column_value) from table(tabstr(:s)));
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
7369 SMITH CLERK 7902 17-DEC-80 800 20
7788 SCOTT ANALYST 7566 09-DEC-82 3000 20
7934 MILLER CLERK 7782 23-JAN-82 1300 10Or in pl/sql.
SQL> var c refcursor
SQL> begin
2 open :c for
3 select * from emp where ename in
4 (select upper(column_value) from table(tabstr(:s)));
5 end;
6 /
PL/SQL procedure successfully completed.
SQL> print c
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
7369 SMITH CLERK 7902 17-DEC-80 800 20
7788 SCOTT ANALYST 7566 09-DEC-82 3000 20
7934 MILLER CLERK 7782 23-JAN-82 1300 10 -
How to change elements in ArrayList into String
Greetings,
i like to change elements in arrayList into string.
This is how i declare an ArrayList in a Java file
ArrayList listing = new ArrayList();below is just a simple example of how i insert the string into the arraylist
String concat = "';
concat = concat + "apple";
//Transfer the concat string into arraylist
listing.add(concat);
return listing;
{code}
On my Jsp page, it will receive the ArrayList from the java file. Lets say the Arrayist is pass into my JSP arraylist
This is my JSP arraylist
{code}ArrayList optLists = new ArrayList();{code}
Inside the arraylist element, it holds data eg: *308577;;RS | [CAT 2] Level: Arena, Section: A02* with a pipe between RS and CAT 2.
Now i looping the arraylist
{code}int a = 0;
for ( a=0; a < optLists.size(); a++)
String tempString = "";
String splitTemp = "";
String tempString = (String)optLists.get(a);
splitTemp = tempString.split("|");
System.out.println("Split String Results: "+ splitTemp);
{code}}
Heres the error:
*SeatAvailable_jsp.java:560: incompatible types*
*[javac] found : java.lang.String[]*
*[javac] required: java.lang.String*
*[javac] splitTemp = tempString.split("|");*
*[javac]*
What can i do to solve the problem?
Edited by: leeChaolan on May 2, 2008 4:45 AM
Edited by: leeChaolan on May 2, 2008 4:48 AMpaternostro is right, you are returning an array into a string which is wrong
but try this, i haven't tested it though..
nt a = 0;
for ( a=0; a < optLists.size(); a++)
String tempString = "";
String splitTemp = "";
String tempString = (String)optLists.get(a);
String[] splitTemp = tempString.split("|");
for(String xyz : splitTemp)
System.out.println("Split String Results: "+ xyz);
}Edited by: linker on May 2, 2008 1:17 PM
Edited by: linker on May 2, 2008 1:18 PM -
Pipe Delimited file with comma
Hi Guys,
I have a pipe '|' delimited csv file. One of the field contains ',' (comma) for few records. The data loads fine uptill the PSA but when I load the data in the cube, that field is coming empty as well as some other feilds which donot have a comma in it.
The delmiter in IP and DS is used '|' pipe.A pipe within quotes? I don't think you can do that with regex. But you can simply itearate through the chars of the String with an "isInsideQuotes" boolean flag and do a manual replacement using StringBuffer.
-
Dynamic Extract. Do Not Want Leading Zeros in Pipe Delimited Record
Greetings,
I am using the following code to create a pipe delimited extract file dynamically. The problem: leading zeros are being lost. For example, when I do an extract of BKPF, BELNR is appended to the extract without leading zeros. This is a problem. Any suggestions for resolving this?
DATA: lv_dref TYPE REF TO data,
lv_dref2 TYPE REF TO data,
lv_data TYPE ty_data,
ls_data TYPE ty_data,
oref TYPE REF TO cx_root,
text TYPE string.
CREATE DATA lv_dref TYPE (p_tab-low).
ASSIGN lv_dref->* TO <lfs>.
CREATE DATA lv_dref2 TYPE TABLE OF (p_tab-low).
ASSIGN lv_dref2->* TO <lft_main>.
CLEAR ds_clauses.
MOVE p_tab-low TO ds_clauses-tablename.
READ TABLE twhere WITH KEY ds_clauses-tablename
INTO ds_clauses.
TRY.
SELECT * FROM (p_tab-low) INTO TABLE <lft_main>
WHERE (ds_clauses-where_tab).
CATCH cx_sy_dynamic_osql_semantics INTO oref.
text = oref->get_text( ).
ENDTRY.
cv_subrc = sy-subrc.
gv_tot_cnt = gv_suc_cnt = sy-dbcnt.
CHECK gv_tot_cnt > 0.
LOOP AT <lft_main> ASSIGNING <lfs>.
CLEAR: ls_data.
DO.
ASSIGN COMPONENT sy-index OF STRUCTURE <lfs> TO <lfv>.
IF sy-subrc IS NOT INITIAL.
EXIT.
ENDIF.
WRITE: <lfv> TO lv_data.
IF ls_data IS NOT INITIAL.
*LEADING ZEROS ARE LOST HERE (at conatenate)
CONCATENATE ls_data lv_data INTO ls_data
SEPARATED BY '|'.
ELSE.
ls_data = lv_data.
ENDIF.
ENDDO.
APPEND ls_data TO ct_data.
ENDLOOP.
Your response is greatly appreciated.
Kind Regards,
JasonYou are losing it because of the write statement, change it to a move. I assume you are using the WRITE to put the correct formatting for a date field or a type P field, if that is the case, you can try to check which field is being written at the time by check sy-index or checking the type at runtime.
*WRITE: <lfv> TO lv_data.
move <lfv> to lv_data.
IF ls_data IS NOT INITIAL.
*LEADING ZEROS ARE LOST HERE (at conatenate)
CONCATENATE ls_data lv_data INTO ls_data
SEPARATED BY '|'.
ELSE.
ls_data = lv_data.
ENDIF.
Regards,
RIch Heilman -
Java Regex Pipe Delimited ?
Hello
I am trying to split the string which is pipe delimited. I am new to Regex and new to Java.
My Java/Regex code line to split is:
listColumns = aLine.split("\\|"); // my code has 2 backslash-escapes chars plus 1 pipe char but this forum does not allow me to put pipes or escapes correctly and plain text help is of NO HELP 8^(
My input string has 3 leading and 4 trailing pipe characters
My Output from split: (3 leading emptry strings work but 4 trailing pipe delimiters dont work)
SplitStrings2:[]
SplitStrings2:[]
SplitStrings2:[]
SplitStrings2:[col1]
SplitStrings2:[col3]
SplitStrings2:[col4]
I do get 3 empty strings for all 3 leading pipes but no empty strings for the any traling 4 pipe characters.
What do I need to change the code such that all repeated pipes resulted in same number of empty strings returned by split method?
thanks
YuriB
Edited by: yurib on Nov 28, 2012 12:25 PM
Edited by: yurib on Nov 28, 2012 12:25 PM
Edited by: yurib on Nov 28, 2012 12:29 PM1. The pipe is a meta-character so escape it.
2. Split rolls things up for you unless you tell it otherwise.
String s = "|||A|B|C||||";
String[] array = s.split("[|]", 10);
for(int i=0; i < array.length; i++)
System.out.println("" + i + ": " + array);
Maybe you are looking for
-
How can I remove ALL of iTunes as 8.2.023 is not identifying my iPhone
I have spent days on this and other discussions trying to fix my unintentional update to iTunes 8.2.023. Apple was called and they could not resolve and were sent a few logs from Apple and Widow Diagnostics. They have now ignored recent email and pho
-
My computer crashed lost all my music how can i transfer from ipod classic to itunes
Hi my computor crashed and i lost all my music how do i tranfer it back from my ipod classic? thanks
-
Is it possible to create a hyperlink in ERP report output
Is it possible to create a hyperlink in ERP report output connecting it to an outside application? Regards Sridhar
-
Hi, As per the weblog /people/venkat.donela/blog/2005/03/03/introduction-to-simple-file-xi-filescenario-and-complete-walk-through-for-starterspart2, I did follow the steps. I configured serv-u FTP server for my local system. I gave my systems Ip Addr
-
Photoshop CC Install Stuck at 90%
I am installing CC and started with Photoshop. It gets stuck at 90%. I've uninstalled/reinstalled three times and I've restarted my computer. Any suggestions?