Set_context is truncating my string?

I have a procedure where I receive several parameters and buid a query based on this params:
IF keyword IS NOT NULL THEN
     dbms_session.set_context('PESQ_CTX', 'keyword', keyword);
     query := query || 'CONTAINS(ed_fotos.detalhe, sys_context(''PESQ_CTX'', ''keyword'')) > 0 AND ';
END IF;
As far as I can see when I register the keyword variable using set_context, the variable string is truncated. Keywors is a mixt of several comparisons: '({SANDY} within description OR {SANDY} within headline etc... )'
When the variable string is large, it is truncated and the variable looses the closing parentesis, causing an Oracle text error:
ORA-29902: error in executing ODCIIndexStart() routine
ORA-20000: Oracle Text error:
DRG-50901: text query parser syntax error on line 1
Is there anyway to avoid this problem? Does the variable registered has a limit of 255 characters? Using short variables I dont receive any error.
If I build the query without the context it works, but set_context should improve the performance
IF keyword IS NOT NULL THEN
     --dbms_session.set_context('PESQ_CTX', 'keyword', keyword);
     query := query || 'CONTAINS(ed_fotos.detalhe, ''' || keyword || ''') > 0 AND ';
END IF;

The default return size for sys_context is 256.
if you need more than that, you need to provide the optional third parameter, the length (up to 4000)

Similar Messages

  • Embedded Single Quote in SQL Column truncates Java String

    I have a jsp web page that queries a database to see what day a user is registered for and then produces an URL for the user to click on. My problem is that the URL being processed stops when an embedded single quote is encountered.
    Here is the database side:
    Database side:
    Create Table registration
    (reg_id int not null,
    name varchar2(45) not null,
    day_nb int not null);
    Insert into registration
    (reg_id, name, day_nb)
    values (1043,'Johnny''s Diner', 1);
    Select name, day_nb from registration
    where reg_id = 1043;
    name, day_nb
    Johnny's Diner 1
    Snippet of relevant java code: (JSP page)
    <%
    int day_nb = rs.getInt("day_nb");
    String particpant_name = rs.getString("name");
    System.out.println("registration.jsp: particpant_name = " + particpant_name);
    %>
    <td width="84%">
         <a
         href='<%=response.encodeURL("registrationHandler.jsp?"particpant_name="+ particpant_name + "&day_nb="+ day_nb)%>'><%=particpant_name%>
                                  </a>
                             </td>
    {code}
    The following is printed to System.Out:
    registration.jsp: particpant_name = Johnny's Diner
    The code produces the following URL
    http://www.mycompany.com/registrationHandler.jsp?particpant_name=Johnny
    The response.encodeURL is stopping on the single quote contained in "Johnny's Diner"
    The URL I want is:
    http://www.mycompany.com/registrationHandler.jsp?particpant_name=Johnny's Diner&day_nb=1
    How do I account for the embedded single quote so the code works properly? Thanks In Advance!                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

    You really need to read up on [SQL Injection|http://en.wikipedia.org/wiki/SQL_injection] and [XSS/Cross-Site Scripting|http://de.wikipedia.org/wiki/Cross-Site_Scripting]. Both present massive security problems and your code seems prone to easily producing both.
    For SQL Injection attacks the correct solution is to always use PreparedStatements with only hard-coded String (i.e. never use String concatenation to build SQL statements).
    For XSS attacks the solution is a bit harder, but basically you need to learn never to trust user input (that includes user input that you've previously stored in the database!) and always escape what the user sent when you print it back out.

  • Regarding String truncation

    Hello all,
    I have got a small problem. Hope you will help me.
    I have got a text String which contains both single byte characters and multi-byte characters mixed up(English characters and non-english characters) which i need to insert into database table. Now the database column is set to store a text of maximum length of 100 bytes so it is required to truncate the string before insertion. Now the problem is when i extract the first 100 bytes from the string, the last character of the string sometimes gets changed( due to extracting only first byte of multi-byte character). The dumbest solution I thought to get around this is something like this:
                    //Here remarks contains the string value
         if (null!= remarks && remarks.getBytes().length > 100 ) {
                          while (remarks.getBytes().length > 100) {
                               remarks = remarks.substring(0, remarks.length()-1 );
                     }I am wondering is there any other elegant solution for this as the loop part is time-consuming and moreover, i am inserting the records in a count of thousands.

    Thanks for your reply
    Why do you have to do that on your own? It's the databases task to correctly truncate a String, if necessary (and inform you of the fact by issuing a Warning).
    But when i insert a string of size greater than 100 bytes i am getting an SQL Exception.
    Also, is the size of the text field really restricted by the number of bytes instead of the number of characters? I've seen that in some DBs (can't remember which ones), but it's a pretty bad idea and fortunately not all do it that way.
    I am using Oracle9i and the size of text field is restricted by the number of bytes.
    Also, your code assumes that the database uses the same encoding as the default locale of the machine running your code. Workaround: find out the encoding of the Database and use that when calling getBytes().Points taken. Thanks.

  • String too long, how to auto-truncate it?

    Is there any general purpose add-on which can detect a string is
    too long to insert/update for a database field, and truncate the
    string to insert/update instead of getting ORA-01401 exception?

    I strongly suggest you don't truncate data going into your database. Data in the database should be complete (and valid). Better to limit a user's input to the size of the field in the database by such methods as only providing an input field of x character size so he can't type in too many characters. If a user types in data and its retrieved truncated, he's going to be mad.
    The question is, how large should a column be? If you set the max size to the max size if your current data set, then a future data value may be too large. I don't know the answer to this, but I suggest you be consistent for the same type of columns in multiple tables. For example, if you set the email address to 255 characters in one table, it should be the same in all tables.
    See: http://www.javapractices.com/topic/TopicAction.do?Id=211

  • Flat file truncation issue

    I am attempting to perform a fairly standard operation, extract a table to a flat file.
    I have set all the schemas, models and interfaces, and the file is produced how I want it, apart from one thing. In the source, one field is 100 characters long, and in the output, it needs to be 25.
    I have set the destination model to have a column physical and logical length of 25.
    Looking at the documentation presented at http://docs.oracle.com/cd/E25054_01/integrate.1111/e12644/files.htm - this suggests that setting the file driver up to truncate fields should solve the issue.
    However, building a new file driver using the string 'jdbc:snps:dbfile?TRUNC_FIXED_STRINGS=TRUE&TRUNC_DEL_STRINGS=TRUE' does not appear to truncate the output.
    I noticed a discrepancy in the documentation - the page above notes 'Truncates strings to the field size for fixed files'. The help tooltip in ODI notes 'Truncates the strings from the fixed files to the field size'. Which might explain the observed lack of truncation.
    My question is - what is the way to enforce field sizes in a flat file output?
    I could truncate the fields separately in each of the mapping statements using substr, but that seems counter-intuitive, and losing the benefits of the tool.
    Using ODI Version:
    Standalone Edition Version 11.1.1 - Build ODI_11.1.1.5.0_GENERIC_110422.1001

    bump
    If this is an elementary issue, please let me know what I've missed in the manual.

  • Discoverer desktop excel export truncates to 255 chars

    Hi,
    I am using both the desktop and web version of Discoverer (10g). I noticed that if i export a file using desktop, then data in every cell is truncated to 255 chars (which is the excel limit). However, the same does not happen if I export using web version. Any suggestions on what i can do so that even the desktop export will not limit the chars to 255? I guess there is some way, since the web version is able to it. Please let me know!
    Thanks.
    A

    I am experiencing the same issue. has anyone got a solution to this issue? i dont really want to truncate the string if possible

  • Truncate byte array of UTF-8 characters without corrupting the data?

    Hi all,
    I need to be able to determine if the byte array, which is truncated from the original byte array representing UTF-8 string, contains corrupted character. Knowing if the byte array contains corrupted character allows me to remove it from the truncated array.
    As in the sample code below, when truncate the string with 16 bytes it displays ok. However, truncate with 17 bytes, the last character is corrupted. Is there a way to check to see if the character is corrupted so that it can be removed from the truncated byte array?
    Thanks in advance,
    Phuong
    PS: The Japanese characters I chose it randomly from Unicode charts. I don't know their meaning so if it is offensive, please forgive me.
    import java.awt.BorderLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.io.UnsupportedEncodingException;
    import javax.swing.BoxLayout;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import javax.swing.JScrollPane;
    import javax.swing.JTextArea;
    import javax.swing.SwingUtilities;
    public class TestTruncateUTF8 extends JFrame
        private static final long serialVersionUID = 1L;
        private JTextArea textArea = new JTextArea(5,20);
        private JLabel japanese = new JLabel("Japanese: " + "\u65e5\u672c\u3041\u3086\u308c\u306e");
         * @param args
        public static void main(String[] args)
            SwingUtilities.invokeLater(new Runnable() {
                @Override
                public void run()
                    JFrame frame = new TestTruncateUTF8();
                    frame.setVisible(true);
        public TestTruncateUTF8()
            super("Test Truncated");
            JButton truncate17Button = new JButton("Truncate 17 bytes");
            truncate17Button.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e)
                    truncates(17);
            JButton truncate16Button = new JButton("Truncate 16 bytes");
            truncate16Button.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e)
                    truncates(16);
            JPanel panel1 = new JPanel();
            panel1.setLayout(new BoxLayout(panel1, BoxLayout.Y_AXIS));
            panel1.add(japanese);
            panel1.add(truncate16Button);
            panel1.add(truncate17Button);
            panel1.add(new JScrollPane(textArea));
            this.setLayout(new BorderLayout());
            this.add(panel1, BorderLayout.CENTER);
            this.pack();
            this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        private void truncates(int numOfBytesToTruncate)
            try
                byte[] bytes = japanese.getText().getBytes("UTF-8");
                byte[] newBytes = new byte[numOfBytesToTruncate];
                System.arraycopy(bytes, 0, newBytes, 0, numOfBytesToTruncate);
                TestTruncateUTF8.this.putTextInsideJTextArea(bytes, newBytes);
            catch (UnsupportedEncodingException e1)
                e1.printStackTrace();
        private void putTextInsideJTextArea(byte[] original, byte[] truncated)
            try
                textArea.append("\nOriginal String:  " + new String(original, "UTF-8"));
                textArea.append("\nTruncated String: " + new String(truncated, "UTF-8"));
                textArea.append("\n*****************************\n");
            catch (UnsupportedEncodingException e)
                e.printStackTrace();
    }

    Since the byte array is in UTF-8, you can easily examine whether it is corrupt or not by taking a look at the last 4 bytes (at most). That is because the bit distribution of each byte (1st, 2nd, 3rd, and 4th) in UTF-8 encoding is well defined in its spec.
    BTW, a Japanese Hiragana/Kanji character typically has 3 bytes in UTF-8, so truncating with neither 16 nor 17 bytes would produce correct truncation.
    HTH,
    Naoto

  • Legend truncated in charts

    Hello!
    BI truncates long string in charts legend. How to disable this feature or change length?

    If you want to alter it for all graphs add : TruncateDownTo='500' to the PCXML file in the Legend tag:
    <Legend Name='legend'>
                   <Properties TruncateDownTo='500' BorderType='None' GrowVerticalMaxHeight='1000' MinimumFontSize='9'Font='Size:9;'/>
    </Legend>
    Regards John
    http://www.obiee101.blogspot.com/

  • Single string tag expanded into 100 plc register values

    I found a way to read 100 registers of plc data with a single string tag, if you can guarantee that none of the plc registers are zero. A register value of zero acts like a Null ascii terminator and truncates the string. Define the string tag as 200 bytes and uncheck the text data only box. Use the code in the attached picture to convert the string bytes back into decimal register values.
    Attachments:
    string tag to 100 U16 values.gif ‏2 KB

    Ins't that code exactly the same as typecasting to an U16 Array?
    Message Edited by altenbach on 05-19-2005 07:24 AM
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    CastingU16.gif ‏3 KB

  • Multi-lingual String Shortening

    Hey all,
    I've got a program that allows the user to name certain objects. These names need to be displayed in a variety of places and there may different amounts of space. I didn't like JLabel's default way of displaying names that are too long to fit. For example, the user would enter A really Long Name 17 and the JLabel might show A really Lo..., which just woudn't work if the number at the end were important.
    So I came up with a series of heuristics that seem to work well. For example, I remove spaces and capitalize the first letter in each word, and remove vowels. Only if the string is still too long do I truncate the string, but even when truncating I keep any number at the end. In the above example, I end up with something like: ARllyLngNm17. All things considered, it's pretty legible.
    The problem is this: it only works in english. I could extend my concept of vowels to include vowels with accents, and many European languages will probably work well, but how do I identify vowels with accents? Is there a trick I'm missing? Any ideas what I can do for Languages I know nothing about, like Arabic and Chinese? Has someone else solved this problem already?
    thanks for any tips!
    Bjorn

    Thanks for the suggestions. It seems like what I'll need is a list of possible word-separators, and a list of characters that can be removed (like vowels in English). It sounds like I could make this work reasonably well in some languages and revert to truncation in other languages, which is really the best I can do in, say Chinese.
    I tried to create a list of vowels from the special characters list in OS X's TextEdit. It seems to work in many cases, but I ended up with a grave accent over an r, after shortening. A little more investigation seems to suggest that in addition to single-charactor unicode codes that indicate a particular character with an accent, there are also unicode character which places an accent on the preceding character, which complicates maters quite a bit.

  • Regarding data truncation

    Hello,
    I have a currency field in the backend ( CURR 13 ). The data stored in the table is say 34.838.839,00.
    Now when I extract this field to BW, I can see the data in PSA as required.
    But when it gets loaded to the master data infoobject, the data is seen as 3483884.
    The infoobject corresponding to this field is of type NUMC 14. I cannot make it of type CURR as it is should be a characteristic, not a key figure.
    I believe this is because of a conversion routine problem.
    Could someone help me out pls?
    Regards,
    Suraj

    Thanks for your reply
    Why do you have to do that on your own? It's the databases task to correctly truncate a String, if necessary (and inform you of the fact by issuing a Warning).
    But when i insert a string of size greater than 100 bytes i am getting an SQL Exception.
    Also, is the size of the text field really restricted by the number of bytes instead of the number of characters? I've seen that in some DBs (can't remember which ones), but it's a pretty bad idea and fortunately not all do it that way.
    I am using Oracle9i and the size of text field is restricted by the number of bytes.
    Also, your code assumes that the database uses the same encoding as the default locale of the machine running your code. Workaround: find out the encoding of the Database and use that when calling getBytes().Points taken. Thanks.

  • To replace "\" with "/" in a string using FrameMaker API

    How to replace "\folder1\folder2\folder3" with "folder1/folder2/folder3" using framemaker API ?

    Hi Asha,
    Here is a function that I use for substring replacement, using all FDK library functions. If you use standard C libraries instead, you could probably reduce this to a line or two.
    To use it, you would send something like:
    path = F_StrCopyString("\\folder1\\folder2\\folder3");
    strReplace(path, "\\", "/", False);
    There might be better ways to do this. I'm not really that much of a programmer.
    Russ
    //returns the index of the first change, or -1 if no changes.
    IntT ws_StrReplace(StringT *mainString,
                       StringT searchString,
                       StringT replaceString,
                       IntT considerCase)
      StringT strBuf,
        returnString,
        appendString;
      IntT i,
        firstIndex = -1;
      //if the search string is empty, there is nothing to do.
      if(F_StrIsEmpty(searchString))
        returnString = F_StrCopyString(*mainString);
      else
        //otherwise, initialize the buffer
        returnString = F_StrCopyString("");
        for(i = 0; i < F_StrLen(*mainString); i++)
          strBuf = F_StrCopyString(*mainString);
          //Truncate the string from the beginning
          F_StrReverse(strBuf, 10000);
          F_StrTrunc(strBuf, (F_StrLen(strBuf) - i));
          F_StrReverse(strBuf, 10000);
          //and lop it down to the size of the search string
          if(F_StrLen(strBuf) > F_StrLen(searchString))
            F_StrTrunc(strBuf, F_StrLen(searchString));
          //if they are the same, we are doing the replacement
          if((considerCase && F_StrCmp(strBuf, searchString) == 0) ||
             (!considerCase && F_StrICmp(strBuf, searchString) == 0))
            appendString = F_StrCopyString(replaceString);
            //set the return value
            if(firstIndex < 0) firstIndex = i;
            //jimmy the loop so we step past the length of the replacement
            //string the next time around
            i += F_StrLen(searchString) - 1;
          //otherwise, we are just appending 1 character on.
          else
            F_StrTrunc(strBuf, 1);
            appendString = F_ApiCopyString(strBuf);
          //now, concatenate
          //rciReturnString = F_Realloc(rciReturnString,
            //F_StrLen(rciReturnString) + F_StrLen(rciAppendString), NO_DSE);
           returnString = (StringT) F_Realloc(returnString,
            (F_StrLen(returnString) + F_StrLen(appendString))*sizeof(StringT), NO_DSE);
          F_StrCat(returnString, appendString);
          F_ApiDeallocateString(&strBuf);
          F_ApiDeallocateString(&appendString);
        } //end main else
      //all done
      F_ApiDeallocateString(mainString);
      *mainString = F_StrCopyString(returnString);
      F_ApiDeallocateString(&returnString);
      return firstIndex;

  • Checking the length of a string in sapscript

    Is there a way to check the length of a string in sapscript?
    What I want to do is, if the length of two strings is greater than a certain ammount, truncate the string.
    But I don't know if is possible inside the sapscript

    Never mind, I did it with a perform instead

  • Microsoft.WindowsAzure.Storage.Table.CloudTable.ExecuteBatchAsync() truncates message

    When I call this method with large EntityProperty (around 17Kb of text), it truncates the string.
    I know that there is a limitation of 64Kb for a column and 1Mb for 1 entire row when it comes to Azure Table.
    Any insights?

    Hi,
    It sounds very strange, if you save the string value to other entity property, will it be truncated? If you use
    Azure storage explorer to save that string value, will it be truncated?
    If the string is not very confidential, could you share here? If you try to use the latest version of the azure storage client library, does this issue will be fixed? Please give us further information for a better support.
    Best Regards,
    Jambor
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • Copying text to the clipboard in AVDocDidOpen event handler causes Acrobat 9 to crash

    I'm trying to copy the filename of a document to the clipboard in a plugin with my AVDocDidOpen event handler.  It works for the first file opened; however when a second file is opened, Acrobat crashes.  The description in the application event log is: "Faulting application acrobat.exe, version 9.1.0.163, faulting module gdi32.dll, version 5.1.2600.5698, fault address 0x000074cc."
    I've confirmed that the specific WIN32 function that causes this to happen is SetClipboardData(CF_TEXT, hText);  When that line is commented out and remaining code is left unchanged, Adobe doesn't crash.
    Is there an SDK function that I should be using instead of WIN32's SetClipboardData()?  Alternately, are there other SDK functions that I need to call be before or after I call SetClipboardData()
    Bill Erickson

    Leonard,
    I tried it with both "DURING, HANDLER, END_HANDLER" and "try catch," as shown below.  However, it doesn't crash in the event handler; it crashes later, so the HANDLER/catch block is never hit.
    The string that's passed to SetClipboardData() is good, because I'm able to paste it into the filename text box of the print dialog when I try to create the "connector line" PDF.  I also got rid of all the string manipulation and tried to pass a zero-length string to the clipboard but it still crashes.
    Here's the code:
    ACCB1 void ACCB2 CFkDisposition::myAVDocDidOpenCallback(AVDoc doc, Int32 error, void *clientData)
        PDDoc pdDoc = AVDocGetPDDoc(doc);
        char* pURL = ASFileGetURL(PDDocGetFile(annotDataRec->thePDDoc));
        if (pURL)    {
            if (strstr(pURL, "file://") && strstr(pURL, "Reviewed.pdf")) {
                // Opened from file system so copy filename to clipboard for connector line report
                char myURL[1000];
                strcpy(myURL, pURL);
                ASfree(pURL);    // Do this before we allocate a Windows handle just in case Windows messes with this pointer
                pURL = NULL;
                HGLOBAL hText = GlobalAlloc(GMEM_MOVEABLE, 1000);
                if (hText)    {
                    try
                        // Skip path info and go right to filename
                        char *pText = (char *)GlobalLock(hText);
                        char *pWork = strrchr(myURL,'/');
                        if (pWork)    {
                            strcpy(pText, pWork+1);
                        } else {
                            strcpy(pText, myURL);
                        char *pEnd = pText + strlen(pText);    // Get null terminator address
                        // Replace "%20" in filename with " "
                        pWork = strstr(pText, "%20");
                        while (pWork)    {
                            *pWork = ' ';
                            memmove(pWork+1, pWork+3, (pEnd - (pWork+2)));
                            pWork = strstr(pText, "%20");
                        // Append a new file extension
                        pWork = strstr(pText, ".pdf");
                        *pWork = 0;    // truncate the string before ".pdf"
                        strcat(pWork,".Connectors.pdf");
                        GlobalUnlock(hText);     // Must do this BEFORE SetClipboardData()
                        // Write it to the clipboard
                        OpenClipboard(NULL);
                        EmptyClipboard();
                        SetClipboardData(CF_TEXT, hText);     // Here's the culprit
                        CloseClipboard();
                        GlobalFree(hText);
                    } catch (char * str) {
                        AVAlertNote(str);
            if (pURL)
                ASfree(pURL);

Maybe you are looking for

  • SunPKCS11 and NSS on Mac OS X 10.5

    Hello there, I've been scratching my head the whole day about how to use the SunPKCS11 provider and Mozilla's NSS framework under Mac OS X 10.5 (a.k.a Leopard). Let me replay the whole movie for you... So here I am, religiously following Sun's guidel

  • Ewm to erp quick access

    Hello, Is it possible using comannd field to switch form ewm menu to ERP basic easy access menu? Thank you inadvance: Vladislav Terziev

  • Attachement to ECC

    Hi Experts. I have the following scenario Soap -> XI-->ECC (Proxy call) I need to send the source xml as an attachement to ECC as well as map the data to proxy. Do you know any module that can be used to send source xml as an attachement to ECC? Much

  • Crosstab SUM behaviour query

    Hello, I have a crosstab report in Discoverer Plus which does not display the expected results. There are organisation areas down the side with their associated staff below (outline style). The data point is a calculation which shows their average mo

  • Pre-Comp Braking My Animation

    Hello All, I have been animating in after effects for about a month now, and I am doing a fold effect on a logo using masks. The problem is that when ever I pre-comp or even render the fold animation, it moves the elements, thus breaking my animation