SQL Trimming Characters in a Column

Hi,
First question here. My company is running Oracle 8i on HP - UX 11, if it helps. So here is the question:
I want to run an update statement that will remove 2-4 characters, only 4 variations from a column with 800 records.
Example, remove MD or M.D. from a Provider's Last Name. The problem is that the Provider's Last Name is from about 500 different providers, hence the variation.
Otherwise I would have to manually change every record with:
update table_name set provider_last_name = example
where provider_last_name = example MD
Any help or ideas would greatly be appreciated.

The number returned by the UPDATE statement indicates how many rows in the table Oracle performed the operation on. In your original UPDATE statement, Oracle performed the REPLACE operation on that field for every row... even though, for most rows, the REPLACE operation didn't change the row contents. For eg. if the column contents were 'xxx', Oracle would have set the column to REPLACE ('xxx','MD'), which is 'xxx'.
When you put the WHERE clause in, it only runs the statement for the rows that match the WHERE clause. The end results are the same, but the second way is faster.
-Natalka
http://toolkit.rdbms-insight.com

Similar Messages

  • Trim Characters From A Column

    Hi,
    I have a column Product (size 100 characters) in which the 1 ^st^ 5 characters are undesirable and I want to trim them out at BMM layer itself.
    I am using the SUBSTRING function to write the column formula SUBSTRING('"Core"."Dim - Product"."Product"', 6, 95).
    Is this the right method? I'm afraid it will go into a loop since the logical column references itself and there is no physical column reference.
    Thanks.

    Use this to get first 5chars only
    SUBSTRING("Core"."Dim - Product"."Product", 1, 5)
    To trim first 5 chars
    SUBSTRING("Core"."Dim - Product"."Product", 6, length("Core"."Dim - Product"."Product"))
    On logical table right click->New logical column->use Data Type tab to point physical column
    SUBSTRING('"Core"."Dim - Product"."Product"', 6, 95)Why you are using single quote for product?
    If helps mark as correct/helpful
    Edited by: Srini VEERAVALLI on Apr 18, 2013 6:31 AM
    Can you update this post?
    Edited by: Srini VEERAVALLI on May 6, 2013 9:22 AM

  • Oracle SQL trim() vs MS Excel clean()

    I have some data being extracted from Oracle 11 db views into CSV files.
    When importing the data into some other system, said other system's data importer crashes.
    I can open the CSV files in MS Excel, apply its clean() function to some columns, paste the values of that, and then the CSV file is a bit smaller, unprintable characters are removed, and data importer in new system is OK.
    Its a cumbersome process.
    I tried Oracle SQL trim() but it doesn't remove all the chars, it seems, that MS Excel clean() function removes.
    Is there a comparable Oracle SQL function that does what [MS Excel clean()|http://office.microsoft.com/en-us/excel-help/clean-HP005209014.aspx] does?
    Edited by: 972095 on Nov 19, 2012 2:35 PM

    I've used: regexp_replace(your_string,'[[:cntrl:]]') for this.
    SQL> declare
      2     s varchar2(30) := chr(10) || 'hello' || chr(10);
      3  begin
      4     dbms_output.put_line('*' || s || '*');
      5     dbms_output.put_line('*' || regexp_replace(s,'[[:cntrl:]]') || '*');
      6  end;
      7  /
    hello
    *hello*
    PL/SQL procedure successfully completed.

  • Replace all TAB and ENTER characters in a column

    Hi,
    how can I replace all chr(9) & chr(12) characters in a column?
    The following SQL replaces on one occurrence of TAB & ENTER, but my column can have many TAB & ENTER characters.
    select trim(replace(replace(column1,chr(9),''), chr(13), '') from some_table;

    Please cut'n'paste a sample from a SQL*Plus session, like this:
    SQL> select 'a'||chr(9)||'p'||chr(9)||'c'||chr(9)||'!'||chr(13)||'!'||chr(13)||'!'||chr(13)||'!'
      2  from dual
      3  /
    'A'||CHR(9)||
    a       p       c       !
    SQL> select replace(replace('a'||chr(9)||'p'||chr(9)||'c'||chr(9)||'!'||chr(13)||'!'||chr(13)||'!'||
    chr(13)||'!', chr(13), ''), chr(9), '')
      2  from dual
      3  /
    REPLACE
    apc!!!!
    SQL> Cheers, APC

  • Finding special characters in the column

    Hi,
    Need a help to find out the special characters in the column. since the data is loaded from external files like excel etc.., there
    are some special characters are got inserted in the column.
    how do i find out the rows in the column which has special characters, Please help ASAP...
    Thanks

    Hi,
    What do you mean by "special characters"?
    SQL> With T As(Select 'A?BC' txt from dual union all
      2            Select 'AB%C' txt from dual union all
      3            Select 'ACAA' txt from dual)
      4  Select txt from t where Regexp_Like(txt,'[[:punct:]]');
    TXT
    A?BC
    AB%C
    [:punct:]      Punctuation symbols
                    % . , " ' ? ! : # $ & ( ) * ;
                    + - / < > = @ [ ] \ ^ _ { } | ~
    {code}
    Regards,
    Christian Balz                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Swapping the first and last characters in a column

    Hi,
    Fairly new to T-SQL and i want to swap the first and last characters in a column.
    Thanks
    Umar Javed

    Likewise i have also tried your suggestion and i still seem to be getting errors:
    IF (@TYPE = 'SCRAMBLE')
    BEGIN
    DECLARE @SQLCOMMAND VARCHAR(2000)
    SET @SQLCOMMAND = 'UPDATE ' + @TABLENAME + ' SET ' + @VALUE +
    STUFF(STUFF(@VALUE,1,1,RIGHT(@VALUE,1)),LEN(@VALUE),1,LEFT(@VALUE,1))
    EXECUTE(@SQLCOMMAND)
    END
    Umar Javed
    Please post the errors.
    EDIT: Actually looking at your code this will bring errors:
    IF (@TYPE = 'SCRAMBLE')
    BEGIN
    DECLARE @SQLCOMMAND VARCHAR(2000)
    SET @SQLCOMMAND = 'UPDATE ' + @TABLENAME + ' SET ' + @VALUE + ' = STUFF(STUFF('+@VALUE+',1,1,RIGHT('+@VALUE+',1)),LEN('+@VALUE+'),1,LEFT('+@VALUE+',1))'
    PRINT @SQLCOMMAND
    EXECUTE(@SQLCOMMAND)
    END
    I've also added a print command so it will show you what the code looks like upon concatenation. It's much easier to debug this way.

  • Why do I get a class conflict between the Prepare SQL.vi and the Get Column Name.vi with the SQL Toolkit compatibility vis from the Database Connectivity Toolkit?

    I have done extensive programming with the SQL Toolkit with LabVIEW versions through 6.1. My customer now wants to upgrade to Windows 7, so I am trying to upgrade to LabVIEW 2009 (my latest purchased version) using the Database Connectivity Toolkit, and the SQL Toolkit Compatibility vis. Everything seemed to be going okay with the higher level SQL operations, but I ran into trouble with the Get Column Name.vi. 
    The pictures below show the problem. The original SQL Toolkit connected the Prepare SQL.vi with the Get Column Name.vi with a cluster of two references, one for connection, and one for sql. The new compatibility vis have a class conflict in the wire because the Prepare SQL.vi contains a cluster with connection, and command references, but the Get Column Name.vi expects a cluster with connection and recordset references. 
    How do I resolve this conflict?
    Thank You.
    Dan

    I've never worked with the old version of the toolkit, so I don't know how it did things, but looking inside the SQL prep VI, it only generates a command, and the the column name VI wants a recordset. I'm not super familiar with all the internals of ADO, but my understanding is that is standard - you only have the columns after you execute the command and get the recordset back. What you can apparently do here is insert the Execute Prepared SQL VI in the middle and that will return what you need.
    I'm not sure why it worked before. Maybe the execute was hidden inside the prep VI or maybe you can get the column names out of the command object before execution. In general, I would recommend considering switching to the newer VIs.
    Try to take over the world!

  • SQL Query - The number of columns specified in "SQL Query" does not match t

    I am creating new UDM for tablespace alert, below is my query,however its failing with error
    SQL Query - The number of columns specified in "SQL Query" does not match the value specified in "SQL Query Output"
    I selected Metric type is number
    SQL Query Format : Two columns
    Query:
    SELECT d.tablespace_name,round(((a.bytes - NVL(f.bytes,0))*100/a.maxbytes),2)
    used_pct FROM sys.dba_tablespaces d,(select tablespace_name, sum(bytes) bytes, sum(greatest(maxbytes,bytes)) maxbytes from sys.dba_data_files group by tablespace_name) a,(select tablespace_name, sum(bytes) bytes from sys.dba_free_space group by tablespace_name) f
    WHERE d.tablespace_name = a.tablespace_name(+) AND d.tablespace_name = f.tablespace_name(+)
    AND NOT (d.extent_management = 'LOCAL' AND d.contents = 'TEMPORARY');
    Any clues why i am getting error.

    SQL> SELECT d.tablespace_name,round(((a.bytes - NVL(f.bytes,0))*100/a.maxbytes),2) used_pct
    2 FROM sys.dba_tablespaces d,(select tablespace_name, sum(bytes) bytes, sum(greatest(maxbytes,bytes)) maxbytes from sys.dba_data_files group by tablespace_name) a,(select tablespace_name, sum(bytes) bytes from sys.dba_free_space group by tablespace_name) f
    3 WHERE d.tablespace_name = a.tablespace_name(+) AND d.tablespace_name = f.tablespace_name(+)
    4 AND NOT (d.extent_management = 'LOCAL' AND d.contents = 'TEMPORARY');
    TABLESPACE_NAME USED_PCT
    MGMT_TABLESPACE .82
    SYSAUX 1.52
    UNDOTBS1 .32
    RMAN .02
    CORRUPT_TS 10.63
    USERS 0
    SYSTEM 2.26
    MGMT_ECM_DEPOT_TS .04
    MGMT_AD4J_TS 0

  • IF NEW VARIABLE IN SQL QUERY, DISPLAYS AS LAST COLUMN + rpad not working

    Hello everybody and thank you in advance,
    1) if I add a new variable to my sql query to select a column which was already in the table, it shows it in the report table as the Last column to the right. That is, if I add "street" to
    something like city, postcode, street, store, manager, etc, instead of placing street between postcode and store, it places it as i said as the last column to the right.
    2) When values are entered into the cells of the tables, yes, they do expand it to their needed lenght, But, only if it is one word. If it is two, like when i enter the value "very good"
    then it takes two lines so as with a carriage return within the cell, thus, making it too high the row. I tried to padd spaces with rpad but it did not work. something like rpad(stock, 20,' ')
    I must say that the table is in the same page where there is a Form, so as the table grows in lenth it is actually squeezing the form located right on its left.
    3) rpad did not work with the most simple syntax, but less would with what i need because it turns out i am using DECODE in order to do a conversion between value displayed and
    value returned in my select list of values, something like : DECODE (TO_CHAR (stock),'1','Deficient','2','Average','3','Good','4','Very Good',null) AS stock,
    so, i have tried to put the rpad there in several places but either it gave parsing error or it left the column empty not picking any values.
    thank you very much
    Alvaro

    Alvaro
    1) That is standard behaviour of apex builder. You can change the display order with the arrows in the report attributes column report.
    2) You will have to play with the style attributes of the column to accomplice this. For instance style="white-space:pre;" in the Element Attributes of the column attributes. White-space:normal would thread several space (' ') as 1. So no matter how many you add with rpad they will be shown as 1.
    Or set a width either as attibute or in a style class for that column.
    Nicolette

  • How to seperate numbers and characters in a column

    Hi,
    In my database i have a table named birth.DBA prior to me created a column with data type var char,for which data type number must be allocated.Both characters and numbers are entered into that column.now i have to change my data type into number.how can i do this.
    My idea is to first separate numbers and characters in that column.But how can i do this.can u please suggest.

    use regular expressions
    SELECT regexp_replace('aa123','[[:digit:]]') from dual;
    SELECT regexp_replace('aa123','[^[:digit:]]') from dual
    hth
    Marco

  • Can anybody help....SQL to display row as column and column as rows

    Can anybody help in writing a SQL to display row as column and column as rows?
    Thanks

    check this link:
    Re: Creating Views - from rows to a new column?

  • What is the best NLS config to be near the ACCESS or SQL Server characters set

    Hi all,
    I am working with an Oracle for Windows.
    I have serious problems with my actual characters set.
    What is the best NLS config to be near the ms-Access or SQL Server characters set behavior ?
    For exemple :
    I have a table with city names
    I want to find the nearest >= city name of a given criteria. so i do this SQL
    SELECT Nom FROM TLCommune WHERE Nom >= 'LIMOGES' ORDER BY Nom, Pays, Dept, Insee
    This SELECT give this result under SQL plus worksheet (same via VB and ADO)
    Why the cities from krosno to Limerick are listed regarding on the WHERE clause Nom >= 'LIMOGES' ?
    NOM
    krosno
    La Manche et la Mer d'Irlande
    Laesv
    Lancashire
    Landes
    Lappi (Lappland)
    Latviya
    Legnica
    Leicester and Rutland
    Leipzig
    Leningrad
    NOM
    Leon
    Lirida
    Leszno
    Liberec
    Libiria
    Libye
    Limburg
    Limburg (Limbourg)
    Limerick
    LIMOGES <--------------------------------------- the city in the nom >= 'LIMOGES' in the SQL statement
    LIMOGES-FOURCHES

    Hi,
    Try these steps:-
    * Open the GUI of Root bridge
    Go to Security/SSID Manager/create SSid/map it to the radio
    * Under Client Authentication setting
    Check the box Open authentication with no Addition ..
    * Then click Apply
    * Go to Ecryption Manager page
    Under Ecryption Modes
    Select Cipher ---TKIP
    Under Encryption Keys
    Select Encryption Key 2 ------Don't put any key ... Leave the box blank and key size be 128bit
    Then click Apply
    * Come back to SSID Manager page
    Under Client Authenticated Key Management ..
    Select Key Management:- Mandatory
    Check the box:- WPA
    Under WPA Pre-shared Key:- Type atleast 8 character key..
    Click Apply:-
    * Then we need to repeat the same settings on Other bridge except the station role will be non-root.
    Now to troubleshoot...
    * First make Bridge are able to talk to each when there is on security setup
    * Set a simple Pre-shared Key ... example 1234567890 on both bridge .. Bridge will not associate if key mismatch..
    Hope this will work for you.

  • How set maximum of characters for the columns

    Hello I use a JTable and I want to set maximum of characters for the columns.
    For example column 1 max 10 characters, column 2 max 20 characters, etc..
    How can I do this?

    The principle is as follows: a table uses certain input components for editing a cell value, e.g. a JCheckBox for Boolean-type values or a JTextField for textual/numerical values. By default, a JTextField doesn't have any size limit, so you can enter as many chars as you want. In order to change this behaviour, you'll have to
    1.) create a JTextField that does have a size limit and
    2.) set a CellEditor on the JTable which uses this manipulated JTextField.
    An easy way for 1.) is to create a custom Document (the internal data representation for text components, the M-part of the MVC -- see javax.swing.text.Document) that doesn't accept any text beyond a given limit, e.g.:
    public class LimitedDocument extends PlainDocument {
      private int max = 0;
      public LimitedDocument(int max) {
        this.max = max;
      public void insertString(int offset, String str, AttributeSet a) throws BadLocationException {
        // too long for the limit; get current contents, insert, and cut off trailing chars
        if ((getLength() + str.length()) > max) {
          StringBuffer buf = new StringBuffer(getText(0,getLength()));
          buf.insert(offset,str);
          remove(0,len); // remove current text contents
          super.insert(0,buf.toString().substring(0,max),a); // insert whole text
        // no problem, will fit
        else {
          super.insertString(offset,str,a);
    }Then, in order to set the cell editor -- for example for the first column --, you can do as follows:
    myTable.getColumnModel().getColumn(0).setCellEditor(new DefaultCellEditor(new JTextField(new LimitedDocument(5),"",5)));This will create a new DefaultCellEditor (see javax.swing.table) and initialize it with a given text field which will be responsible for any edition in this column. As the text field itself is created using a limit of 5, it should accept no text insertion beyond 5 chars.

  • Error 1000: AFx Library library exception: Sql encountered an error: These columns don't currently have unique values.

    Hi everyone,
    Using the Writer block, configured with a correct SQLAzure instance, I experience this error:
    - Error 1000: AFx Library library exception: Sql encountered an error: These columns don't currently have unique values.
    I have read that this error can be related to inheritance problems, but my table does not have inheritances of any kind:
    CREATE TABLE [dbo].[my_table](
    [my_float] [float] NULL
    ) ON [PRIMARY]
    GO
    Writer block parameters:
    Comma separated list of columns to be saved:
    temp      (from Bike Rental UCI Dataset)
    Data Table name: [dbo].[my_table]
    Comma separated list of datatable columns:
    [my_float]
    The experiment from which I have extracted the writing part was able to correctly write to DB until few days ago. Is it possible that some changes in the platform are causing this issue or am I doing something wrong?
    Thank you and best regards,
    FV

    Hi Maureen,
    Yes, the scenario is correct. On SQL profiler I can't see any SQL operation that can lead to that kind of error, but as you were saying it was worth trying anyway having that error message.
    New test scenario:
    CREATE TABLE [dbo].[my_table_identity](
        [ID] [int] IDENTITY(1,1) NOT NULL,
        [my_float] [float] NULL,    
     CONSTRAINT [PK_my_table_identity] PRIMARY KEY CLUSTERED 
        [ID] ASC
    )WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON)
    ) ON [PRIMARY]
    -- These lines work fine on SQL Management Studio
    INSERT INTO [dbo].[my_table_identity] (my_float) VALUES (1.23)
    INSERT INTO [dbo].[my_table_identity] (my_float) VALUES (1.23)
    INSERT INTO [dbo].[my_table_identity] (my_float) VALUES (1.23)
    -- I can see all new rows with each one a different ID
    SELECT * FROM [dbo].[my_table_identity]
    dbo is the default schema for my Azure login.
    New writer block parameters:
    Comma separated list of columns to be saved: temp  
       (from Bike Rental UCI Dataset)
    Data Table name: my_table_identity
    Comma separated list of datatable columns: my_float
    I still get the same error: Error 1000: AFx Library library exception: Sql encountered an error: These columns don't currently have unique values.
    I have also tried to pass the "instant" column instead of "temp", as it hasn't any duplicated values, but still no luck.
    I attach the log file (purged of sensitive information) because I see some error / warnings there.
    https://dl.dropboxusercontent.com/u/40411467/azure_log.txt
    Thank you again and best regards,
    FV

  • Execute PL/SQL statement on rendered report column only (APEX 4.02)

    Hello,
    i have a classic report which selects approx. 100.000 rows. For one of the columns in the sql i am executing
    a rather complex PL/SQL function which generates additional html. This function slows down the query
    by a tremendous amount (over one hour for the select, without this function it's 30 seconds) so i don't
    want to execute it for each selected row but for the rendered ones only (15 per page).
    Is it possible to do so in a report?

    Steven Mark wrote:
    So if APEX does not give us the option to execute PL/SQL scripts on actually rendered columns onlyI have long thought that this is a major limitation of APEX. We know from Marc's post Re: Reports/Tabular Form and number of executions of a Lov Query that built-in column display operations are only performed for the rows rendered on the current page. However, there are many requirements (even relatively simple ones like row-level conditional display) that are impossible to meet using the built-in Display As/LOV, HTML Expression, Tabular Form Element, and Column Link display options. The alternatives are inefficient (context switching to user-defined functions) or poor practice (losing the separation of concerns by generating HTML/links in report queries).
    The ability to call user-defined functions at the same rendering point as built-in column display operations, and to apply row-level conditions to built-in display options are long overdue enhancements.

Maybe you are looking for

  • File send adapter error : java.lang.NullPointerException

    Hi All, I have an issue on some of the file sender adapter communication channels .The channels are failing with the error : Error :"Attempt to process file failed with java.lang.NullPointerException" This issue is happening for couple of file sender

  • Save data in a file and email the file

    Dear all, I have 2 vi files: 1. one vi file can store data into a file when it runs and stopped 2. another vi can send a file out through email when it is run. Is it possible for me to run the first vi and stop after one hour (to store data into A fi

  • How to import a picture in java

    hello can annyone help me with my problem, i have tried various ways to import a picture but i cant seem to find the correct way. Can annyone help me with this problem that would be great. You all have my thanks

  • Python closes on open

    Lemme preface this post by saying the following - I've taken my computer to the local IT office on RIT campus, asked a Computer Science professor specializing in Python, and posted my question on answers.yahoo.com (I don't know why I expected that to

  • What is my browser ersion number?

    The website 247pearsoned.custhelp.com needs to know this information