Masking Data for CLOB columns

Hi Guys,
We have a CLOB column in our PNR database with the complete PNR details as below (all information has been changed ):
<PNR><PNR_Body>AXYDFB  -ETKT-
REC LOC HDQ1P37EJNM/XAV/24639860/CHI/1P/T/US/USD/GS
HDQ RM 1P 01OCT0000Z
1.1TEST/ONE
1 VS3011N 14DEC SA LHREDI HK1  1950. 2120. 03C*
2 VS3002N 18DEC WE EDILHR HK1  0910. 1040. 03C*
FONE-
1.LHR*[email protected]/N000
2.LHR72582/H530
3.LHR8200144*I24639860 ORBITZ/A877
4.LHR3072582/H415
TKT-T/TBC/CCAX379461823464012/12/72601233655/0001/$
GEN FAX-  *TKN/SSR FOR TKT NBRS
1.OSI YY BF0.00 TX141.10 TF141.10 PADT@FSR
2.SSRSEATVSKK1LHREDI3011N14DEC.03CN/RS
3.SSRSEATVSKK1EDILHR3002N18DEC.03CN/RS
4.SSROTHSVSKK1LHREDI3011N14DEC.UNTKTD VS SEGS MAY CANX 141013
5.SSROTHSVSKK1LHREDI3011N14DEC.TKT PER FARE RULES TO AVOID ADM
6.SSROTHSVSKK1EDILHR3002N18DEC.UNTKTD VS SEGS MAY CANX 141013
7.SSROTHSVSKK1EDILHR3002N18DEC.TKT PER FARE RULES TO AVOID ADM
8.SSROTHSVSKK1LHREDI3011N14DEC.UNTKTD VS SEGS MAY CANX 141013
9.SSROTHSVSKK1LHREDI3011N14DEC.TKT PER FARE RULES TO AVOID ADM
10.SSROTHSVSKK1EDILHR3002N18DEC.UNTKTD VS SEGS MAY CANX 141013
11.SSROTHSVSKK1EDILHR3002N18DEC.TKT PER FARE RULES TO AVOID ADM
12.SSROTHSVSKK1LHREDI3011N14DEC.UNTKTD VS SEGS MAY CANX 141013
13.SSROTHSVSKK1LHREDI3011N14DEC.TKT PER FARE RULES TO AVOID ADM
14.SSROTHSVSKK1EDILHR3002N18DEC.UNTKTD VS SEGS MAY CANX 141013
15.SSROTHSVSKK1EDILHR3002N18DEC.TKT PER FARE RULES TO AVOID ADM</PNR_Body><PNR_History>REC LOC AXYDFB7EJNM/XAV/24631260/CHI/1P/T/US/USD/GS
HDQ RM 1P 01OCT0000Z
A3 SSRSEATVSNN1LHREDI3011N14DEC.03C/RS
RCVD-AXYDFB7EJNM/XAV/24612860/CHI/1P/T/US/USD/GS
HDQ RM 1P 01OCT0000Z
X3 SSRSEATVSNN1LHREDI3011N14DEC.03C/RS
A3 SSRSEATVSKK1LHREDI3011N14DEC.03CN/RS
RCVD-
HDQ RM 1P 01OCT0000Z
A3 SSRSEATVSNN1EDILHR3002N18DEC.03C/RS
RCVD-AXYDFB7EJNM/XAV/24612860/CHI/1P/T/US/USD/GS
HDQ RM 1P 01OCT0000Z
X3 SSRSEATVSNN1EDILHR3002N18DEC.03C/RS
A3 SSRSEATVSKK1EDILHR3002N18DEC.03CN/RS
RCVD-
HDQ RM 1P 01OCT0000Z
A3 SSROTHSVSKK1LHREDI3011N14DEC.UNTKTD VS SEGS MAY CANX 142313
A3 SSROTHSVSKK1LHREDI3011N14DEC.TKT PER FARE RULES TO AVOID ADM
A3 SSROTHSVSKK1EDILHR3002N18DEC.UNTKTD VS SEGS MAY CANX 142313
A3 SSROTHSVSKK1EDILHR3002N18DEC.TKT PER FARE RULES TO AVOID ADM
RCVD-VSWEBSERVICE
CRC SU X1 01OCT0001Z D23B06 VS
A3 SSROTHSVSKK1LHREDI3011N14DEC.UNTKTD VS SEGS MAY CANX 142313
A3 SSROTHSVSKK1LHREDI3011N14DEC.TKT PER FARE RULES TO AVOID ADM
A3 SSROTHSVSKK1EDILHR3002N18DEC.UNTKTD VS SEGS MAY CANX 142313
A3 SSROTHSVSKK1EDILHR3002N18DEC.TKT PER FARE RULES TO AVOID ADM
RCVD-VSWEBSERVICE
CRC SU X1 01OCT0001Z AXYDFB VS
A3 SSROTHSVSKK1LHREDI3011N14DEC.UNTKTD VS SEGS MAY CANX 142313
A3 SSROTHSVSKK1LHREDI3011N14DEC.TKT PER FARE RULES TO AVOID ADM
A3 SSROTHSVSKK1EDILHR3002N18DEC.UNTKTD VS SEGS MAY CANX 142313
A3 SSROTHSVSKK1EDILHR3002N18DEC.TKT PER FARE RULES TO AVOID ADM
RCVD-VSWEBSERVICE
CRC SU X1 01OCT0001Z D12B06 VS
A3 SSRTKNEVSHK1LHREDI3011N14DEC-1TEST/ONE.4444123456C1
A3 SSRTKNEVSHK1EDILHR3002N18DEC-1TEST/ONE.4444123456C2
RCVD-AXYDFB7EJNM/XAV/24623860/CHI/1P/T/US/USD/GS
HDQ RM 1P 01OCT0042Z</PNR_History><Seating>SEATS ASSIGNED     FLT 3011  14DEC  HK1  1950.  2120.   X CLASS
B7   *   1TEST/JA  LHR TO EDI N  28Z*
NEXT FLIGHT AT EDI FLT 3002  18DEC  HK1  0910.  1040.   N CLASS
B2   *   1TEST/JA  EDI TO LHR N  23D*</Seating><ETicket_Info>AXYDFB -ETKT-      CPN  FLIGHT DATE  CLS FRM TO STATUS     ISSUE
1.  TEST/ONE  1. VS 3011 14DEC  N  LHREDI             1P
                    2. VS 3002 18DEC  N  EDILHR</ETicket_Info><ETicket_History>TEST/ONE          44443333222211110           $USD  141.10
FP CCAX44443333222211110/9306/142323                            
CHI 1P RS 01OCT0042Z 999999 VS                                
***END OF DISPLAY***                                            </ETicket_History><Fare_Quote>NO FQ DATA EXISTS</Fare_Quote><Fare_History>NO FQ DATA EXISTS</Fare_History><APIS>*NO APIS TO DISPLAY</APIS><Queue_History>SYSQ/IET/00
-Q SSRTKNE 01OCT0042Z </Queue_History></PNR>
Please can somebody suggest how I can browse through each row of the data identify credit card numbers (that we will be doing as per the business requirements from business) mask the numbers and put that back at the orignal location as it was.
Please can somebody explain me considering "44443333222211110" was a credit card number and requires to be masked.
Thanks,
Shaz

Here's a function you can use on 9i
CREATE OR REPLACE FUNCTION mask_cc_nums(i_clob CLOB)
  RETURN CLOB IS
  -- function to scan a clob and anywhere it finds a string of 16 consecutive numerics
  -- replace then with 16 *'s
  v_charpos  PLS_INTEGER := 0;
  v_outclob  CLOB;
  v_inlen    PLS_INTEGER := dbms_lob.getlength(i_clob);
BEGIN
  v_outclob := i_clob;
  WHILE v_charpos+16 <= v_inlen LOOP
    v_charpos := least(CASE WHEN dbms_lob.instr(v_outclob,'0',v_charpos+1) > 0
                            THEN dbms_lob.instr(v_outclob,'0',v_charpos+1)
                            ELSE v_inlen+1
                       END
                      ,CASE WHEN dbms_lob.instr(v_outclob,'1',v_charpos+1) > 0
                            THEN dbms_lob.instr(v_outclob,'1',v_charpos+1)
                            ELSE v_inlen+1
                       END
                      ,CASE WHEN dbms_lob.instr(v_outclob,'2',v_charpos+1) > 0
                            THEN dbms_lob.instr(v_outclob,'2',v_charpos+1)
                            ELSE v_inlen+1
                       END
                      ,CASE WHEN dbms_lob.instr(v_outclob,'3',v_charpos+1) > 0
                            THEN dbms_lob.instr(v_outclob,'3',v_charpos+1)
                            ELSE v_inlen+1
                       END
                      ,CASE WHEN dbms_lob.instr(v_outclob,'4',v_charpos+1) > 0
                            THEN dbms_lob.instr(v_outclob,'4',v_charpos+1)
                            ELSE v_inlen+1
                       END
                      ,CASE WHEN dbms_lob.instr(v_outclob,'5',v_charpos+1) > 0
                            THEN dbms_lob.instr(v_outclob,'5',v_charpos+1)
                            ELSE v_inlen+1
                       END
                      ,CASE WHEN dbms_lob.instr(v_outclob,'6',v_charpos+1) > 0
                            THEN dbms_lob.instr(v_outclob,'6',v_charpos+1)
                            ELSE v_inlen+1
                       END
                      ,CASE WHEN dbms_lob.instr(v_outclob,'7',v_charpos+1) > 0
                            THEN dbms_lob.instr(v_outclob,'7',v_charpos+1)
                            ELSE v_inlen+1
                       END
                      ,CASE WHEN dbms_lob.instr(v_outclob,'8',v_charpos+1) > 0
                            THEN dbms_lob.instr(v_outclob,'8',v_charpos+1)
                            ELSE v_inlen+1
                       END
                      ,CASE WHEN dbms_lob.instr(v_outclob,'9',v_charpos+1) > 0
                            THEN dbms_lob.instr(v_outclob,'9',v_charpos+1)
                            ELSE v_inlen+1
                       END);
    IF v_charpos <= v_inlen-16 AND
       TRANSLATE(SUBSTR(v_outclob,v_charpos,16),' 0123456789',' ') IS NULL
    THEN
      v_outclob := SUBSTR(v_outclob,1,v_charpos-1)||'****************'||SUBSTR(v_outclob,v_charpos+16);
    END IF;
  END LOOP;
  RETURN v_outclob;
END;

Similar Messages

  • Problem in Loading data for clob column using sql ldr

    Hi,
    I am having problem in loading data for tables having clob column.
    Could anyone help me in correcting the below script for ctrl file inorder to load the data which is in mentioned format.
    Any help really appreciated.
    Table Script
    Create table samp
    no number,
    col1 clob,
    col2 clob
    Ctrl File
    options (skip =1)
    load data
    infile 'c:\1.csv'
    Replace into table samp
    fields terminated by ","
    trailing nullcols
    no,
    col1 Char(100000000) ,
    col2 Char(100000000) enclosed by '"' and '"'
    Data File(1.csv)
    1,asdf,"assasadsdsdsd""sfasdfadf""sdsdsa,ssfsf"
    2,sfjass,"dksadk,kd,ss""dfdfjkdjfdk""sasfjaslaljs"
    Error Encountered
    ORA-01461: can bind a LONG value only for insert into a LONG column
    Table sampThanks in advance

    I can't reproduce it on my 10.2.0.4.0. CTL file:
    load data
    INFILE *
    Replace into table samp
    fields terminated by ","
    trailing nullcols
    no,
    col1 Char(100000000) ,
    col2 Char(100000000) enclosed by '"' and '"'
    BEGINDATA
    1,asdf,"assasadsdsdsd""sfasdfadf""sdsdsa,ssfsf"
    2,sfjass,"dksadk,kd,ss""dfdfjkdjfdk""sasfjaslaljs"Loading:
    SQL> Create table samp
      2  (
      3  no number,
      4  col1 clob,
      5  col2 clob
      6  );
    Table created.
    SQL> host sqlldr scott/tiger control=c:\temp\samp.ctl log=c:\temp\samp.log
    SQL> select * from samp
      2  /
            NO
    COL1
    COL2
             1
    asdf
    assasadsdsdsd"sfasdfadf"sdsdsa,ssfsf
             2
    sfjass
    dksadk,kd,ss"dfdfjkdjfdk"sasfjaslaljs
            NO
    COL1
    COL2
    SQL> SY.

  • Limitation for CLOB columns? - ORA-01704: string literal too long

    Hello!
    I'm trying to update a CLOB column with more than 35000 characteres, but I get "ORA-01704: string literal too long".
    The code:
    declare
    l_clob clob;
    begin
    update test set test = empty_clob()
    WHERE ID = 1
    returning test into l_clob;
    dbms_lob.write( l_clob, length('A...here 35000xA...A'), 1,'A...here 35000xA...A');
    end;
    Is there any limitation for CLOB columns?
    Thanks for help.
    Daniel

    user605489 wrote:
    32768 characteres :)Actually it's 1 character less than 32K...
    *32767*
    SQL> declare
      2    v_vc varchar2(32768);
      3  begin
      4    null;
      5  end;
      6  /
      v_vc varchar2(32768);
    ERROR at line 2:
    ORA-06550: line 2, column 17:
    PLS-00215: String length constraints must be in range (1 .. 32767)
    SQL>I guess it comes from a legacy thing where signed words (2 bytes) are/were used to represent a value. As the most significant bit of the word is used to represent the sign of the number the range goes from -32768 to 32767.

  • Error reading data from CLOB column into VARCHAR2 variable

    Hi all,
    Am hitting an issue retrieving data > 8K (minus 1) stored in a CLOB column into a VARCHAR2 variable in PL/SQL...
    The "problem to be solved" here is storing DDL, in this case a "CREATE VIEW" statement, that is longer than 8K for later retrieval (and execution) using dynamic SQL. Given that the EXECUTE IMMEDIATE statement can take a VARCHAR2 variable (up to 32K(-1)), this should suffice for our needs, however, it seems that somewhere in the process of converting this VARCHAR2 text to a CLOB for storage, and then retrieving the CLOB and attempting to put it back into a VARCHAR2 variable, it is throwing a standard ORA-06502 exception ("PL/SQL: numeric or value error"). Consider the following code:
    set serveroutput on
    drop table test1;
    create table test1(col1 CLOB);
    declare
    cursor c1 is select col1 from test1;
    myvar VARCHAR2(32000);
    begin
    myvar := '';
    for i in 1..8192 loop
    myvar := myvar || 'a';
    end loop;
    INSERT INTO test1 (col1) VALUES (myvar);
    for arec in c1 loop
    begin
    myvar := arec.col1;
    dbms_output.put_line('Read data of length ' || length(myvar));
    exception when others then
    dbms_output.put_line('Error reading data: ' || sqlerrm);
    end;
    end loop;
    end;
    If you change the loop upper bound to 8191, all works fine. I'm guessing this might have something to do with the database character set -- we've recently converted our databases over to UTF-8, for Internationalizion support, and that seems to have changed underlying assumptions regarding character processing...?
    As far as the dynamic SQL issue goes, we can probably use the DBMS_SQL interface instead, with it's EXECUTE procedure that takes a PL/SQL array of varchar2(32K) - the only issue there is reading the data from the CLOB column, and then breaking that data into an array but that doesn't seem insurmountable. But this same basic issue (when a 9K text block, let's say, turns into a >32K block after being CLOBberred) seems to comes up in other text-processing situations also, so any ideas for how to resolve would be much appreciated.
    Thanks for any tips/hints/ideas...
    Jim

    For those curious about this, here's the word from Oracle support (courtesy of Metalinks):
    RESEARCH
    ========
    Test the issue for different DB version and different characterset.
    --Testing the following PL/SQL blocks by using direct assignment method(myvar := arec.col1;) on
    different database version and different characterset.
    SQL>create table test1(col1 CLOB);
    --Inserting four CLOB data into test1.
    declare
    myvar VARCHAR2(32767);
    begin
    myvar := RPAD('a',4000);
    INSERT INTO test1 (col1) VALUES (myvar);
    myvar := RPAD('a',8191);
    INSERT INTO test1 (col1) VALUES (myvar);
    myvar := RPAD('b',8192);
    INSERT INTO test1 (col1) VALUES (myvar);
    myvar := RPAD('c',32767);
    INSERT INTO test1 (col1) VALUES (myvar);
    commit;
    end;
    --Testing the direct assignment method.
    declare
    cursor c1 is select col1, length(col1) len1 from test1;
    myvar VARCHAR2(32767);
    begin
    for arec in c1 loop
    myvar := arec.col1;
    --DBMS_LOB.READ(arec.col1, arec.len1, 1, myvar);
    dbms_output.put_line('Read data of length: ' || length(myvar));
    end loop;
    end;
    The following are the summary of the test results:
    ===================================
    1. If the database characterset is WE8ISO8859P1, then the above direct assignment
    method(myvar := arec.col1;) works for database version 9i/10g/11g without any
    errors.
    2. If the database characterset is UTF8 or AL32UTF8, then the above direct assignment method(myvar := arec.col1;) will generate the "ORA-06502:
    PL/SQL: numeric or value error" when the length of the CLOB data is greater
    than 8191(=8K-1). The same error can be reproduced across all database versions
    9i/10g/11g.
    3. Using DBMS_LOB.READ(arec.col1, arec.len1, 1, myvar) method to read CLOB data into a VARCHAR2 variable works for both WE8ISO8859P1 and UTF8
    characterset and for all database versions.
    So - it seems as I'd surmised, UTF8 changes the way VARCHAR2 and CLOB data is handled. Not too surprising, I suppose - may you all be lucky enough to be able to stay away from this sort of issue. But - the DBMS_LOB.READ workaround is certainly sufficient for the text processing situations we find ourselves in currently.
    Cheers,
    Jim C.

  • How to retreive soap xml data from clob column in a table

    Hi,
    I am trying to retrieve the XML tag value from clob column.
    Table name = xyz and column= abc (clob datatype)
    data stored in abc column is as below
    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:head="http://www.abc.com/gcgi/shared/system/header" xmlns:v6="http://www.abc.com/gcgi/services/v6_0_0_0" xmlns:sys="http://www.abc.com/gcgi/shared/system/systemtypes">
    <soapenv:Header xmlns:wsa="http://www.w3.org/2005/08/addressing">
    <RqHeader soapenv:mustUnderstand="0" xmlns="http://www.abc.com/gcgi/shared/system/header">
    <DateAndTimeStamp>2011-12-20T16:02:36.677+08:00</DateAndTimeStamp>
    <UUID>1000002932</UUID>
    <Version>6_0_0_0</Version>
    <ClientDetails>
    <Org>ABC</Org>
    <OrgUnit>ABC</OrgUnit>
    <ChannelID>HBK</ChannelID>
    <TerminalID>0000</TerminalID>
    <SrcCountryCode>SG</SrcCountryCode>
    <DestCountryCode>SG</DestCountryCode>
    <UserGroup>HBK</UserGroup>
    </ClientDetails>
    </RqHeader>
    <wsa:Action>/SvcImpl/bank/
    SOAPEndpoint/AlertsService.serviceagent/OpEndpointHTTP/AlertDeleteInq</wsa:Action></soapenv:Header>
    <soapenv:Body>
    <v6:AlertDeleteInqRq>
    <v6:Base>
    <v6:VID>20071209013112</v6:VID>
    <!--Optional:-->
    <v6:Ref>CTAA00000002644</v6:Ref>
    </v6:Base>
    </v6:AlertDeleteInqRq>
    </soapenv:Body>
    </soapenv:Envelope>
    And i want to retrieve the values of tag
    <ChannelID> and <v6:VID>
    can somebody help, i have tried with extractvalue but not able to get the values

    I have used the below two queries but not able to get the expected results. Both queries result into no values.
    select xmltype(MED_REQ_PAYLOAD).extract('//ClientDetails/Org','xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" || xmlns="http://www.abc.com/gcgi/shared/system/header"').getStringValue() from ESB_OUTPUT_TEMP where SOAPACTION = '/SvcImpl/bank/alerts/v6_0_0_0/SOAPEndpoint/AlertsService.serviceagent/OpEndpointHTTP/AlertDeleteInq'
    select EXTRACTVALUE(xmltype(MED_REQ_PAYLOAD),'/RqHeader/) from ESB_OUTPUT_TEMP where SOAPACTION = '/SvcImpl/bank/SOAPEndpoint/AlertsService.serviceagent/OpEndpointHTTP/AlertDeleteInq'
    Well, for starters, both queries are syntactically wrong :
    - non terminated string
    - incorrect namespace mapping declaration
    - unknown XMLType method "getStringValue()"
    Secondly, all those functions are deprecated now.
    Here's an up-to-date example using XMLTable. It will retrieve the two tag values you mentioned :
    SQL> select x.*
      2  from esb_output_temp t
      3     , xmltable(
      4         xmlnamespaces(
      5           'http://schemas.xmlsoap.org/soap/envelope/' as "soap"
      6         , 'http://www.abc.com/gcgi/shared/system/header' as "head"
      7         , 'http://www.abc.com/gcgi/services/v6_0_0_0' as "v6"
      8         )
      9       , '/soap:Envelope'
    10         passing xmlparse(document t.med_req_payload)
    11         columns ChannelID  varchar2(10) path 'soap:Header/head:RqHeader/head:ClientDetails/head:ChannelID'
    12               , VID        varchar2(30) path 'soap:Body/v6:AlertDeleteInqRq/v6:Base/v6:VID'
    13       ) x
    14  ;
    CHANNELID  VID
    HBK        20071209013112
    You may also want to store XML in XMLType columns for both performance and storage optimizations.

  • Show the rtf formated data from CLOB Column

    Hi all,
    is it possible to show the rtf formatted text stored in a clob column on the report generated with bi publisher?
    A step-by-step guidance wuold be nice.
    I have created with bi publisher a report, generated a data source and sql query.
    But in ms word it will not be shown as formatted. All rtf tags will be shown too.
    Regards,

    Hi Leonid,
    A) =======
    I'd be keen if someone like Tim would pick up on this and advise the full list of supported fo:instream-foreign-object content-type's that BI Publisher supports, would be nice if there was application/pdf and as you require application/rtf or similar. That way you'd just base64 encode your file in your XML output as per images like jpg/gif/png and include it in your template.
    Desirable syntax would then be like:
    <fo:instream-foreign-object content-type="application/rtf" >
    <xsl:value-of select="MY_BASE64_RTF_ELEMENT"/>
    </fo:instream-foreign-object>However thats wishful thinking as I can only see documented support for images specifically in jpg / gif / png formats.
    B) =======
    As a workaround if you have the ability to update your RTFs files (clobs) then you can just use the standard subtemplate functionality.
    In that case the approach would be:
    1. Update the RTFs (stored as clobs) to surround with template syntax:
    <?template:DefSubTemp?>
    ... your RTF doc here ...
    <?end template?>2. Take your clob and setup/upload as template (subtemplate=yes) manual or backend automate.
    3. Add the subtemplate to your main template (assuming you register under Application Object Library, code XXV8_SUBTEMP, language English and territory United States):
    <?import:xdo://FND.XXV8_SUBTEMP.EN.US?>
    <?call-template:DefSubTemp?>C) =======
    If you don't have the ability to update your RTF CLOBs and neither of the other solutions are suitable, then one of thing I thought of is on the fly conversion of the RTFs to, say, PNG and then use the image functionality to embed the image in the output. But again this may not be suitable as it will be an image not the "textual" output.
    D) =======
    All else failing you could look into the XML Publisher APIs to see if those could help.
    Hopefully something for you to think about here and get more info on.
    Regards,
    Gareth
    Blog: http://garethroberts.blogspot.com/

  • Create hash value for clob column ?

    Hi,
    does anybody know a way to calculate a hash value for a clob column (9i) ?
    DBMS_UTILITY.GET_HASH_VALUE could only handle varchar2(4000).
    Thank you!
    Regrads
    Michael
    Message was edited by:
    mseiwert

    I can't reproduce it on my 10.2.0.4.0. CTL file:
    load data
    INFILE *
    Replace into table samp
    fields terminated by ","
    trailing nullcols
    no,
    col1 Char(100000000) ,
    col2 Char(100000000) enclosed by '"' and '"'
    BEGINDATA
    1,asdf,"assasadsdsdsd""sfasdfadf""sdsdsa,ssfsf"
    2,sfjass,"dksadk,kd,ss""dfdfjkdjfdk""sasfjaslaljs"Loading:
    SQL> Create table samp
      2  (
      3  no number,
      4  col1 clob,
      5  col2 clob
      6  );
    Table created.
    SQL> host sqlldr scott/tiger control=c:\temp\samp.ctl log=c:\temp\samp.log
    SQL> select * from samp
      2  /
            NO
    COL1
    COL2
             1
    asdf
    assasadsdsdsd"sfasdfadf"sdsdsa,ssfsf
             2
    sfjass
    dksadk,kd,ss"dfdfjkdjfdk"sasfjaslaljs
            NO
    COL1
    COL2
    SQL> SY.

  • Get frequent data for each column of a table

    What is the best way to get the most frequent data in each column of a table.
    we have around 25 tables and each table has around 20 columns , so rather than writing group by for each column of table , is there any easy way to find this?
    example we have table
    Column A       Column B         Column C
    Apple             Monday             Red
    orange            Tuesday            Green
    Apple              Monday            Red
    Lemon            Wednesday       Green
    Apple               Thursday         Red
    in this table, column A's frequnt data is Apple , column B's frequent data is Monday , Column C's frequnt data is Red
    Apple 3          Monday 2                  Red 3
    Orange 2        Tuesday 1                 Green 2
    Lemon 1          Wednesday 1         
                          Thursday 1
    Group by kind of query will give this result, but with 20 tables each having 20 - 30 columns if we need similar kind of result ..  is there any way to get this data.

    Hi,
    GROUP BY (using aggregate functions) is the best way to do what you described.
    PIVOT and UNPIVOT are probably what you'd want in this case.  The phrase "GROUP BY" may not actually appear in your code, but you'll essentially be doing a GROUP BY.
    Analytic functions (rather than aggregate functions) can do the job, too, but they'll be less efficient.  Analytic functions get you results about the groups, without losing each row's identify, but in this case, losing each row's identity is eactly what you want to do.  You only want 'Apple' to appear 1 time, not 3 times.
    The fact that you need to do the same query on 20 different tables suggests that there's something wrong with your table design.  Wouldn't it be better to have 1 big table, with a new column that has 20 unique values instead?
    I hope this answers your question.
    If not, please post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) from all tables involved, so that the people who want to help you can re-create the problem and test their ideas.
    Also post the results you want from that data, and an explanation of how you get those results from that data, with specific examples.
    Simplify the problem as much as possible.  For example, instead of posting a problem with 20 tables, each having 25 columns, post a similar problem involving, say, 2 tables, each with 3 columns.
    Always say which version of Oracle you're using (for example, 11.2.0.2.0).
    See the forum FAQ: https://forums.oracle.com/message/9362002

  • Get a quarter out of data for a column chart

    Who can help me with this challenge?
    I want to create a column chart with four quarters in the current year and one column with the rest later in time.
    One project can have multiple output data. They are separated by an ;
    The notation of the outputdata can be a date (d-m-yyyy), a month (mm-yyyy) or a quarter (Q1-yyyy).
    This is by example the available data.
    Project              outputdata
    Project 1           1-4-2014
    Project 2           03-2014;Q4-2014;Q2-2015
    Project 3           25-09-2014;Q1-2015
    The data I want to get for the column chart is:
    Project              outputdata                    columnchart
    Project 1           1-4-2014                       Q2-2014
    Project 2           03-2014                        Q1-2014
    Project 2           Q4-2014                       Q4-2014
    Project 2           Q2-2015                       2015 and later
    Project 3           25-09-2014                   Q3-2014
    Project 3           Q1-2015                       2015 and later
    I hope that someone can help me in the right direction.
    Thanks in advance,
    Els

    Adding to what Frank has already suggested, try something on these lines:
    Something like this?
    SQL> ed
    Wrote file afiedt.buf
      1  with x2 as(
      2     select 'proj1' proj, '1-4-2014' op, NULL chart from dual UNION ALL
      3     select 'proj2' proj, '03-2014' op, NULL chart from dual UNION ALL
      4     select 'proj2' proj, 'Q4-2014' op, NULL chart from dual UNION ALL
      5     select 'proj2' proj, 'Q2-2015' op, NULL chart from dual UNION ALL
      6     select 'proj3' proj, '25-09-2014' op, NULL chart from dual UNION ALL
      7     select 'proj3' proj, 'Q1-2015' op, NULL chart from dual
      8  )
      9  select
    10     proj,
    11     op,
    12     case
    13     when regexp_like(op,'((\d{1}|\d{2})-(\d{1}|\d{2})-(\d{4}))')
    14     then
    15             'Q'||TO_CHAR(TO_DATE(op,'dd-mm-yyyy'),'Q')||'-'||TO_CHAR(TO_DATE(op,'dd-mm-yyyy'),'yyyy')
    16     when regexp_like(op, 'Q\d{1}-\d{4}')
    17     then
    18             CASE
    19             when SUBSTR(op,-4,4) > 2014
    20             then
    21                     SUBSTR(op,-4,4)||' and later'
    22             else
    23                     op
    24             end
    25     when regexp_like(op, '\d{2}-\d{4}')
    26     then
    27             'Q'||TO_CHAR(TO_DATE(op,'mm-yyyy'),'Q')||'-'||TO_CHAR(TO_DATE(op,'mm-yyyy'),'yyyy')
    28     end
    29* from x2
    SQL> /
    PROJ       OP                   CASEWHENREGEXP
    proj1      1-4-2014             Q2-2014
    proj2      03-2014              Q1-2014
    proj2      Q4-2014              Q4-2014
    proj2      Q2-2015              2015 and later
    proj3      25-09-2014           Q3-2014
    proj3      Q1-2015              2015 and later
    6 rows selected.

  • Insert XMLTYPE data into CLOB column

    Hi,
    I am trying to insert XMLTYPE datatype column value into the CLOB datatype column.
    I get an error -
    ORA - 00932: Inconsistent datatypes: expected CLOB got -
    How do I insert xml type data into clob?
    Thanks!

    Here is my sql code:
    I have a view :
    create or replace view test_view
    (id,
    code,
    desc)
    as select
    id,
    code,
    xmlroot(xmlelement("empname", ename), version '1.0') as desc
    from employee;
    I have a table emp_details_table. The columns in the emp_details_table are
    ID number,
    CODE varchar2,
    EMP_DETAILS CLOB
    I am tring to insert the 'test_view' data into the 'emp_details_table' and I get an error cannot insert xmltype data into clob.
    insert into emp_details_table
    (ID , CODE, EMP_DETAILS)
    select
    (ID, CODE, DESC) from test_view;
    Thanks.

  • How to name the data for each column I am acquiring in lvm file

    does anybody hint  How to name the data for each cloumn I am acquiring in lvm file.
    I want to tag or name ,eg temperature at top of a column which shows the temperature readings .I am writing into a labview measurement file.
    Thanks

    Use Set Waveform Attribute on each channel of your data.  Set an attribute with name "NI_ChannelName".  The value is a string containing the name you wish to call the channel.
    This account is no longer active. Contact ShadesOfGray for current posts and information.

  • SQL loader Field in data file exceeds maximum length for CLOB column

    Hi all
    I'm loading data from text file separated by TAB and i got the error below for some lines.
    Event the column is CLOB data type is there a limitation of the size of a CLOB data type.
    The error is:
    Record 74: Rejected - Error on table _TEMP, column DEST.
    Field in data file exceeds maximum length
    I'm using SQL Loader and the database is oracle 11g r2 on linux Red hat 5
    Here are the line causing the error fronm my data file and my table description for test:
    create table TEMP
    CODE VARCHAR2(100),
    DESC VARCHAR2(500),
    RATE     FLOAT,
    INCREASE VARCHAR2(20),
    COUNTRY VARCHAR2(500),
    DEST     CLOB,
    WEEK     VARCHAR2(10),
    IS_SAT VARCHAR2(50),
    IS_SUN VARCHAR2(50)
    CONTROL FILE:
    LOAD DATA
    INTO TABLE TEMP
    APPEND
    FIELDS TERMINATED BY X'9' TRAILING NULLCOLS
    CODE,
    DESC,
    RATE,
    INCREASE,
    COUNTRY),
    DEST,
    WEEK,
    IS_SAT,
    IS_SUN
    Data file:
    BHS Mobile     Bahamas - Mobile     0.1430          1     "242357, 242359, 242375, 242376, 242395, 242421, 242422, 242423, 242424, 242425, 242426, 242427, 242428, 242429, 242431, 242432, 242433, 242434, 242435, 242436, 242437, 242438, 242439, 242441, 242442, 242443, 242445, 242446, 242447, 242448, 242449, 242451, 242452, 242453, 242454, 242455, 242456, 242457, 242458, 242462, 242463, 242464, 242465, 242466, 242467, 242468, 24247, 242524, 242525, 242533, 242535, 242544, 242551, 242552, 242553, 242554, 242556, 242557, 242558, 242559, 242565, 242577, 242636, 242646, 242727"               
    BOL Mobile ENTEL     Bolivia - Mobile Entel     0.0865     Increase     591     "67, 68, 71, 72, 73, 740, 7410, 7411, 7412, 7413, 7414, 7415, 7420, 7421, 7422, 7423, 7424, 7425, 7430, 7431, 7432, 7433, 7434, 7435, 7436, 7437, 7440, 7441, 7442, 7443, 7444, 7445, 7450, 7451, 7452, 7453, 7454, 7455, 746, 7470, 7471, 7472, 7475, 7476, 7477, 7480, 7481, 7482, 7483, 7484, 7485, 7486, 7490, 7491, 7492, 7493, 7494, 7495, 7496"               Thank you.

    Hi
    Thank you for youe help, I found the solution and here what i do in my Control file i added
    char(40000) OPTIONALLY ENCLOSED BY '"' .
    LOAD DATA
    INTO TABLE TEMP
    APPEND
    FIELDS TERMINATED BY X'9' TRAILING NULLCOLS
    CODE,
    DESC,
    RATE,
    INCREASE,
    COUNTRY,
    DEST
    char(40000) OPTIONALLY ENCLOSED BY '"',
    WEEK,
    IS_SAT,
    IS_SUN
    Thank you for your help.

  • How to Load data for extra columns exist in the dest schema....

    Hi Experts,
    Please help me.
    I need to replicate data from SchemaA to SchemaB.
    SchemaB has 3 extra columns. Two are varchar2 type and other is Integer type.
    I need to replicate the data from SchemaA to SchemaB in the same database.
    When ever i inserted the data in SchemaA, The extra columns should be populated with some default data.
    And if we did any update on SchemaA then the extra columns on SchemaB should be populated with other Data.
    I wrote some DML_HANDLER but it always populating same data.
    I dont know ow to handle this type of situation.
    my Handler is:
    CREATE OR REPLACE PROCEDURE dml_handler(in_any in sys.anydata)
    IS
    lcr SYS.LCR$_ROW_RECORD;
    rc PLS_INTEGER;
    object_owner VARCHAR2(30);
    BEGIN
    rc := in_any.GETOBJECT(lcr);
    object_owner := lcr.GET_OBJECT_OWNER();
    IF lcr.get_object_owner() = 'SchemaB' THEN
    lcr.add_column('new','SHIP_DATE',sys.anydata.convertvarcahr2('N'));
    lcr.add_column('new','SHIP_ZONE',sys.anydata.convertvarchar2('N'));
    lcr.add_column('new','SHIP_REACH_BY_DATE',sys.anydata.convertnumber(1));
    lcr.EXECUTE(TRUE);
    END IF;
    END;
    BEGIN
    DBMS_APPLY_ADM.SET_DML_HANDLER
    (object_name => 'SchemaB.TAB_TEST',
    object_type => 'TABLE',
    operation_name => 'INSERT',
    error_handler => FALSE,
    user_procedure => 'STRMADMIN.DML_HANDLER');
    END;
    On extra columns in SChemaB
    if its a first insert then the default values are (N,N,1).
    If we did any update the values should be (Y,Y,2)
    Post any script or give me some idea.
    Thanks,
    Ray
    Edited by: user7423698 on Mar 3, 2009 6:12 PM

    CREATE OR REPLACE PROCEDURE dml_handler (
    in_any IN SYS.ANYDATA
    IS
    lcr sys.lcr$_row_record;
    rc PLS_INTEGER;
    cmd_type VARCHAR2 (30);
    BEGIN
    rc := in_any.getobject (lcr);
    cmd_type := lcr.get_command_type;
    IF cmd_type = 'INSERT'
    THEN
    lcr.set_values ('new', lcr.get_values ('new', 'N'));
    lcr.add_column ('new', 'type', sys.anydata.convertchar ('I'));
    lcr.set_values ('old', NULL);
    lcr.add_column ('new', 'time', sys.anydata.converttimestamp (systimestamp));
    lcr.execute (TRUE);
    END IF;
    END;
    Set the DML handler for INSERT and write a similar one for UPDATE.

  • Data loading: formatting data for timestamp column

    Hi All,
    I have a table with a timestamp column named as created_date. I want to upload data to that table using data loading page. but there is one problem while uploading data, I have a csv file in which the created_date column data in two different format as follows ,
    09/03/2013 03:33am
    09/02/2013 03:24pm
    the above data throws an error ORA-01821: date format not recognized.
    In Data / Table Mapping page, I tried with MM/DD/YYYY HH12:MI:SS AM. What format should i use for am and pm??
    Please help me to solve....
    Thanks in advance
    Lakshmi

    I solved by using the format MM/DD/YYYY HH:MIAM.
    Thanks
    Lakshmi

  • Decimal Point data for Stacked Column Chart

    Hi,
    I use a basic version of a Column chart for one of my projects. I use a stacked column chart with 2 data series namely "Expenses" & "Profit".
    I use decimal point numbers (with only two or three places after the decimal point) for both series.
    When I mouse over the bars of the output for tool tip, I view more numbers after the decimal point for some data.
    How to fix the decimal point to only 2 places & what is the reason for this behaviour?
    Attached is the sample output (output.gif) showing the above condition for the mentioned data.
    -Sen

    Create an toolTipShow event handler and use a NumberFormatter to set the precision of the numbers (sample code from LiveDocs):
    <?xml version="1.0"?>
    <!-- formatters\MainNumberFormatter.mxml -->
    <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
        <mx:Script>
            <![CDATA[
                // Define variable to hold the number.       
                [Bindable]
                private var bigNumber:Number = 6000000000.65;
            ]]>
        </mx:Script>
        <!-- Declare and define parameters for the NumberFormatter.-->
        <mx:NumberFormatter id="PrepForDisplay"
            precision="0"
            rounding="up"
            decimalSeparatorTo="."
            thousandsSeparatorTo=","
            useThousandsSeparator="true"
            useNegativeSign="true"/>
        <!-- Trigger the formatter while populating a string with data.-->
        <mx:TextInput text="{PrepForDisplay.format(bigNumber)}"/> 
    </mx:Application>

Maybe you are looking for

  • Sales Order Incompletion

    Hi All, I have a seemingly random error on sales orders that I was wondering about.  When looking at the collective run every morning, I frequently see sales documents stuck due to pricing errors.  When I go into the sales orders, the incompletion lo

  • PDF Printing using OC4J

    Hi, I have used BI Desktop Publisher to convert an RTF document into the necessary XSL-FO format. I have uploaded the report layout and assigned it to a report query in APEX. When I run the report I get the following errror:- fop: Servlet error oracl

  • OVI Website don´t show my events

    BUG REPORT: Since my registration, OVI website do not show my calendar events, but i can see them in the search rsults, witch proves that they are successfull syncronized. Events created at the website aren´t showed too...

  • Consignment indicator added to production orders

    Hi Everyone, I was wondering if you could help me, we have a raw material that has been moved from consignment to own stock, all the info records have been changed and material moved to own stock BUT when we create a production order the consignment

  • Updates or install of applications from disk won't install.

    Hello. Tried running a software update on my recently already archived and installed Macbook. Neither the Safari or iTunes would install. Tried installing older version of iTunes (deleted iTunes 8 due to problems) and that wont work. When I did a sof