How to trim spaces in SQL?

Hi there,
I have installed Oracle XE on my machine and have populated it with some data. In one table,namely the Id column i noted there are spaces before the actual code. For example _ _ _12345. My question is, how do i removed these spaces? I am using Oracle SQL Developer to query the tables in XE. I have over 100,000 records.
Thanks for the help
SI

http://download.oracle.com/docs/cd/E11882_01/server.112/e10592/functions002.htm#CJAEEJFC
Refer to the TRIM, LTRIM and RTRIM functions and issue an appropiate UPDATE statement
Sybrand Bakker
Senior Oracle DBA

Similar Messages

  • How to trim spaces from string in BMM layer?

    Hi friends,
    I need to trim spaces from the string. can you please give me syntax with example.
    Thanks

    Hi
    I have tried the below option , but it did not work . PS_D_PERSON
    PERSON_ID is char type in the data base oracle , and it is defined as varchar on the physical layer .
    So the table is loaded with space , i am not able to remove the space using trim both
    Thanks
    Sridhar.N

  • Urgent !!! How to trim spaces of an email filed ?

    Hi,
    I have an email field in a form ,which have a validation at the time of submission of form as shown in the below .
    function isEmailValid(fld){
                        var result = true;
                        if(fld != null){
                                  var r = new RegExp();
                            r.compile("^[a-z0-9_\\-\\.\\']+\\@[a-z0-9_\\-\\.]+\\.[a-z]{2,4}$","i");
                                  result = r.test(fld.rawValue);
                        return result;
    but if user by mistakely enters the space in that field  at the time of validation it is  showing an error called "Invalid Email Format"
    I need to trim those spaces either modifying the above regular expression or the best way
    Please suggest ..
    Thanks in Advance
    Bharathi

    In the exit event of your email field put:
    this.rawValue = this.rawValue.replace(/\s/g,"");
    Kyle

  • How to identify space in sql server?

    Hi,
    i dont want any special chars in ITEM_DESC_1 column,but it should not consider space .i tired the below query
    SELECT ITEM_DESC_1
    FROM  DBO.MIC_TARGET
    WHERE ITEM_DESC_1 LIKE
    '%[^a-zA-Z0-9]%'
    but this considers space also at the end of the string.this query not fetching records if it has space at the end of the string 
    so please help me on getting exact query.

    Hi JKumar,
    I am sure that the character which appears within the description is not a blank space(may be unicode character). We can check the ascii code for the character. The ascii code for blank space
    is 32. Can you check the ascii of the space character that is appearing in the description field?
    Regards, RSingh

  • Viewing/Identifying blank spaces in SQL*plus

    How can i identify blank spaces in Sql*plus? How will i know if the result of the following query has the blank spaces on the right trimmed?
    SQL> select rtrim('sxxx  ') from dual;
    RTRI
    sxxxMessage was edited by:
    J.Kiechle

    Why? This seems a pretty strange requirement for me.
    Are you sure that you have a problem with blank padded characters?
    select 1, '|'||rtrim('sxxx  ')||'|' from dual
    UNION
    select 2, '|'||'sxxx  '||'|' from dual;
    Row#     1     '|'||RTRIM('SXXX')||'|'
    1     1     |sxxx|
    2     2     |sxxx  |

  • CPU consumption 100%: How do I see which SQL is consuming?

    Hi,
    I need help badly with this because I cannot get my head around the problem. I have a Windows server 2003 Enterprise 64-bit running Oracle 10.2.0.3 and last night it started consuming 100% CPU. The Windows performance monitor shows 100% CPU in any case, and it was difficult to even login via remote desktop.
    It is Oracle.exe that is consuming, and there is only one database on this server. It is an Opteron 875 2.2Ghz with 8GB ram.
    I want to see which SQL statement is responsible for the CPU consumption. I know exactly which user/programapplication is using it... it is useless to kick the session because the application connects immediately again from the app. server and runs the same thing. Restarting the database also has the same effect: session reconnects and CPU goes through the roof. Customer says that they are running the same stuff as always, and app. has not been updated recently. 100 % CPU to them, means something is wrong.
    Incidently, I tried to CPU patch this database a couple of days beforehand, but there was not enough space on disk (needed 1.6GB) so opatch complained and would not continue. I simply restarted the database without having run opatch. I cannot imagine that this is the cause of this problem.
    Anyhoo...
    I have a script from Kyle Haileys web site to get the CPU for each sql_id using ash tables:
    -- (c) Kyle Hailey 2007
    col type for a10
    select * from (
    select
    ash.SQL_ID , ash.SQL_PLAN_HASH_VALUE Plan_hash, aud.name type,
    sum(decode(ash.session_state,'ON CPU',1,0)) "CPU",
    sum(decode(ash.session_state,'WAITING',1,0)) -
    sum(decode(ash.session_state,'WAITING', decode(wait_class, 'User I/O',1,0),0)) "WAIT" ,
    sum(decode(ash.session_state,'WAITING', decode(wait_class, 'User I/O',1,0),0)) "IO" ,
    sum(decode(ash.session_state,'ON CPU',1,1)) "TOTAL"
    from v$active_session_history ash,
    audit_actions aud
    where SQL_ID is not NULL
    and ash.sql_opcode=aud.action
    and ash.sample_time > sysdate - &minutes /( 60*24)
    group by sql_id, SQL_PLAN_HASH_VALUE , aud.name
    order by sum(decode(session_state,'ON CPU',1,1)) desc
    ) where rownum < 10
    This give following output:
    SQL_ID PLAN_HASH TYPE CPU WAIT IO TOTAL
    cxk376gut06wn 3831248992 SELECT 12 145 5855 6012
    4ffvdt72n46yt 4094592372 SELECT 0 3 1131 1134
    dnxgm7bg8wqg1 4025412530 SELECT 3 13 337 353
    3y0dyvkc9sx69 1764840833 SELECT 18 169 56 243
    abz05715h08ct 1967470119 SELECT 0 7 175 182
    4gd6b1r53yt88 0 UNKNOWN 0 92 4 96
    9phhuzxpqwsgc 2662599208 SELECT 0 67 0 67
    275bbj5czbrwp 629013258 SELECT 0 2 64 66
    1dvrrg3aah2mu 75914095 SELECT 0 6 57 63
    My assumption is that this gives the average CPU usage over the last x minutes and the total cpu usage for this sql_id. There are no sql running that show a very high average CPU, but the total is up in 6000 for the longest running sql, so I get the statement for the top sql_id that has highest total, and it is this:
    SQL_ID cxk376gut06wn, child number 2
    SELECT NVL(MIN(ID),0) FROM TABLE_OBFUSCATED WHERE TASK = :B1 AND
    STATUS='JobQueue' AND MESSAGE_ID IS NULL
    Plan hash value: 3831248992
    | Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
    | 0 | SELECT STATEMENT | | | | 3231 (100)| |
    | 1 | SORT AGGREGATE | | 1 | 42 | | |
    |* 2 | TABLE ACCESS FULL| TABLE_OBFUSCATED | 3 | 126 | 3231 (1)| 00:00:39 |
    Predicate Information (identified by operation id):
    2 - filter(("TASK"=:B1 AND "STATUS"='JobQueue' AND "MESSAGE_ID" IS NULL))
    It doesn't seem to fit! It's such a simple statement, but according to ash this is the sql using the most total cpu over the last 30 minutes?? So I create a temp index on the filter and check the plan for the statement again, and it uses the index, but I need to kill the session or bounce the database for the new plan to be used because the currently running session is still using the old plan. Customer was desperate to get it down so I even tried flushing the shared pool but new plan does not get used. I did not want to restart the database. Do I have to kill all sessions using that plan for the new one to take effect?
    Now im stuck. I don't really know how else to get an accurate picture of which sql is currently consuming CPU. I need to know this to try to fix the SQL because stopping the application is not an option, even if it is throwing too much at the database. The only other option I can think of is setting up profile limits for cpu consumption in oracle, but then the job will likely take an unacceptable amount of time for the customer.
    So my questions are:
    1. How else can I check which SQL is using CPU accurately?
    2. Does the SQL I show above accuratlely display current average CPU over x minutes with ASH? Why is it so low for the top consumer but my CPU is still at 100% on the OS?
    Thankyou for your help.

    Yeah, OK, I can see an arbitary number for CPU used since session startup (what does that refer to by the way? It can't be percent), and I can see that one user has consumed massive amounts of CPU compared to all other sessions, but he is currently not running anything, so how can I see which SQL he ran in the past day that cuased all that CPU consumption? Can I do this without AWR?
    By the way, do you need a Diagnostic Pack license for simply viewing the Performance tab of dbconsole? I Can go into dbconsole and see history for 2 days back and see the massive espike that caused CPU consumption, but when dbconsole displays the list of top SQL and top sessions under the graph, is it the top listed SQL that consumed the most cpu or do you need to correlate the colours, i.e. find the SQL listed in top SQL that has the same colour as CPU usage on the graph (green) even if it is not listed as the top "consumer" (which I assume means top AAS consumer: overall consumption of all resources)?

  • When and how to trim string

    Not sure the best way around this issue.  In a query I have the following:
    SUBSTRING(blogStories.blogBody,1,220) AS blogBody
    Later, when I go to display this, I want to strip the html so I have this:
    <cfset trimmedBodyText = REReplaceNoCase(#rsBlog.blogBody#,"<[^>]*>","","ALL")>
    <p><cfoutput>#trimmedBodyText#</cfoutput><em> ... (more)</em></p>
    This is where the problem comes in.  If my SQL query happens to end in the middle of a string like this:
    <p>Web 2.0 tools allow opportunities for doing traditional things in new and fundamentally different ways. As Clay Shirky writes in <a target="_blank" href="http://perma://BLPageReference/75484FCE-115D-450B-A2DF-4F71745B
    Then the REReplaceNoCase causes problems because there is no end tag.
    Can I do this in SQL, or should I pull the whole story, do the REReplaceNoCase and then trim it?  If so, what is the command in ColdFusion for trimming?  Everything I've found only trims spaces. I can't seem to specify a length anywhere.

    OK, I hadn't received an answer and I kept digging and found the LEFT command, so what I have done is changed my query to get the entire story then I run this code for the output
    <cfset variables.blogStory = REReplaceNoCase(#rsBlog.blogStory#,"<[^>]*>","","ALL")>
    <cfset variables.blogStory = Left(#variables.blogStory#, 220)>
    <p>#variables.blogStory#<em>... (more)</em></p></td>
    Then the problem was that sometimes I'd get cut off in the middle of a word, so I've changed it to this to find the last word and remove it:
    <cfset variables.blogStory = REReplaceNoCase(#rsBlog.blogStory#,"<[^>]*>","","ALL")>
    <cfset variables.blogStory = Left(#variables.blogStory#, 220)>
    <cfset variables.lastWord = ListLast(#variables.blogStory#, " ")>
    <cfset variables.trimLength = Len(#variables.lastWord#)>
    <cfset variables.blogStory = Left(#variables.blogStory#, 220-#variables.trimLength#)>
    <p>#variables.blogStory#<em>... (more)</em></p></td>
    This solves the problem for me.  I get the output I want, but I'm sure there is a more elegant way of doing this with less code.  If anyone knows of one, I'd love to hear it.

  • How to eliminate spaces while reading a file in BPEL Process

    Hi All,
    How to eliminate space when reading a file which of fixedlength and inserting into database.
    Inserting some of columns sucessfully but there is a column where there is a space n front the value, how to eliminate the that space.
    I have a custom XSD and using out in the process. How to resolve this issue to get all rows sucessfully inserted into the database.
    Anyone hod gone through this kind of functionality.
    Regards,
    CH

    Hi,
    try to use XPath functions like 'normalize-space()', 'right-trim()', 'left-trim()' in your transformation.
    Regards,
    Martin.

  • How could I find the SQL statement who get this message ?

    ORA-01555 caused by SQL statement below (Query Duration=11191 sec, SCN: 0x0854.723b9c32)
    ... How could I find the SQL statement who got this message ?
    Thanks, Paul

    ORA-01555 means that the UNDO/ROLLBACK space is not large enough.
    This occurs because the SELECT statement is attempting to read the UNDO, but the UNDO has been released (transactions have committed or rolled back) and reused.
    The following are SOME of the reasons I have seen this to occur:
    1) Updates in a loop, with commits happening in the same loop
    - this will mark the UNDO available quickly and quickly reuse it. Then when the SELECT wants to rebuild a block, the UNDO used to rebuild the block has been reused (solution, make the UNDO bigger)
    2) A SELECT cursor used to control a loop in which updates are performed, and a 'done' flag is marked against the current cursor record, and commits are performed at the end of each loop, prior to fetching the next record
    - same problem as above, but it hits the current process. Same solution
    3) A 'month end' activity spike occurs, and all sorts of transactions create updates. There is a report that reports the activity - amusingly it needs to start at the beginning of all the work and updates periodically by doing a huge SELECT up front. This is then used to drive a loop which attempts to get information from the various transactions that have been updated and committed. After a while, the SELECT gets an ORA-01555
    - same problem as above and same solution. Get a bigger UNDO segment.
    You say this only happens once a month. That should give a hint.
    I wouldn't bother with which SELECT statement, as much as which APPLICATIONs are being run when it happens.
    One way around this - use 10g and set the guaranteed retention period. All sorts of other things will break, by no more 1555. <g>

  • How much free space does a 4GB ipod need?

    why does it keep saying i dont have enough free space? i already decreased the space to 3.85 GB, and its still saying i dont have enough free space. how much free space does it need?

    This is more likely a matter of Apple specifying 4G as 4,000,000,000 byte rather than 41024*10241024 byte like your computer counts.
    Using the "1000 notation", your 3.85GB would require 4.1GB. Try trimming your library down a bit more (to around 3.7G). I don't have my Nano yet, so I cannot verify if the device actually uses any of those "4G" for things other than storing your data.

  • How much table space will be alloctaed per user

    hi all,
    when a user is created how much table space will be allocated by default per user the oracle server or is there any default size fixed by the dba.
    thanks and regards,
    sri ram.

    Untill the administrator doesn't specify QUOTA or grant UNLIMITED TABLESPACE to user Oracle account doesn't have available space in any tablespace, event in default:
    SQL> create user new_user identified by new_user
      2  default tablespace users;
    User created.
    SQL> grant create session, create table to new_user;
    Grant succeeded.
    SQL> conn new_user/new_user
    Connected.
    SQL> create table t(x int);
    create table t(x int)
    ERROR at line 1:
    ORA-01950: no privileges on tablespace 'USERS'
    SQL> conn / as sysdba
    Connected.
    SQL> alter user new_user quota 1M on users;
    User altered.
    SQL> conn new_user/new_user
    Connected.
    SQL> create table t(x int);
    Table created.

  • Forms 10gR2 does not trim spaces

    Hi,
    we are planning to migrate to 10g from 6i. as far as i know forms always trims trailing spaces. so when we are inserting space to a table it inserts null.
    but at 10gR2 it does not trims spaces and inserts non-null value.
    Am i missing something or is it really changed?
    Regards. Engin.

    I had fogotten about that bug. But it still exists, even in Forms 6i, patch 17 (6.0.8.26.0)
    I ran this test:
    Declare
      v1  varchar2(4);
      v2  varchar2(4);
      v3  varchar2(4);
    Begin
      v1 := ' ';  -- one space
      select nvl(v1,'X'), v1 into v2, v3 from dual;
      message
        ('V2=' || v2 || ', Length(V2) = ' || nvl(Length(v2),0) );
      message
        ('V3=' || v3 || ', Length(V3) = ' || nvl(Length(v3),0) );
    End;And I get the following messages:
    V2=X, Length(V2) = 1
    V3=, Length(V3) = 0Run under SQL Plus, changing Message to DBMS_Output.Put_Line:
    V2= , Length(V2) = 1
    V3= , Length(V3) = 1I get the correct result, the same as SQL Plus, in Forms 10.1.2.0.2.

  • How can i use one SQL statement to solve problem?

    How can i use one SQL statement to solve the question below?
    For a Table named A, there is a column named F(char type).
    Now select all the records where F like '%00' and update their F value to '%01'
    Just one SQL statement.Do not use PL/SQL block.
    How to do that?
    Thanks.

    What is the data volume for this table?
    Do you expect lots of rows to have '%00' as their value?
    Following two statements come to mind. Other experts would be able to provide better alternatives:
    If you have index on SUBSTR(f, 2):
    UPDATE A
    SET    f = SUBSTR(f,
                      1,
                      length(f) - 2) || '01'
    WHERE  substr(f,
                  -2) = '00';If most of the rows have pattern '%00':
    UPDATE A
    SET    f = SUBSTR(f,
                      1,
                      length(f) - 2) ||
               DECODE(SUBSTR(f,
                             -2),
                      '00',
                      '01',
                      SUBSTR(f,
                             -2));

  • How can I connect to SQL Server CE?

    Hi!
    How can I connect to SQL Server CE ?
    Any idea?
    I found jdbc driver for SQL Server 6.5,7.0,2000.
    But no driver for SQL CE.
    Thanks for any suggestion....

    I am also searching for same answer.
    I wanna choose Access as a db. but I can't find that so I have a no choice to select SQL2000CE though.
    I am stuck in driver problem. I can't find that.
    Should I use Oracle Lite or PointBase?
    I am under a lot of stress... like you've been...
    I wish you find and post that....

  • How do i connect to sql server 2012 from cmd .

    Hi ,
    I Installed sql server 2008 R2 and 2012 Express and sql server2014 . I can conect to sql server 2008 R2 using
    SQLCMD -L command .
    How do i connect to sql server 2012 express edition from cmd .
    Any Hep appreciated
    Thanks in advance,
    Shravan

    I HAVE ANOTHER INSTANCE NAMED TEST  WHEN I USE THE COMMAND IT GIVES ME THIS ERROR 
    HOW TO RECTIFY 
    C:\Users\HP>SQLCMD -S HP-HP/TEST
    Sqlcmd: Error: Microsoft SQL Server Native Client 11.0 : Named Pipes Provider: C
    ould not open a connection to SQL Server [67]. .
    Sqlcmd: Error: Microsoft SQL Server Native Client 11.0 : Login timeout expired.
    Sqlcmd: Error: Microsoft SQL Server Native Client 11.0 : A network-related or in
    stance-specific error has occurred while establishing a connection to SQL Server
    . Server is not found or not accessible. Check if instance name is correct and i
    f SQL Server is configured to allow remote connections. For more information see
     SQL Server Books Online..
    PLZ HELP 

Maybe you are looking for