SQL Function to compare 2 strings

Hi All
Is there any SQL function to compare 2 strings?

If you are looking for a character by character comparison then you would have to do something like...
SQL> ed
Wrote file afiedt.buf
  1  WITH T AS (select 'THIS IS MY 1ST STRING' string1, 'THIS IS MY 2ND String Bob' string2 from dual)
  2  --
  3  select s1ch, s2ch, decode(s1ch,s2ch,'Match','Mismatch') as compare
  4  from (
  5        select rn, substr(string1,rn,1) as s1ch, substr(string2,rn,1) as s2ch
  6        from t, (select rownum rn from t connect by rownum <= greatest(length(string1), length(string2)))
  7       )
  8* order by rn
SQL> /
S S COMPARE
T T Match
H H Match
I I Match
S S Match
    Match
I I Match
S S Match
    Match
M M Match
Y Y Match
    Match
1 2 Mismatch
S N Mismatch
T D Mismatch
    Match
S S Match
T t Mismatch
R r Mismatch
I i Mismatch
N n Mismatch
G g Mismatch
    Mismatch
  B Mismatch
  o Mismatch
  b Mismatch
25 rows selected.
SQL>

Similar Messages

  • PL/SQL function returning a SQL Query

    Is this only availabe in HTML db or in 10g in general? Where do I find more about this feature?
    Thanks in advance,
    Denes

    Not sure what you mean. HTML DB allows to use a PL/SQL function returning a valid SQL query in report regions.
    Its just a PL/SQL function returning a string, outside of HTML DB, I guess you can use it wherever it makes sense.

  • String Substitutions with PL/SQL Function

    Hello, i user APEX 4.2.1.00.08 in Database 11g
    I new in apex and a try to use String Substitutions.
    When I define a String like CONST with static value like '999' in Edit Applications Definition it's work fine.
    But I need to define the same String 'CONST' but with value to return from PL/SQL function like.. Package.function
    It's Possible ??
    Thanks !!

    No, you'll need to use application items instead - or pass the value as parameter to your function.
    Passing parameters like this makes for good practice anyway, since your modules become more testable outside the apex environment, and more robust.

  • Function "xmlnamespaces" gives PL/SQL: ORA-19102: XQuery string literal....

    Below is my script that you can run successfully, and i have version Oracle 11g.
    Script has Xml namespace as constant at the moment there:
       xmlnamespaces(default 'http://elion.ee/webservices/Sales/Dynamics')I want to have a variable there instead, like this:
       xmlnamespaces(default    l_sSOAP_Namespace )But if i add such variable there i get such error:
    PL/SQL: ORA-19102: XQuery string literal expectedCan i avoid such error somehow and use still the namespace as variable somehow, not the constant?
    My script:
    declare
       l_resp varchar2(4000);
       l_sSOAP_Namespace varchar2(4000) := 'http://elion.ee/webservices/Sales/Dynamics';
    begin
      l_resp :=
      '<ns0:FindItemMetaDataResponse xmlns:ns0="http://elion.ee/webservices/Sales/Dynamics">
            <ns0:ItemMetaData>
              <ns0:ItemMetaData>
                <ns0:ItemGroupId>IT.LS.VS.DSL</ns0:ItemGroupId>
                <ns0:ItemGroupName>IT lisad võrguseadmed DSL</ns0:ItemGroupName>
                <ns0:ItemId>DSLGP603</ns0:ItemId>
                <ns0:ItemName>ADSL SIP ST546</ns0:ItemName>
               <ns0:ItemType>Item</ns0:ItemType>
               <ns0:MacAddressMandatory>No</ns0:MacAddressMandatory>
               <ns0:SalesUnit>tk</ns0:SalesUnit>
               <ns0:SerialNumMandatory>No</ns0:SerialNumMandatory>
               <ns0:TaxValue>20.00</ns0:TaxValue>
             </ns0:ItemMetaData>
             <ns0:ItemMetaData>
               <ns0:CurrencyCode>EUR</ns0:CurrencyCode>
               <ns0:ItemGroupId>KL.PS.HGW</ns0:ItemGroupId>
               <ns0:ItemGroupName>Ruuterid</ns0:ItemGroupName>
               <ns0:ItemId>DSLGP603NY</ns0:ItemId>
               <ns0:ItemName>ADSL stardikomplekt Thomson ST546 stardi</ns0:ItemName>
               <ns0:ItemType>Item</ns0:ItemType>
               <ns0:MacAddressMandatory>No</ns0:MacAddressMandatory>
               <ns0:PriceWithoutVAT>12.78</ns0:PriceWithoutVAT>
               <ns0:PriceWithVAT>15.34</ns0:PriceWithVAT>
               <ns0:SalesUnit>tk</ns0:SalesUnit>
               <ns0:SerialNumMandatory>Yes</ns0:SerialNumMandatory>
               <ns0:TaxValue>20.00</ns0:TaxValue>
             </ns0:ItemMetaData>
           </ns0:ItemMetaData>
         </ns0:FindItemMetaDataResponse>';
      for rec in
         with xml_doc (doc) as (
            select xmlparse(document
            l_resp)
           from dual
         select x.*
         from xml_doc t
            , xmltable (
                xmlnamespaces(default 'http://elion.ee/webservices/Sales/Dynamics')
              , '/FindItemMetaDataResponse/ItemMetaData/ItemMetaData'
                passing t.doc
                columns
                CurrencyCode varchar2(4000) path 'CurrencyCode',
                ItemGroupId varchar2(4000) path 'ItemGroupId',
                ItemGroupName varchar2(4000) path 'ItemGroupName',
                ItemId varchar2(4000) path 'ItemId',
                ItemName varchar2(4000) path 'ItemName',
                ItemType varchar2(4000) path 'ItemType',
                MacAddressMandatory varchar2(4000) path 'MacAddressMandatory',
                PriceWithoutVAT varchar2(4000) path 'PriceWithoutVAT',
                PriceWithVAT varchar2(4000) path 'PriceWithVAT',
                SalesUnit varchar2(4000) path 'SalesUnit',
                SerialNumMandatory varchar2(4000) path 'SerialNumMandatory',
                TaxValue varchar2(4000) path 'TaxValue'         
              ) x
      ) loop
        dbms_output.put_line('ItemId=' || rec.ItemId);
      end loop;
    end;
    /* Output:
    ItemId=DSLGP603
    ItemId=DSLGP603NY
    */Edited by: CharlesRoos on 11.04.2013 14:46

    How badly do you need the namespace to be dynamic ?
    Is it likely to change that frequently?
    The reason for having to hardcode namespace declarations and XQuery string in general is optimization.
    By doing so, the CBO is able to analyze the whole expression and apply optimization techniques such as XQuery rewrite.
    As said, use dynamic SQL if you really have no way around this requirement.
    The other solution I'm reluctent to expose here is to make the whole thing namespace-free by using construct such as "*:element-name" or "*[local-name()="element-name"]".
    Both will use XQ functional evaluation and perform worse.

  • SQL report region source to call a pl/sql function using DB link

    Hi - I have a pl/sql function fn_dbtype(id NUMBER) defined in database X. The pl/sql function executes couple DML statements and returns a string (a SELECT query). I am able to call this function using SQL Plus (Connected to Database X) as below and it works fine:
    declare
    vSQL VARCHAR2(100);
    begin
    vSQL := fn_dbtype(1);
    end;
    The DML operations completed fine and vSQL contains the "Select" query now.
    In APEX:
    I am trying to create a SQL report in APEX using SQL query(PL/SQL function returning a sql statement) option. I am trying to figure out what to put in the region source so that the output of the "Select" query is displayed in the report.
    Moreover APEX is hosted in a different database instance. So I would need to call this pl/sql function using a DB Link.
    Please let me know what I need to put in the region source to execute the pl/sql function which returns the "Select" query thereby displaying the query output in the report. Thanks.
    Edited by: user709584 on Mar 19, 2009 2:32 PM
    Edited by: user709584 on Mar 19, 2009 2:34 PM

    try something like this:
    return fn_dbtype(1)@dblink;

  • Problem with empty report parameters when passed to PL/SQL function

    Hi,
    We have come across what appears to be a bug in the JRC. When passing a report parameter to a PL/SQL function as a parameter, empty parameters are changed before being sent to the function. More specifically, an empty string "" ends up as the value "(')" in the PL/SQL function parameter. In our report we print the report parameters on the first page so we know that the parameters are OK before being passed to the database.
    The problem exists for version 12.2.203, 12.2.204 and 12.2.205 of the JRC.
    We have identified a workaround, but it is not exactly elegant: Before executing the report we modify all empty  parameters ("") to " " . In the PL/SQL function, we trim all parameters before using them.
    We call the function using a command object with a sql syntax like this example:
    select * from table (qa_batch_release.get_qa_br('{?p_report_id}','{?p_reg_set_number}','{?p_cr_number}','{?p_change_id_decode}','{?p_country_id}','{?p_mfg_item_no}','{?p_4_no}','{?p_5_no}','{?p_7_no}'))
    The PL/SQL function is a table returning function.
    Best regards, Thor

    Hi Kishore,
    using #COLUMN_VALUE# would probably not make much sense, because normally a report has multiple columns and not just the numeric column which you want to verify if it's negative. But APEX will fire the template condition for each column, because the report template is a column cell template.
    What you can do to make it more generic is to use for example
    #CHECK_AMOUNT#
    in the template and provide a not displayed column in your SQL statement which contains your value which is named CHECK_AMOUNT. For example:
    SELECT NAME
         , BALANCE
         , BALANCE AS CHECK_AMOUNT
    FROM XXX;Because this CHECK_AMOUNT column would be a generic name, you can use this template in all your reports as long as you provide this column.
    Thope that helps
    Patrick

  • Passing #COLUMN_VALUE# as parameter to pl/sql function in column template

    Hi all,
    I want to color negative amounts in red in sql report using column template.
    I created a pl/sql function"isNegativeNum" which returns 1 or -1.
    create or replace function isNegativeNum(p_column_value varchar2) return number
    as
    l_dummy number;
    begin
          l_dummy := to_number(p_column_value,'999G999G990D00PR');
          IF l_dummy < 0
             THEN
                RETURN 1;
          else
                return -1;
          END IF;
    exception
    when others then
       RETURN -1;
    end;Below is column template.
    Column Template 1
    <td class="t3dataalt" #ALIGNMENT#><p color=red>#COLUMN_VALUE#</p></td>Column Template 1 Condition
    isNegativeNum('#COLUMN_VALUE#') = -1The issue is #COLUMN_VALUE# value is not being passed to the function, Insert statement in function reveals p_column_value as a string "#COLUMN_VALUE#". When I try without quotes like isNegativeNum(#COLUMN_VALUE#) = -1, I get below error.
    ORA-06550: line 1, column 48: PLS-00103: Encountered the symbol "#" when expecting one of the following: ( ) - + case mod new not null others select table avg count current exists max min prior sql stddev sum variance execute multiset the both leading trailing forall merge year month DAY_ hour minute second timezone_hour timezone_minute timezone_region timezone_abbr time timestamp interval date
         Error      ERR-1025 Error processing PLSQL expression. isNegativeNum(#COLUMN_VALUE#) = 1
    Any help is appreciated.
    Kishore

    Hi Kishore,
    using #COLUMN_VALUE# would probably not make much sense, because normally a report has multiple columns and not just the numeric column which you want to verify if it's negative. But APEX will fire the template condition for each column, because the report template is a column cell template.
    What you can do to make it more generic is to use for example
    #CHECK_AMOUNT#
    in the template and provide a not displayed column in your SQL statement which contains your value which is named CHECK_AMOUNT. For example:
    SELECT NAME
         , BALANCE
         , BALANCE AS CHECK_AMOUNT
    FROM XXX;Because this CHECK_AMOUNT column would be a generic name, you can use this template in all your reports as long as you provide this column.
    Thope that helps
    Patrick

  • PL/SQL function. ORA-00933: SQL command not properly ended

    This is my first attempt at pl/sql functions with dynamic sql. It will compile, but when I try to test it I get the ORA-00933 error at line 147. line 147 is OPEN retval FOR report_query;
    Please take a look and let me know what it wrong! thanks
    {CREATE OR REPLACE FUNCTION TSARPTS.Stats (v_Hub       IN VARCHAR2,
                                              v_type      IN VARCHAR2,
                                              v_subtype   IN VARCHAR2)
       RETURN SYS_REFCURSOR
    IS
       retval           SYS_REFCURSOR;
       report_query_a   VARCHAR2 (10000)
                           := '
      SELECT hub,
             CASE
                WHEN Total = 0 OR Pass_1st = 0 THEN 0
                ELSE ROUND (Pass_1st / (Total) * 100, 2)
             END
                AS Pass_1st_percent,
             CASE
                WHEN Total = 0 OR Pass_2nd = 0 THEN 0
                ELSE ROUND (Pass_2nd / (Total) * 100, 2)
             END
                AS Pass_2nd_percent,
             CASE
                WHEN Total = 0 OR Pass_3rd = 0 THEN 0
                ELSE ROUND (Pass_3rd / (Total) * 100, 2)
             END
                AS Pass_3rd_percent,
             CASE
                WHEN Total = 0 OR DNM = 0 THEN 0
                ELSE ROUND (DNM / (Total) * 100, 2)
             END
                AS DNM,
             CASE
                WHEN Total = 0 OR Incomplete = 0 THEN 0
                ELSE ROUND (Incomplete / (Total) * 100, 2)
             END
                AS Incomplete
        FROM (  SELECT hub,
                       SUM (DECODE (result, ''Pass_on_1st'', 1, 0)) Pass_1st,
                       SUM (DECODE (result, ''Pass_on_2nd'', 1, 0)) Pass_2nd,
                       SUM (DECODE (result, ''Pass_on_3rd'', 1, 0)) Pass_3rd,
                       SUM (DECODE (result, ''DNM'', 1, 0)) DNM,
                       SUM (DECODE (result, ''INCOMPLETE'', 1, 0)) Incomplete,
                         SUM (DECODE (result, ''Pass_on_1st'', 1, 0))
                       + SUM (DECODE (result, ''Pass_on_2nd'', 1, 0))
                       + SUM (DECODE (result, ''Pass_on_3rd'', 1, 0))
                       + SUM (DECODE (result, ''DNM'', 1, 0))
                       + SUM (DECODE (result, ''INCOMPLETE'', 1, 0))
                          Total
                  FROM employees_vw a, pse_vw b
                 WHERE     a.emplid = b.emplid
                       AND status IN (''S'', ''I'', ''N'')
                       AND TYPE = ''PSE''
       report_query_b   VARCHAR2 (10000)
                           := ' 
    SELECT hub,
           TYPE,
           subtype,
           CASE
              WHEN Total = 0 OR Pass_1st = 0 THEN 0
              ELSE ROUND (Pass_1st / (Total) * 100, 2)
           END
              AS Pass_1st_percent,
           CASE
              WHEN Total = 0 OR Pass_2nd = 0 THEN 0
              ELSE ROUND (Pass_2nd / (Total) * 100, 2)
           END
              AS Pass_2nd_percent,
           CASE
              WHEN Total = 0 OR Pass_3rd = 0 THEN 0
              ELSE ROUND (Pass_3rd / (Total) * 100, 2)
           END
              AS Pass_3rd_percent,
           CASE
              WHEN Total = 0 OR DNM = 0 THEN 0
              ELSE ROUND (DNM / (Total) * 100, 2)
           END
              AS DNM,
           CASE
              WHEN Total = 0 OR Incomplete = 0 THEN 0
              ELSE ROUND (Incomplete / (Total) * 100, 2)
           END
              AS Incomplete
      FROM (  SELECT hub,
       TYPE,
           subtype
                      SUM (DECODE (result, ''Pass_on_1st'', 1, 0)) Pass_1st,
                       SUM (DECODE (result, ''Pass_on_2nd'', 1, 0)) Pass_2nd,
                       SUM (DECODE (result, ''Pass_on_3rd'', 1, 0)) Pass_3rd,
                       SUM (DECODE (result, ''DNM'', 1, 0)) DNM,
                       SUM (DECODE (result, ''INCOMPLETE'', 1, 0)) Incomplete,
                         SUM (DECODE (result, ''Pass_on_1st'', 1, 0))
                       + SUM (DECODE (result, ''Pass_on_2nd'', 1, 0))
                       + SUM (DECODE (result, ''Pass_on_3rd'', 1, 0))
                       + SUM (DECODE (result, ''DNM'', 1, 0))
                       + SUM (DECODE (result, ''INCOMPLETE'', 1, 0))
                          Total
                  FROM employees_vw a, pse_vw b
                 WHERE     a.emplid = b.emplid
                       AND status IN (''S'', ''I'', ''N'')
                     AND TYPE = ''PSE''
       report_query     VARCHAR2 (10000);
    BEGIN
       IF v_hub <> '*'
       THEN
          report_query := report_query_a;
       ELSE
          report_query := report_query_b;
       END IF;
       IF v_hub <> '*'
       THEN
          report_query :=
             report_query || ' and hub = ''' || v_hub || ''' GROUP BY hub )
    GROUP BY hub,
             Pass_1st,
             Pass_2nd,
             Pass_3rd,
             Total,
             DNM,
             Incomplete';
       END IF;
       IF v_type <> '*' AND v_subtype <> '*' AND v_hub <> '*'
       THEN
          report_query :=
                report_query
             || ' and hub = '''
             || v_hub
             || ''' and type = '''
             || v_type
             || ''' and subtype= '''
             || v_subtype
             || '''
              GROUP BY hub,
                     TYPE,
                     subtype,
            GROUP BY hub,
                     TYPE,
                     subtype,
                     Pass_1st,
                     Pass_2nd,
                     Pass_3rd,
                     Total,
                     DNM,
                     Incomplete';
       END IF;
       OPEN retval FOR report_query;
       RETURN retval;
    END;
    Edited by: user10821012 on May 13, 2010 9:56 AM

    What you are seeing is pretty common. When I work with dynamic SQL I usually include some logic to put the dyanmic SQL into a string and a means to see what was generated, something like (untested here)
      v_sql_c := 'select * from dual';
      open refcur for v_sql_c;
    exception
      when others then
         insert into work_table (clob_column) values (v_sql_c);so I can later query the table to get to the generated SQL for debugging, something like
      select * from work_table;I also try to write dynamic SQL so I can paste it from the work table right into query execution without editing.

  • Multiple Select List looping thru PL/SQL function body returning SQL query

    Hi,
    I have a Multiple Select List. I want to loop through the values from the Select List and process them in a PL/SQL function body returning a SQL query. Currently, my code only returns the SQL SELECT results of one item in the select list. How do I change my code to make it return the results of all of the items in the select list? (I tested it and it is definitely picking up all the values in the select list).
    <b>
    DECLARE
    selected_items HTMLDB_APPLICATION_GLOBAL.VC_ARR2;
    s   VARCHAR2(20);
    q varchar2(32767);
    BEGIN
    selected_items := HTMLDB_UTIL.STRING_TO_TABLE(:P50_SELECTED_INSTRUMENTS);
    -- htp.p('COUNT: '||selected_items.count);
      FOR i in 1..selected_items.count LOOP
      s := TO_CHAR(selected_items(i));
    -- htp.p('First: '||s);
    -- htp.p('Second: '||:s);
    -- htp.p('Third: '||TO_CHAR(selected_items(i)));
      q:= 'SELECT  '||
    'SUBSTR(orig_geo_loc_sys,1,INSTR(orig_geo_loc_sys,''-'')-1) AS INSTRUMENT, '||
    'SUBSTR(orig_geo_loc_sys,INSTR(orig_geo_loc_sys,''-'')+1, LENGTH'||
    ' (orig_geo_loc_sys)) AS ORIG_LINENUM, '||
    'sum(orig_intrl) orig_intrl, '||
    'sum(orig_extrl) orig_extrl, '||
    'sum(recv_intrl) recv_intrl, '||
    'sum(recv_extrl) recv_extrl '||
    'FROM line_usage_sum_view '||
    'WHERE TO_CHAR(orig_geo_loc_sys) LIKE ''' || s ||'%'' '||
    --'WHERE TO_CHAR(orig_geo_loc_sys) LIKE ''2213003%'' '||
    'AND switch_id = ''' || :P1_SWITCH_ID || ''' ' ||
    'AND call_start_date > TO_DATE(''30-NOV-1999'') ' ||
    'AND call_clear_time > TO_DATE(''30-NOV-1999'') '||
    'AND '||
    :SORTFIELD||' BETWEEN '||
    'TO_DATE(:STARTDATE,''dd-MON-YYYY HH24:MI'') AND '||
    'TO_DATE(:STOPDATE, ''dd-MON-YYYY HH24:MI'') '||
    'GROUP BY GROUPING SETS (orig_geo_loc_sys)';
    -- htp.p('SQL query: '||q);
      RETURN q;
      END LOOP;
    END;</b>
    Thank you,
    Laura

    Laura,
    First, I would be careful of introducing SQL Injection possibilities. Any time I see
    'Select ... ' || :P123_FOO || ' ... '
    I worry about sql injection. In your case you are converting :P50_SELECTED_INSTRUMENTS into selected_items and then selected_items into s. So when I see
    'WHERE TO_CHAR(orig_geo_loc_sys) LIKE ''' || s ||'%'' '||
    I think, "I could use sql Injection and hack this."
    So, I would do some validation on :P50_SELECTED_INSTRUMENTS or some other method to avoid this.
    I'm not certain I understand your query. Do you really intend to allow the user to select the beginning of a string and then find all rows that start with that string? Or, do you just want to let them find when it matches the string. This is one way if you want to do matching:
    DECLARE
    selected_items HTMLDB_APPLICATION_GLOBAL.VC_ARR2;
    s VARCHAR2(32767);
    q varchar2(32767);
    BEGIN
    -- Change the : separate string to be comma separated with quoted strings
    s := '''' || replace(:P50_SELECTED_INSTRUMENTS, ',', ''',''')|| '''' ;
    -- htp.p('COUNT: '||selected_items.count);
    q:= 'SELECT '||
    'SUBSTR(orig_geo_loc_sys,1,INSTR(orig_geo_loc_sys,''-'')-1) AS INSTRUMENT, '||
    'SUBSTR(orig_geo_loc_sys,INSTR(orig_geo_loc_sys,''-'')+1, LENGTH'||
    ' (orig_geo_loc_sys)) AS ORIG_LINENUM, '||
    'sum(orig_intrl) orig_intrl, '||
    'sum(orig_extrl) orig_extrl, '||
    'sum(recv_intrl) recv_intrl, '||
    'sum(recv_extrl) recv_extrl '||
    'FROM line_usage_sum_view '||
    'WHERE TO_CHAR(orig_geo_loc_sys) in (' || s ||' ) '||
    --'WHERE TO_CHAR(orig_geo_loc_sys) LIKE ''2213003%'' '||
    'AND switch_id = ''' || :P1_SWITCH_ID || ''' ' ||
    'AND call_start_date > TO_DATE(''30-NOV-1999'') ' ||
    'AND call_clear_time > TO_DATE(''30-NOV-1999'') '||
    'AND '||
    :SORTFIELD||' BETWEEN '||
    'TO_DATE(:STARTDATE,''dd-MON-YYYY HH24:MI'') AND '||
    'TO_DATE(:STOPDATE, ''dd-MON-YYYY HH24:MI'') '||
    'GROUP BY GROUPING SETS (orig_geo_loc_sys)';
    -- htp.p('SQL query: '||q);
    RETURN q;
    END;
    If you want to do something more like you originally stated, try this:
    DECLARE
    selected_items HTMLDB_APPLICATION_GLOBAL.VC_ARR2;
    s VARCHAR2(20);
    q varchar2(32767);
    BEGIN
    selected_items := HTMLDB_UTIL.STRING_TO_TABLE(:P50_SELECTED_INSTRUMENTS);
    -- htp.p('COUNT: '||selected_items.count);
    q:= 'SELECT '||
    'SUBSTR(orig_geo_loc_sys,1,INSTR(orig_geo_loc_sys,''-'')-1) AS INSTRUMENT, '||
    'SUBSTR(orig_geo_loc_sys,INSTR(orig_geo_loc_sys,''-'')+1, LENGTH'||
    ' (orig_geo_loc_sys)) AS ORIG_LINENUM, '||
    'sum(orig_intrl) orig_intrl, '||
    'sum(orig_extrl) orig_extrl, '||
    'sum(recv_intrl) recv_intrl, '||
    'sum(recv_extrl) recv_extrl '||
    'FROM line_usage_sum_view '||
    'WHERE 1=1 ';
    FOR i in 1..selected_items.count LOOP
    s := TO_CHAR(selected_items(i));
    q := q || ' and TO_CHAR(orig_geo_loc_sys) LIKE '''|| s ||'%'' ' ;
    END LOOP;
    q := q || ||'%'' '||
    --'WHERE TO_CHAR(orig_geo_loc_sys) LIKE ''2213003%'' '||
    'AND switch_id = ''' || :P1_SWITCH_ID || ''' ' ||
    'AND call_start_date > TO_DATE(''30-NOV-1999'') ' ||
    'AND call_clear_time > TO_DATE(''30-NOV-1999'') '||
    'AND '||
    :SORTFIELD||' BETWEEN '||
    'TO_DATE(:STARTDATE,''dd-MON-YYYY HH24:MI'') AND '||
    'TO_DATE(:STOPDATE, ''dd-MON-YYYY HH24:MI'') '||
    'GROUP BY GROUPING SETS (orig_geo_loc_sys)';
    -- htp.p('SQL query: '||q);
    RETURN q;
    END;
    Hope this helps...
    Anton

  • SQL Error: ORA-01704: string literal too long

    select * from table(fn_split('some 10000 characters with comma separation .........................'))
    Error report:
    SQL Error: ORA-01704: string literal too long
    01704. 00000 - "string literal too long"
    *Cause:    The string literal is longer than 4000 characters.
    *Action:   Use a string literal of at most 4000 characters.
    how to pass my 10k record string

    933663 wrote:
    The string is through a user interface.So, that interface is using what datatype for the string? What language is the interface written in?
    insert into table
    select * from table(fn_split('2,4,2,5,7'));Do you understand what a string literal is? You cannot provide a varchar2 string that exceeds 4000 bytes from within SQL. Fact. It just cannot be done.
    If you are passing the string from a user interface using a datatype that supports more than 4000 bytes, and you pass it directly to PL/SQL code by calling the function or procedure directly (not using SQL) then you can use up to 32767 bytes for your VARCHAR2.
    The code you've posted (which happens to be some of my own code posted years ago on these forums) takes a VARCHAR2 as an input. You would have to change that to accept a CLOB datatype and work on the CLOB instead. However, you still wouldn't be able to pass in a string literal of more than 4000 bytes from SQL for it.
    Looking at your other thread: Seperate the string value
    ... it looks like the 'user' is trying to pass in a table definition. What is it your application is trying to do? Surely you are not trying to create a table at run time?
    So explain, what is the business issue you are trying to solve? We may be able to provide a better way of doing it.

  • Invoking a PL/SQL function from BPEL throws fault.

    Hi, I'm trying to invoke a PL/SQL function that inserts data in to a table from a BPEL via DB Adapter. The process, when I test it, throws a runtime fault as follows:
    *Exception occured when binding was invoked. Exception occured during invocation of JCA binding: "JCA Binding execute of Reference operation 'EmpRegister' failed due to: JCA Binding Component connection issue. JCA Binding Component is unable to create an outbound JCA (CCI) connection. AddEmployee:EmpRegister [ EmpRegister_ptt::EmpRegister(InputParameters,OutputParameters) ] : The JCA Binding Component was unable to establish an outbound JCA CCI connection due to the following issue: BINDING.JCA-12510 JCA Resource Adapter location error. Unable to locate the JCA Resource Adapter via .jca binding file element <connection-factory/> The JCA Binding Component is unable to startup the Resource Adapter specified in the <connection-factory/> element: location='eis/DB/DBConn_215'. The reason for this is most likely that either 1) the Resource Adapters RAR file has not been deployed successfully to the WebLogic Application server or 2) the '<jndi-name>' element in weblogic-ra.xml has not been set to eis/DB/DBConn_215. In the last case you will have to add a new WebLogic JCA connection factory (deploy a RAR). Please correct this and then restart the Application Server ". The invoked JCA adapter raised a resource exception. Please examine the above error message carefully to determine a resolution.*
    Also, the fault description was a s follows:
    *JCA Resource Adapter location error. Unable to locate the JCA Resource Adapter via .jca binding file element <connection-factory/> The JCA Binding Component is unable to startup the Resource Adapter specified in the <connection-factory/> element: location='eis/DB/DBConn_215'. The reason for this is most likely that either 1) the Resource Adapters RAR file has not been deployed successfully to the WebLogic Application server or 2) the '<jndi-name>' element in weblogic-ra.xml has not been set to eis/DB/DBConn_215. In the last case you will have to add a new WebLogic JCA connection factory (deploy a RAR). Please correct this and then restart the Application Server.*
    I know, it looks like a JCA adapter error, but when I do a DB to DB table synchronization with this connection factory, no problems happen. Is ther any special procedure I should follow in mapping input data to db schema?

    HI,
    I am working on BPEL process and human workflow...
    I created a process and a Data control and now can see it as JCA Adapter in console..in this adapter I am executing a sql procedure.. we can execute in in BPEL process through invoke activity, now my requirement is how to invoke this data control through custom java code. please help...\
    now i have two wsdl files.
    RegistrationUpload.wsdl(process name)
    <?xml version="1.0" encoding="UTF-8"?>
    <wsdl:definitions name="RegistrationUpload"
    targetNamespace="http://xmlns.oracle.com/RegistrationUpload_jws/RegistrationUpload/RegistrationUpload"
    xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
    xmlns:client="http://xmlns.oracle.com/RegistrationUpload_jws/RegistrationUpload/RegistrationUpload"
    xmlns:plnk="http://schemas.xmlsoap.org/ws/2003/05/partner-link/">
         <!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
         TYPE DEFINITION - List of services participating in this BPEL process
         The default output of the BPEL designer uses strings as input and
         output to the BPEL Process. But you can define or import any XML
         Schema type and use them as part of the message types.
         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
         <wsdl:types>
              <schema xmlns="http://www.w3.org/2001/XMLSchema">
                   <import namespace="http://xmlns.oracle.com/RegistrationUpload_jws/RegistrationUpload/RegistrationUpload" schemaLocation="xsd/RegistrationUpload.xsd" />
              </schema>
         </wsdl:types>
         <!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
         MESSAGE TYPE DEFINITION - Definition of the message types used as
         part of the port type defintions
         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
         <wsdl:message name="RegistrationUploadRequestMessage">
              <wsdl:part name="payload" element="client:process"/>
         </wsdl:message>
         <wsdl:message name="RegistrationUploadResponseMessage">
              <wsdl:part name="payload" element="client:processResponse"/>
         </wsdl:message>
         <!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
         PORT TYPE DEFINITION - A port type groups a set of operations into
         a logical service unit.
         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
         <!-- portType implemented by the RegistrationUpload BPEL process -->
         <wsdl:portType name="RegistrationUpload">
              <wsdl:operation name="process">
                   <wsdl:input message="client:RegistrationUploadRequestMessage"/>
              </wsdl:operation>
         </wsdl:portType>
         <!-- portType implemented by the requester of RegistrationUpload BPEL process
         for asynchronous callback purposes
         -->
         <wsdl:portType name="RegistrationUploadCallback">
              <wsdl:operation name="processResponse">
                   <wsdl:input message="client:RegistrationUploadResponseMessage"/>
              </wsdl:operation>
         </wsdl:portType>
         <!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
         PARTNER LINK TYPE DEFINITION
         the RegistrationUpload partnerLinkType binds the provider and
         requester portType into an asynchronous conversation.
         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
         <plnk:partnerLinkType name="RegistrationUpload">
              <plnk:role name="RegistrationUploadProvider">
                   <plnk:portType name="client:RegistrationUpload"/>
              </plnk:role>
              <plnk:role name="RegistrationUploadRequester">
                   <plnk:portType name="client:RegistrationUploadCallback"/>
              </plnk:role>
         </plnk:partnerLinkType>
    </wsdl:definitions>
    uploadDataToPermananentDB.wsdl
    <?binding.jca uploadDataToPermananentDB_db.jca?>
    <wsdl:definitions name="uploadDataToPermananentDB"
    targetNamespace="http://xmlns.oracle.com/pcbpel/adapter/db/RegistrationUpload/RegistrationUpload/uploadDataToPermananentDB"
    xmlns:db="http://xmlns.oracle.com/pcbpel/adapter/db/DAMSMGR/TEMP_TO_PERMANENTDB/"
    xmlns:tns="http://xmlns.oracle.com/pcbpel/adapter/db/RegistrationUpload/RegistrationUpload/uploadDataToPermananentDB"
    xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
    xmlns:plt="http://schemas.xmlsoap.org/ws/2003/05/partner-link/">
    <plt:partnerLinkType name="uploadDataToPermananentDB_plt">
    <plt:role name="uploadDataToPermananentDB_role">
    <plt:portType name="tns:uploadDataToPermananentDB_ptt"/>
    </plt:role>
    </plt:partnerLinkType>
    <wsdl:types>
    <schema xmlns="http://www.w3.org/2001/XMLSchema">
    <import namespace="http://xmlns.oracle.com/pcbpel/adapter/db/DAMSMGR/TEMP_TO_PERMANENTDB/"
    schemaLocation="xsd/DAMSMGR_TEMP_TO_PERMANENTDB.xsd"/>
    </schema>
    </wsdl:types>
    <wsdl:message name="args_in_msg">
    <wsdl:part name="InputParameters" element="db:InputParameters"/>
    </wsdl:message>
    <wsdl:portType name="uploadDataToPermananentDB_ptt">
    <wsdl:operation name="uploadDataToPermananentDB">
    <wsdl:input message="tns:args_in_msg"/>
    </wsdl:operation>
    </wsdl:portType>
    </wsdl:definitions>
    please help me how to call the data adaper from my java code..
    hope i will get some hint in this forum...
    Edited by: user13370040 on Mar 22, 2011 5:55 AM

  • SQL query (pl/sql function body returning query) performance issue

    I create my report in building my sql instruction with ( SQL Query pl/sql function body returning sql query );
    My report take more than 20 seconds however if i did a cut and paste with the sql code in TOAD the same sql take 1 second.
    To try to discover the source of the problem; i take the sql generated by the function and i create another report ( sql query ) this new report take 2 seconds.
    My query is very big 25,000 characters with database link.
    What is the difference between SQL-quey and sql-query(pl/sql function body returning sql query)
    Thanks
    Marc

    Marc,
    Firstly...don't compare the timings from Toad, since often Toad only fetches the first few records for you (i.e. it pages them).
    Secondly....the database link could be a factor here, but without seeing your query it's too hard to say.
    Can you post the query somewhere (on a webserver say)?

  • Data passed from Java to a PL/SQL function

    OK, I am at the beginner-to-intermediate level when it comes to PL/SQL...and a virtual novice when it comes to Java, so please forgive me if my question seems strange or naive.
    We are developing a Java-based web app. Some of the screens are reminiscent of a spreadsheet-type layout--potentially LOTS of rows and LOTS of columns (actually, an open-ended # of rows/columns--the rows represent a particular 'thing' and the columns represent the dates on which that 'thing' occurred), where the user can check off any and all the cells that apply. We are also 'auditing' all database activity (who did what to the data, and when). The approach we have chosen is as follows: When the user clicks save, the first thing we do is 'inactivate' all of the existing active rows in the db for that screen, whether or not they have changed(i.e., there is an 'active' flag that we set to false & we also save the user id of the person making the change and the date time of the change). Then the Java code calls the database once per row/contiguous column unit. For instance, on a single row, if the user checks off columns 1-4 and 7-15 and column 21 the Java code will send three calls to the database for that row with info about the start/stop column for each unit.
    OK--here is my concern...the majority of the time there will be a reasonably small #of 'units'. Occasionally there will be a moderate, and once in awhile a LARGE # of 'units'. So, let's take an extreme case and say that currently the db has 200 such row/contiguous column units for a given screen. The user goes into that screen and adds the 201st unit, then clicks Save. Java calls the db to first inactivate the 200 rows. Then one by one Java calls the db to add the rows back in, only on row #40, the internet connection is lost. The only way the user can tell what happened is to look at the entire screen and reverify ALL the data in order to tell what got saved/resaved and what didn't. Obviously this is a bad situation that we want to avoid.
    I should add that the reason this approach was chosen is that the Java developers thought it would be way too complex in this situation to track the changes the user made on the screen, sort out what has been added/modified/deleted, and only call the db for changes.
    So given this background, can anyone offer any suggestions/ideas on how we can prevent unintended data loss given the auditing constraints and concern about minimizing complexity on the Java side (redesigning the GUI screen is NOT an option, as the users are very attached to this design)?
    Is there a way for Java to pass a multidimensional (& variable-sized) array to a PL/SQL function? Can Oracle's complex (row, table) data types be used in a function's parameter string, and if so...how?...Or else is there some way we can send a single call to the db on a screen like this one? We thought of calling the db once and sending one very large string packed with all the data (could get very big, not sure of Oracle's limatations on passed data--is it 32K for varchar2? )
    Advice, ideas, even random thoughts would be greatly appreciated!

    Tracy,
    <quote>… only on row #40, the internet connection is lost. The only way the user can tell what happened is to look at the entire screen and reverify ALL the data in order to tell what got saved/resaved and what didn't</quote>
    That would be "the only way" if the Java programmers had decided to totally bury the error … what should happen here is the end-user should get a proper error message … no need to re-verify at this point since all bets are off (in fact, nothing should’ve been changed in the database).
    Nonetheless, your concerns regarding the chosen approach are valid … making multiple calls to the database after a Save makes controlling a business transaction rather complex (in an n-tier system) … they should make one call only to the database passing in all the data to be saved … one database transaction … either all changes get applied or none.
    The fact that lots of data may need to be passed in for one Save is of no relevance … if you have to carry 500Kb of data for that screen then, well, you have to do it … 1 bucket of 500Kb or 50 buckets of 10Kb? … it doesn’t really matter as far as the actual transport part is concerned.
    As already answered, one can pass complex types in pl/sql … so one database call per Save would be my first random thought. There are lots of suspect things in here … some things you didn’t mentioned at all … like how is concurrency addressed? … have you/they implemented some sort of optimistic locking mechanism? Of course the architecture of your system won’t be solved in a forum … so, finding a good system/data/Oracle architect on site for the project would be my second random thought.
    PS. One last random thought … fight off that idea of packing and sending large strings (XML or not) … if the data is structured then contemplate XML for no more than few seconds.

  • How to use the Java objects or methods in pl/sql function as a parameter

    dear all,
    I java object passed as a parameter in pl/sql. how can i access the java objects as parameter in pl/sql function. please give a soultion to me
    mohan reddy

    I'm not sure whether this would help you.
    Have a look at this program to list files from a directory.
    CREATE GLOBAL TEMPORARY TABLE DIR_LIST
    ( FILENAME VARCHAR2(255) )
    ON COMMIT DELETE ROWS
    Table created.
    create or replace
    and compile java source named "DirList"
    as
    import java.io.*;
    import java.sql.*;
    public class DirList
    public static void getList(String directory)
    throws SQLException
    File path = new File( directory );
    String[] list = path.list();
    String element;
    for(int i = 0; i < list.length; i++)
    element = list;
    #sql { INSERT INTO DIR_LIST (FILENAME)
    VALUES (:element) };
    Java created.
    SQL>
    create or replace
    procedure get_dir_list( p_directory in varchar2 )
    as language java
    name 'DirList.getList( java.lang.String )';
    SQL> exec get_dir_list( 'C:\Bhagat' );
    PL/SQL procedure successfully completed.
    Thanks,
    Bhagat

  • SQL Query ( PL/SQL function body returning query ) page

    Hello Friends,
    I have a page with type SQL Query ( PL/SQL function body returning query ).
    I have written a pl/sql block that returns a sql query - select statment.
    Some times i am getting no data found error - does it got to do with the variable that stores the query .
    =======================
    ORA-06502: PL/SQL: numeric or value error: character string buffer too small
    Error ERR-1101 Unable to process function body returning query.
    OK
    =====================
    When the query is returned with records where exactly the records are stored is it in the variable declared in pl/sql block or with the Oracle Apex implicit cursor.
    Here's the pl/sql block ..
    The query is generated while the user is navigating through pages ..
    ====================
    declare
    l_return_stmt varchar2(32767);
    l_select varchar2(32000);
    l_from varchar2(32000);
    l_where varchar2(32000);
    l_order_by varchar2(32000);
    l_stmt_recordcount varchar2(32000);
    l_recordcount number ;
    begin
    l_select := 'select '||:P10_VARLIST1||:P10_VARLIST2||:P10_VARLIST3
    ||:P10_VARLIST4||:P10_VARLIST5;
    l_from := ' from '||:P10_RELATION;
    if length(:P10_WHERE) > 0 then
    l_where := ' where '||:P10_WHERE;
    else
    l_where := '';
    end if;
    if length(:P10_ORDER_BY) > 0 then
    l_order_by := ' order by '||:P10_ORDER_BY;
    else
    l_order_by := '';
    end if;
    l_return_stmt := l_select||l_from||l_where||l_order_by;
    :P10_STMT := l_return_stmt;
    return l_return_stmt;
    end;
    =============================
    Appreciate your help in this regard.
    thanks/kumar
    Edited by: kumar73 on Apr 22, 2010 6:38 AM

    It looks like the query string you are trying to pass back exceeds the 32K limit for a varchar. Where this is happening is kind of difficult to tell as it could be any number of points, and also depends on what you are passing into the process via page items.
    I would first try to establish what combination of page items causes this error to occur. Then, starting from the bottom and working your way backwards, I would start 'switching off' some of the items you use to build your query until it breaks again, thus establishing which part is leading to the error.
    Also, I'm not sure what :P10_STMT is doing (are you maybe using this for visiblity of the query created)?
    It looks like the query string you are trying to pass back exceeds the 32K limit for a varchar. Where this is happening is kind of difficult to tell as it could be any number of points, and also depends on what you are passing into the process via page items.
    I would first try to establish what combination of page items causes this error to occur. then, starting from the bottom and working your way backwards, I would start 'switching off' some of the items you use to build your query until it breaks again, thus establishing which part is leading to the error.
    Also, I'm not sure what :P10_STMT is doing (are you maybe using this for visiblity of the query created)?

Maybe you are looking for

  • Can I use apps from my itunes account on my pc.

    I want to use an app on my computer but can't figure out how. Is it possible?

  • How to display a field value in tcode MIR4

    Dear all      I want  to  display the bank control key of the vendor in transaction code MIR4. Now it is showing the bank account number and its description with the address of the vendor.      So, for that I think, I have to create a screen exit. Pl

  • User field in BAPI_ACC_DOCUMENT_POST

    hai friends, I am using BAPI_ACC_DOCUMENT_POST for GL posting. The user wants to populate values in the custom field in BSEG Table, say BSEG-ZZFLAT1 through  Bapi for posting. I populate the table EXTENSION1 in the BAPI. But it cannot update in the B

  • Problem with the usb drives

    After re-instal of the Lion my Macbook pro does not see any of the external hard drives, usb, phones etc. What can be the problem?

  • Need Information about cookies

    Hi I am developing a website. Now I want to put Remember me in the login page. I have following queries. 1) Cookies can be created, read through javascript and and also through JSP, which one I should opt for? 2) Can cookies created by JSP can be rea