Escaping sql quotes manually. (replace function)

I can't get a simple replace to work and am surprised at myself.
How do I replace every occurrence of either a 'single or "double quote with a backslash+quote (\' or \")?
(I need it for mysql escaping of selects. Before you jump that prepared statements do it, yes but Jboss-ejb does not, and I don't know how to tell jboss to do so.)
Anyhow this is a basic Java question, I tried the following to no avail:
public static String escapeMySqlSelect(String s){
     if ((s.indexOf("\"") >=0) || (s.indexOf("\'") >=0)) {
          s = s.replace("\"","\\\"");
          s = s.replace("\'","\\\'");
          return s;
}Whatever I try as the second argument for the replace, I get 1 of the following:
1) Same as original string.
2) TWO backslashes+quote.
3) A red-flag from Eclipse with some obscure error message. (Won't compile.)
Thanks
-nat

Further research;
Jboss automatically escapes the string internally (likely via prepared statement), therefore causing a problem if I also escaped it. BUT, I have yet to figure out exactly when it does so.
[And this threw me off completely ]There is definetly a BUG in ECLIPSE's (3.1) debugger!
The 'variables ' panel does not show the true value of the returned string. In other words, a println of the returned string will DIFFER with what the debugger is showing as the value.
Anyone with Eclipse can try it; with or without j2ee.
-nat

Similar Messages

  • Escape double quotes in replace formula in runcat.cmd

    Hi All,
    We are using command line (runcat.cmd) for search and replacing strings. I need to escape doble quotes from the formula. Please suggest a way to do it.
    For e.g,
    I want to replace
    <sawx:expr xmlns:xsd="http://www.w3.org/2001/XMLSchema" xsi:type="xsd:string">May</sawx:expr>
    with
    <sawx:expr xmlns:xsd="http://www.w3.org/2001/XMLSchema" xsi:type="xsd:string">Jun</sawx:expr>
    The complete string "<sawx:expr xmlns:xsd="http://www.w3.org/2001/XMLSchema" xsi:type="xsd:string">May</sawx:expr>" is not working as we need to
    override the double quotes.
    If anyone has achieved this, please let us know.
    Thanks,
    Nithin

    Hi MK,
    We want to ensure that this replace does not have unnecessary impacts. i.e. if a column formula contains "May", it should not be changed.
    The no of such reports are huge, hence we can not go to each and every report and modify the XML.
    Any other ideas?
    Thanks,
    Nithin

  • Invalid state in SQL query for a function that was created with no errors.

    SQL> CREATE OR REPLACE FUNCTION overlap(in_start1 IN TIMESTAMP, in_end1 IN TIMESTAMP, in_start2 IN TIMESTAMP, in_end2 IN TIMESTAMP) RETURN NUMBER
    2 IS
    3
    4 BEGIN
    5 IF (in_start1 BETWEEN in_start2 AND in_end2 OR in_end1 BETWEEN in_start2 AND in_end2 OR in_start2 BETWEEN in_start1 AND in_end1) THEN
    6 RETURN 0;
    7 ELSE
    8 RETURN 1;
    9 END IF;
    10 END;
    11 /
    Function created.
    SQL> show errors;
    No errors.
    SQL>
    SQL> SELECT * FROM tbl where overlaps(current_time,current_time+1,current_time-1,current_time+2) = 0;
    SELECT * FROM tbl where overlaps(current_time,current_time+1,current_time-1,current_time+2) = 0
    ERROR at line 1:
    ORA-06575: Package or function OVERLAPS is in an invalid state
    I do not understand why overlaps is returned as in invalid state in the query, when it was created with no errors earlier. Could anyone help me?

    Marius
    Looking at the logic you are trying to create it looks like you are looking for overlapping time periods.
    Consider two date/time ranges:
    Range 1 : T1 - T2
    Range 2 : T3 - T4
    Do they overlap?
    1) No: T1 < T4 (TRUE)  T2 > T3 (FALSE)
    T1 --- T2
               T3 --- T4
    2) Yes: T1 < T4 (TRUE)  T2 > T3 (TRUE)
    T1 ---------- T2
               T3 --- T4
    3) Yes: T1 < T4 (TRUE)  T2 > T3 (TRUE)
    T1 -------------------- T2
               T3 --- T4
    4) Yes: T1 < T4 (TRUE)  T2 > T3 (TRUE)
                   T1 ----- T2
               T3 --- T4
    5) Yes: T1 < T4 (TRUE)  T2 > T3 (TRUE)
               T1 --- T2
           T3 ------------ T4
    5) No: T1 < T4 (FALSE) T2 > T3 (TRUE)
                    T1 --- T2
           T3 --- T4Answer: Yes they overlap if:
    T1 < T4 AND T2 > T3
    So you can code the logic in your SQL as simply:
    SELECT *
    FROM tbl
    WHERE range1_start < range2_end
    AND    range_1_end > range2_startIf you go around implementing PL/SQL functions for simple logic that can be achieved in SQL alone then you cause context switching between the SQL and PL/SQL engines which degrades performance. Wherever possible stick to just SQL and only use PL/SQL if absolutely necessary.

  • Problem with DBMS_OUTPUT and SQL statment with a function

    I am using SQL Developer version 3.0.04 and I have a function that has a dbms_output statment in it. I am running the following SQL to select the output of that statment.
    select A.A_FUCTION('TEST') from dual;
    The output works fine but the dbms_output line does not show in the dbms_output window. I turned on the output window etc. and i can get the select to print out the output if i wrap it in a declare begin end wrapper... and then change the query to insert the return value into variable.
    just wondering if there is way to get the dbms_output to flush out with just an SQL statment instead of in a begin end wrapper etc.

    just wondering if there is way to get the dbms_output to flush out with just an SQL statment instead of in a begin end wrapper etc.works fine in sql*plus, so I guess it must be a preference or sth. in sql*developer:
    SQL> set serverout on
    SQL> create or replace function f1 (r int)
      2    return int
      3  as
      4  begin
      5    dbms_output.put_line ('Hello World ' || r);
      6    return r;
      7  end f1;
      8  /
    Function created.
    SQL>
    SQL> select f1 (rownum) f1 from dual connect by level <= 3
      2  /
            F1
             1
             2
             3
    3 rows selected.
    Hello World 1
    Hello World 2
    Hello World 3
    SQL>

  • SQL replace function in JDeveloper

    In SQL*Plus I run the following queries...
    select last_name, phone_number from employees
    LAST_NAME PHONE_NUMBER
    Chung 650.505.1876
    Dilly 650.505.2876
    Gates 916.764.6600
    select last_name, replace (phone_number, '.', '-') from employees
    LAST_NAME REPLACE(PHONE_NUMBER
    Chung 650-505-1876
    Dilly 650-505-2876
    Gates 916-764-6600
    If I try to use the "REPLACE" function in the JDeveloper by editing the sql statement in the view object editor and run the page the results returned for the phone number column on the page are blank.
    How can I substitute a dash for the period on the page?

    Try using AS:
    select last_name, replace (phone_number, '.', '-') AS phone_number from employees
    In this case is recommended for your VO a read only query.

  • SQL Replace function: errors if replacement text is 8191 characters

    Oracle 10.2.0.3.0 Enterprise Edition
    I'm working on an application which has a function to generate emails.
    We have a template, which gets filled with data from the database depending on the email being sent.
    To do this I'm using the Replace function to replace certain parts of the template with the right data.
    It seems that if the replacement text (the third argument to the function) is longer than 8191 bytes the function throws a PL/SQL: numeric or value error.
    This limitation doesn't appear to be documented anywhere, certainly nowhere that I can find.
    Anyone know of a way around this short of building my own replace function?

    I've figured out what was going on.
    The database column for the replacement text is defined as a clob, but there is a front end limit of 10,000 characters for the field being used.
    When using the replace function I was assigning the value to a varchar2(32767) field in the PL/SQL.
    So in terms of datatypes the function call is:
    varchar2 := replace(varchar2, varchar2, clob)
    If the length of the clob is over 8191 characters it errors.
    (Presumably because of the bug mentioned in this thread DBMS_LOB.SUBSTR() returning 8191 characters instead of 32767
    I've fixed it by simply changing the datatype of the variable to which the value is being assigned to a clob.

  • Escaping single quotes in SQL Statement

    I am getting SQL Statement error when i tried to have a value with a single quote in it ,inside my SQL Statement.
    e.g.
    INSERT INTO tblHoldings(Title) VALUES ('Developing Asia�s fibre processing through collaboration');
    here the Title to be inserted in the table tblHoldings is "Developing Asia�s fibre processing through collaboration"
    i used to trapped the single quote by using its escape character ( \ ) with this method and its fine with MySQL 4 but when I upgraded to MySQL 5.0.22, I now getting the SQL Statement error again.
    public String cleanse(String dirty) {
          String clean = dirty.replaceAll("\'", "\\\\'");         
          return clean;
      }    please help me..how can i trapped/escape single quote in MySQL 5 in Java?
    Thanks in advance for your help.

    No. Please use PreparedStatements. That is theonly
    correct answer to this question.Ok please tell us. how would you use prepare
    statement.. no just say USE PREPARE STATE.. givethe
    guy the code... or help..What size spoon would you like to be fed with? There
    was nothing about gob size in the original post.
    http://www.javaalmanac.com
    well duffymo.. i think you gave a link, is quite of help, but my friend preparestatement just gave "use preparestatement"..
    i think even you when you start coding you needed help... and some one just tell you use preparestatement how do you feel..
    There is a level of help. i think it will be (((as much as you can)))

  • Replace() function doesn't work in Application Designer?

    I'm using PeopleSoft Application Designer 8.51. I'm trying to do a simple Replace function so I can escape single quotes rather than allow them to blow up the sql query.
    &deptid = Replace(&deptid, "'", "''");
    App Designer chokes when I hit Save: "Invalid function parameter type. (2,19)"
    According to the docs I'm using this correctly: http://docs.oracle.com/cd/E26239_01/pt851h3/eng/psbooks/tace/book.htm?File=tace/htm/tace14.htm#H4095
    Even if I try to execute the example right out of the documentation, I get the same error: REPLACE("StringFun", "Fun", "Number");
    Is this a bug in app designer? REPLACE is a super common thing, it's not something obscure. How can this not work?
    Thanks in advance.

    I figured this out. “Replace” is a strange duck function that relies on offsets. “Substitute” is the magic I needed, works just like I was expecting Replace to work. The documentation I was reading on Replace was for “ PeopleSoft Analytic Calculation Engine” rather than peoplecode. I’ll pay closer attention to that next time. Maybe this will help someone else...

  • Replace function and '-' character

    Hello,
    How can I use '-' character in a REPLACE function?
    create or replace procedure zd authid current_user as
    begin
    execute immediate ' create table select ZDK
    Replace(SO_HEADER.ZDNUMBER,'' - '','' '') from so_header';
    end zd;
    Thanks a lot,

    Hm. I don't see that you want to replace the minus "-". If you truely ment the underscore "_" then you are right. Sometimes it must be escaped since it has the special meaning of "any single character" (same as the ? wildcard for microsoft users). However this is only true for the LIKE operator. Not for the REPLACE function.
    examples (non dynamic)
    select SUBSTR(Replace('123\456\789\', '\'),7,7) from dual;
    789
    select SUBSTR(Replace('123_456_789_', '_'),7,7) from dual;
    789The escape keyword in not allowed anywhere inside the replace function.
    What was your intended input and output?
    Just a recommendation. You don't need to specify the third paramater if you just want to remove the search string.
    And your insert statement is not dynamic. If you don't create the table dynamically then you can simply write the insert statement inside pl/sql without the need to make it dynamic. This would make testing and debugging much easier!
    Edited by: Sven W. on Jul 27, 2011 7:56 PM

  • 10g error on initjvm.sql during manual db creation

    Hi all,
    I get an error after my (manual) database ceation when I want to install a jvm (on Suse linux 10g), I hope you can help.
    I've done several 'clean' installations by hand and several 'full' installations using the dbca. But I want to have a 'clean' install from my own scripts (including a RON & use of inside java later), but this effort fails (after a neat installation) when I want to install the jvm using the initjvm.sql script.
    After my default database creation, I want to install the JVM, by starting:
    cd /u01/app/oracle/product/10.1.0/db_1/javavm/install
    sqlplus sys/[passwd] as sysdba @initjvm.sql 2>&1 | tee ~/setup_inst01/spool/initjvm.lst
    cd -At the end (or at least at the end of this run) I get the following error:
    begin if :jvmrmaction = 'NONE' then
    ERROR at line 1:
    ORA-29558: JAccelerator (NCOMP) not installed. Refer to Install Guide for
    instructions.
    ORA-06512: at "SYS.DBMS_JAVA", line 236
    ORA-06512: at line 2It seemed that this JAccelerator was not really necessary for a JVM to run. So I installed the JVM check funtion (which I've installed before on Metalink's advice):
    CREATE OR REPLACE FUNCTION XMLVER RETURN VARCHAR2 IS LANGUAGE JAVA NAME
    'oracle.xml.parser.v2.XMLParser.getReleaseVersion() returns java.lang.String';
    /Unfortunatelly it returned:
    ERROR at line 1:
    ORA-29540: class oracle/xml/parser/v2/XMLParser does not existThis gives me a clue the JVM is not installed properly.
    I've run the rmjvm.sql script and am searching for a way to install the jvm correctly using scripts (not the dbca).
    At this developing stage I'm not really able to contact Metalink, so I'm wondering how to install a JVM on a 10g database using scripts (10.1.0.3.0 on Linux). Anyone got an idea?
    Regards,
    Michiel

    So,
    I removed the JVM by running @rmjvm.sql in @ORA_HOME/javavm/install, then installed it again by running @initjvm.sql and ignored the error.
    Next was running @initxml.sql in $ORA_HOME/rdbms/admin, but that wasn't really right (so @rmxml.sql in the same dir). After I ran @initxml.sql from @ORA_HOME/xdk/admin, no problems!
    Regards,
    Michiel

  • Password change fails in SQL Developer with verify function...

    A couple of months ago I enforced a password verify function on our 11.2.0.3 databases and also one legacy 10.2.0.4 database.
    At the time I tested on my account (which had elevated privileges...doh!).   Now some users are hitting expiry, they can't change it via SQL Developer.
    If I create a user with 'create session' privilege and set their profile to one that uses the verify function (see both below), I then log in to SQL Developer (we have tried with versions 3.1 (Windows) and 3.2 (Linux) with same failure results.
    BTW,.. the password verify function enforces the following:
    password must be minimum of 8 characters
    password must not be the same as the user name, or user name (1-100)
    password must contain at least a single digit
    password must contain at least a single character
    1. Works = I log into the local server and run command line SQLPlus, type 'password' and update.   I can successfully change my password.
    2. Fails = I log into the local server and run command line SQLPlus, type 'alter user <me> identified by <newpwd>;' I get:
    TEST: SUTEMP > alter user sutemp identified by carport9999;
    alter user sutemp identified by carport9999
    ERROR at line 1:
    ORA-28221: REPLACE not specified
    This error is because the account does not have the 'alter user' privilege.   I'm okay with this, as I don't want our users having this privilege.
    3. I start SQL Developer 3.2, type 'alter user <me> identified by <newpwd>;' I get the same ORA-28221 error as above.   That is fine, and as expected.
    4. Now in SQL Developer, I type 'password', set a valid password, but I get 'Failed to change password' in the Script Output tab.
    I have a database 'after servererror on database' trigger set, and querying the database table it is logging into, I see a record with a date stamp matching my failure with a server_error=28221 (the same as above).
    So I'm wondering if I'm doing something wrong here, or if this is a bug in SQL Developer.   I don't want standard users having 'alter user' privileges, but I do want to enforce password verification.
    I get the same result on three 11.2.0.3 databases (haven't tried any more but suspect same results for others) and one legacy 10.2.0.4 database, and using SQL Developer 3.1 and 3.2.
    DBA_PROFILE used:
    PROFILE   
    RESOURCE_NAME  
    RESOURCE LIMIT
    CTRU  
    COMPOSITE_LIMIT  
    KERNEL     DEFAULT
    CTRU  
    SESSIONS_PER_USER  
    KERNEL     10
    CTRU  
    CPU_PER_SESSION  
    KERNEL     DEFAULT
    CTRU  
    CPU_PER_CALL  
    KERNEL     DEFAULT
    CTRU  
    LOGICAL_READS_PER_SESSION    KERNEL     DEFAULT
    CTRU  
    LOGICAL_READS_PER_CALL  
    KERNEL     DEFAULT
    CTRU  
    IDLE_TIME  
    KERNEL     DEFAULT
    CTRU  
    CONNECT_TIME  
    KERNEL     DEFAULT
    CTRU  
    PRIVATE_SGA  
    KERNEL     DEFAULT
    CTRU  
    FAILED_LOGIN_ATTEMPTS  
    PASSWORD 10
    CTRU  
    PASSWORD_LIFE_TIME  
    PASSWORD 180
    CTRU  
    PASSWORD_REUSE_TIME  
    PASSWORD DEFAULT
    CTRU  
    PASSWORD_REUSE_MAX  
    PASSWORD 5
    CTRU  
    PASSWORD_VERIFY_FUNCTION     PASSWORD VERIFY_FUNCTION_11G
    CTRU  
    PASSWORD_LOCK_TIME  
    PASSWORD .002
    CTRU  
    PASSWORD_GRACE_TIME  
    PASSWORD 21
    16 rows selected.
    Verify Function used:
    $ cat utlpwdmg.sql
    Rem
    Rem $Header: utlpwdmg.sql 02-aug-2006.08:18:05 asurpur Exp $
    Rem
    Rem utlpwdmg.sql
    Rem
    Rem Copyright (c) 2006, Oracle. All rights reserved.
    Rem
    Rem    NAME
    Rem      utlpwdmg.sql - script for Default Password Resource Limits
    Rem
    Rem    DESCRIPTION
    Rem      This is a script for enabling the password management features
    Rem      by setting the default password resource limits.
    Rem
    Rem    NOTES
    Rem      This file contains a function for minimum checking of password
    Rem      complexity. This is more of a sample function that the customer
    Rem      can use to develop the function for actual complexity checks that the
    Rem      customer wants to make on the new password.
    Rem
    Rem    MODIFIED   (MM/DD/YY)
    Rem    suren       05/09/13 - customise for NIHI use
    Rem    asurpur     05/30/06 - fix - 5246666 beef up password complexity check
    Rem    nireland    08/31/00 - Improve check for username=password. #1390553
    Rem    nireland    06/28/00 - Fix null old password test. #1341892
    Rem    asurpur     04/17/97 - Fix for bug479763
    Rem    asurpur     12/12/96 - Changing the name of password_verify_function
    Rem    asurpur     05/30/96 - New script for default password management
    Rem    asurpur     05/30/96 - Created
    Rem
    -- This script sets the default password resource parameters
    -- This script needs to be run to enable the password features.
    -- However the default resource parameters can be changed based
    -- on the need.
    -- A default password complexity function is also provided.
    -- This function makes the minimum complexity checks like
    -- the minimum length of the password, password not same as the
    -- username, etc. The user may enhance this function according to
    -- the need.
    -- This function must be created in SYS schema.
    -- connect sys/<password> as sysdba before running the script
    CREATE OR REPLACE FUNCTION verify_function_11G
    (username varchar2,
      password varchar2,
      old_password varchar2)
      RETURN boolean IS
       n boolean;
       m integer;
       differ integer;
       isdigit boolean;
       ischar  boolean;
       ispunct boolean;
       db_name varchar2(40);
       digitarray varchar2(20);
       punctarray varchar2(25);
       chararray varchar2(52);
       i_char varchar2(10);
       simple_password varchar2(10);
       reverse_user varchar2(32);
    BEGIN
       digitarray:= '0123456789';
       chararray:= 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
       -- Check for the minimum length of the password
       IF length(password) < 8 THEN
          raise_application_error(-20001, 'Password length less than 8');
       END IF;
       -- Check if the password is same as the username or username(1-100)
       IF NLS_LOWER(password) = NLS_LOWER(username) THEN
         raise_application_error(-20002, 'Password same as or similar to user');
       END IF;
       FOR i IN 1..100 LOOP
          i_char := to_char(i);
          if NLS_LOWER(username)|| i_char = NLS_LOWER(password) THEN
            raise_application_error(-20005, 'Password same as or similar to user name ');
          END IF;
        END LOOP;
       -- Check if the password contains at least one letter, one digit
       -- 1. Check for the digit
       isdigit:=FALSE;
       m := length(password);
       FOR i IN 1..10 LOOP
          FOR j IN 1..m LOOP
             IF substr(password,j,1) = substr(digitarray,i,1) THEN
                isdigit:=TRUE;
                 GOTO findchar;
             END IF;
          END LOOP;
       END LOOP;
       IF isdigit = FALSE THEN
          raise_application_error(-20008, 'Password must contain at least one digit, one character');
       END IF;
       -- 2. Check for the character
       <<findchar>>
       ischar:=FALSE;
       FOR i IN 1..length(chararray) LOOP
          FOR j IN 1..m LOOP
             IF substr(password,j,1) = substr(chararray,i,1) THEN
                ischar:=TRUE;
                 GOTO endsearch;
             END IF;
          END LOOP;
       END LOOP;
       IF ischar = FALSE THEN
          raise_application_error(-20009, 'Password must contain at least one digit, and one character');
       END IF;
       <<endsearch>>
       -- Check if the password differs from the previous password by at least
       -- 3 letters
       IF old_password IS NOT NULL THEN
         differ := length(old_password) - length(password);
         differ := abs(differ);
         IF differ < 3 THEN
           IF length(password) < length(old_password) THEN
             m := length(password);
           ELSE
             m := length(old_password);
           END IF;
           FOR i IN 1..m LOOP
             IF substr(password,i,1) != substr(old_password,i,1) THEN
               differ := differ + 1;
             END IF;
           END LOOP;
           IF differ < 3 THEN
             raise_application_error(-20011, 'Password should differ from the old password by at least 3 characters');
           END IF;
         END IF;
       END IF;
       -- Everything is fine; return TRUE ;
       RETURN(TRUE);
    END;
    alter profile ctru limit password_verify_function verify_function_11g;
    alter profile default limit password_verify_function verify_function_11g;
    alter profile web_and_it limit password_verify_function verify_function_11g;

    okay,... I just saw another website which shows I should put in the 'replace <oldpwd>' clause in.
    This works in SQL Developer:     alter user sutemp identified by carport999 replace garage999;
    So why does the 'password' command fail?     (Developers:  it would also be helpful to have the ORA- error displayed as opposed to 'Failed to change password')

  • SQL query with object function

    I want to write a function, which returns more than one value and to include those values into a SQL statement. For example I want to query the RDB with....
    select t.id, my_function(t.id).value1 name, my_function(t.id).value2 address ....
    from table_x t
    where t.id between 1 and 10
    and bitand(my_function(t,id)).sec_id,2)>3
    Is it possible to do something like this?
    I tried to use object and table of objects(my_type) to return value of my_type but when I used
    select ......my_function(t.id).name,my_function(t.id).address ...
    from table_x
    where t.id=some_value;
    the function was called twice(i expected this result, but i don't know how to avoid it).
    Simple example
    CREATE OR REPLACE TYPE l_test AS OBJECT
    id NUMBER(10),
    name varchar2(100),
    a_date date
    CREATE OR REPLACE FUNCTION test_f2(test_number IN NUMBER)
    RETURN l_test
    IS
    a number;
    BEGIN
    select t_seq.nextval into a from dual;
    return l_test(a,'test value ='||test_number,sysdate+test_number);
    END;
    select test_f2(i.id).id client_id, test_f2(i.id).name client_name from r_owners i
    CLIENT_ID CLIENT_NAME
    1 test value =1
    3 test value =2
    I want to be able to loop in cursor and use those values
    All ideas are welcome!
    Thanks,
    Iassen Houbenov

    Check it out...
    SQL> CREATE OR REPLACE TYPE emp_add AS OBJECT
      2  (  office VARCHAR2(50),
      3     location VARCHAR2(50),
      4      MEMBER FUNCTION get_office RETURN VARCHAR2,
      5      MEMBER FUNCTION get_location RETURN VARCHAR2,
      6      CONSTRUCTOR FUNCTION emp_add(id NUMBER) RETURN SELF AS RESULT,
      7      CONSTRUCTOR FUNCTION emp_add(id NUMBER, office VARCHAR2,location VARCHAR2) RETURN
      8        SELF AS RESULT
      9  ) NOT FINAL;
    10  /
    Type created.
    SQL> CREATE OR REPLACE TYPE BODY emp_add IS
      2      MEMBER FUNCTION get_office RETURN VARCHAR2
      3      IS
      4      BEGIN
      5          RETURN SELF.office;
      6      END;
      7      MEMBER FUNCTION get_location RETURN VARCHAR2
      8      IS
      9      BEGIN
    10          RETURN SELF.location;
    11      END;
    12      CONSTRUCTOR FUNCTION emp_add(id NUMBER)
    13          RETURN SELF AS RESULT
    14      IS
    15      BEGIN
    16         SELECT dname, loc
    17         INTO   SELF.office, SELF.location
    18         FROM   dept
    19         WHERE  deptno = id;
    20         RETURN;
    21      END;
    22      CONSTRUCTOR FUNCTION emp_add(id NUMBER, office VARCHAR2,location VARCHAR2)
    23          RETURN SELF AS RESULT
    24      IS
    25      BEGIN
    26         SELF.office := office;
    27         SELF.location := location;
    28         RETURN;
    29      END;
    30  END;
    31  /
    Type body created.
    SQL> SELECT e.ename, e.d.office, e.d.location 
      2  FROM   ( SELECT ename
      3                 , (SELECT emp_add(emp.deptno) FROM dual ) d
      4           FROM   emp ) e
      5  /
    ENAME      D.OFFICE
    D.LOCATION
    SMITH      RESEARCH
    DALLAS
    ALLEN      SALES
    CHICAGO
    WARD       SALES
    CHICAGO
    ....Smoke me a kipper I'll be back before breakfast.
    Cheers, APC

  • Replace function not working for XML CLOB data

    Hi all,
    I am generating XML using DBMS_XMLGEN in oracle 10g. After generating the XML, I am replacing the ROW tags with appropriate tag name using REPLACE function. Sometimes the tag name is not replaced correctly.
    Eg.I am replacing </Cargo_ROW> with </CargoDetail>. But sometimes in one xml, this tag is coming as </CargoDetROW> or </CargoDetaiW>. The XML size is always huge and the same tag is repeated so many time in the loop and in the same XML, only one tag will be replaced incorrectly. This also not happening for all XMLs.
    If any one knows the cause about this problem or solution, please share the same.
    thanks,

    Yes Anton, you are right..
    It was typecasting problem
    replace supports clob
    Check this out
    SQL> declare
      2  xmldata clob;
      3  Begin
      4  xmldata:='<Message transaction_log_id="" extraction_date="25/11/09 09:52:03 AM" versio
      5  <Transaction>
      6  <TransactionType>ORIGINAL</TransactionType>
      7  <ControlNumber>60022449779</ControlNumber>
      8  <BookingHeader>
      9  <PortCodeOriginal>GBSOU</PortCodeOriginal>
    10  <Contact>.</Contact>
    11  <PhoneContact>.</PhoneContact>
    12  </BookingHeader>
    13  <PartyInformation>
    14  <PartyDetails>
    15  <PartyId>10002866</PartyId>
    16  <Type>SHIP</Type>
    17  <Name1>L LTD.</Name1>
    18  </PartyDetails>
    19  </PartyInformation>
    20  <Cargo>
    21  <CargoDetROW>
    22  <CargoHeader>
    23  <CargoReceivedSeqNo>600015391790</CargoReceivedSeqNo>
    24  <CargoId>RW9330P013948</CargoId>
    25  </CargoHeader>
    26  <CargoDimensions>
    27  <Length>1</Length>
    28  <Width>2</Width>
    29  </CargoDimensions>
    30  </CargoDetail>
    31  <CargoDetROW>
    32  <CargoHeader>
    33  <CargoReceivedSeqNo>600015391791</CargoReceivedSeqNo>
    34  <CargoId>RW9330P01394AA</CargoId>
    35  </CargoHeader>
    36  <CargoDimensions>
    37  <Length>2</Length>
    38  <Width>2</Width>
    39  </CargoDimensions>
    40  </CargoDetail>
    41  <Cargo_ROW>
    42  <CargoHeader>
    43  <CargoReceivedSeqNo>600015391792</CargoReceivedSeqNo>
    44  <CargoId>RW9330P01322</CargoId>
    45  </CargoDetaiW>
    46  <CargoDimensions>
    47  <Length>1</Length>
    48  <Width>2</Width>
    49  </CargoDimensions>
    50  </Cargo_ROW>
    51  </Cargo>
    52  </Transaction>
    53  </Message>';
    54  xmldata:=to_clob(regexp_replac(xmldata,'</Cargo_ROW>|</CargoDetaiW>|</CargoDetROW>','</CargoDetail'));
    55  xmldata:=to_clob(regexp_replace(xmldata,'<Cargo_ROW>|<CargoDetaiW>|<CargoDetROW>','<CargoDetail>'));
    56  dbms_output.put_line(xmldata);
    57  end;
    58  /
    <Message transaction_log_id="" extraction_date="25/11/09 09:52:03 AM"
    version="1.0">
    <Transaction>
    <TransactionType>ORIGINAL</TransactionType>
    <Contro
    lNumber>60022449779</ControlNumber>
    <BookingHeader>
    <PortCodeOriginal>GBSOU</Por
    tCodeOriginal>
    <Contact>.</Contact>
    <PhoneContact>.</PhoneContact>
    </BookingHead
    er>
    <PartyInformation>
    <PartyDetails>
    <PartyId>10002866</PartyId>
    <Type>SHIP</Ty
    pe>
    <Name1>L
    LTD.</Name1>
    </PartyDetails>
    </PartyInformation>
    <Cargo>
    <CargoDetail>
    <CargoHea
    der>
    <CargoReceivedSeqNo>600015391790</CargoReceivedSeqNo>
    <CargoId>RW9330P01394
    8</CargoId>
    </CargoHeader>
    <CargoDimensions>
    <Length>1</Length>
    <Width>2</Width>
    </CargoDimensions>
    </CargoDetail>
    <CargoDetail>
    <CargoHeader>
    <CargoReceivedSeq
    No>600015391791</CargoReceivedSeqNo>
    <CargoId>RW9330P01394AA</CargoId>
    </CargoHe
    ader>
    <CargoDimensions>
    <Length>2</Length>
    <Width>2</Width>
    </CargoDimensions>
    <
    /CargoDetail>
    <CargoDetail>
    <CargoHeader>
    <CargoReceivedSeqNo>600015391792</Carg
    oReceivedSeqNo>
    <CargoId>RW9330P01322</CargoId>
    </CargoDetail>
    <CargoDimensions>
    <Length>1</Length>
    <Width>2</Width>
    </CargoDimensions>
    </CargoDetail>
    </Cargo>
    </Transaction>
    </Message>
    PL/SQL procedure successfully completed.
    SQL> Twinkle
    Edited by: Twinkle on Nov 26, 2009 6:05 PM

  • Queries on pl/sql tables within a function

    hi,
    how can i execute regular sql-queries within a function on a pl/sql table which the function has recieved as a parameter ? i have tried quite a bit and always get type mismatches or internal errors. anybody has a good example on this ?
    thanks in advance,
    stephan

    hi,
    okay, i will not post the actual code i have, because it won't make too much sense out of the context, but here are the relevant parts...
    i have a few object definitions that represent the records of the three tables (two input and one output)...
    create type t1 as object (...);
    create type t2 as object (...);
    create type t3 as object (...);
    and a package with the table definitions
    create or replace package t_defs as
    type tab_t1 is table of t1;
    type tab_t2 is table of t2;
    type tab_t3 is table of t3;
    end t_defs;
    and here is a rough sketch what the function should look like later:
    CREATE OR REPLACE FUNCTION some_function (
    tab1 IN t_defs.tab_t1, tab2 IN t_def.tab_t2)
    RETURN t_defs.tab_t3 PIPELINED IS
    TYPE refcur IS REF CURSOR;
    cur0 refcur;
    curr_rec t3 := t3(NULL, ....);
    BEGIN
    open cur0 for 'here is the statement i could not do';
    LOOP
    FETCH cur0 INTO curr_rec.....;
    EXIT WHEN cur0%NOTFOUND;
    . -- (manipulate the record) --
    PIPE ROW(curr_rec);
    END LOOP;
    RETURN;
    END;

  • Replace function in TT7

    Hi,
    I have a database in TT Release 7.0.3.1.0 and other in Release 11.2.2.4.0. I need use replace sql function over Release 7.0.3.1.0.
    I know that it not apply in this version but I've tried with ttIsqlCS in node with TT11 through connection in database TT7 but I received this error:
    ttIsqlCS database_test_R7
    Command> select replace('asjkhdfkhaskdh','a','1') from dual;
    2818: Unknown function REPLACE
    The command failed.
    Command> version;
    TimesTen Release 11.2.2.4.0
    Any idea ??
    Thanks in advance.
    Babs.

    Hi Babs,
    I am afraid that you are out of luck. SQL is implemented in the TimesTen engine/libraries not in the ttIsql client. Since 7.0 SQL does not have th REPLACE() function there is no way to execute that in 7.0 regardless of the client you use. You'll need to find some other option to accomplish what you require (maybe upgrade the 7.0 database to 11.2.2?).
    Chris

Maybe you are looking for

  • Adobe Cloud

    I have the Adobe Cloud downloaded on my desktop and have used the Photoshop program. I also purchased it so I can continue using it. At this time, I am unable to open my photoshop documents for further editing. It says I have already purchased a plan

  • VENDOR MASTER REPORT

    HELLO, In SAP MM there is a transaction s_alr_87012089 for general vendor master.And the standard report is RFKABL00.This report shows the value of fields F_new and F_Old if the created document in changed.But if the document is not chnaged it shows

  • Unabl eto share Internet connection through Airport

    I have a new Samsung wave S8500. I'm trying to access the internet connection shared by my mac on the airport, everytime i try to connect to my mac through the Wi-Fi on my phone, it doesn't connect. I put a 40 bit WEP Key length on the sharing option

  • New laptop spec suggestions for Photoshop and Illustrator

    Hi Everyone! As I am sifting through the posts regarding laptops - I figured I'd post my own as my requirements are a little different.  I am looking to buy a new windows laptop.  I work with Photoshop and Illustrator and basic office programs like o

  • Follow-on Question:  special character in SED routine

    ref. http://discussions.apple.com/thread.jspa?threadID=1281065&tstart=0 Camelot successfully answered my specific question in the above thread. When I closed that out, I tacked on a related question -- but either that was missed or there's not a stra