Oracle PL/SQL/Char Functions/RTRIM — различия между версиями

Материал из SQL эксперт
Перейти к: навигация, поиск
м (1 версия)
 
(нет различий)

Версия 13:45, 26 мая 2010

Rtrim char type column data

 
SQL>
SQL> CREATE TABLE old_item (
  2       item_id   CHAR(20),
  3       item_desc CHAR(25)
  4       );
Table created.
SQL>
SQL> INSERT INTO old_item VALUES("LA-101", "Can, Small");
1 row created.
SQL> INSERT INTO old_item VALUES("LA-102", "Can, Large");
1 row created.
SQL> INSERT INTO old_item VALUES("LA-103", "Bottle, Small");
1 row created.
SQL> INSERT INTO old_item VALUES("LA-104", "Bottle, Large");
1 row created.
SQL> INSERT INTO old_item VALUES("NY-101", "Box, Small");
1 row created.
SQL> INSERT INTO old_item VALUES("NY-102", "Box, Large");
1 row created.
SQL> INSERT INTO old_item VALUES("NY-103", "Shipping Carton, Small");
1 row created.
SQL> INSERT INTO old_item VALUES("NY-104", "Shipping Carton, Large");
1 row created.
SQL>
SQL>
SQL> SELECT "Item  " ||
  2         RTRIM(item_id) ||
  3         " is described as a " ||
  4         RTRIM(item_desc) ||
  5         "."  "Item Description Sentence"
  6  FROM   old_item;
Item Description Sentence
-----------------------------------------------------------------------
Item  LA-101 is described as a Can, Small.
Item  LA-102 is described as a Can, Large.
Item  LA-103 is described as a Bottle, Small.
Item  LA-104 is described as a Bottle, Large.
Item  NY-101 is described as a Box, Small.
Item  NY-102 is described as a Box, Large.
Item  NY-103 is described as a Shipping Carton, Small.
Item  NY-104 is described as a Shipping Carton, Large.
8 rows selected.
SQL>
SQL> drop table OLD_ITEM;
Table dropped.
SQL>



RTRIM function removes trailing characters

SQL> --RTRIM function removes trailing characters.
SQL>
SQL> SELECT RTRIM("S" , "STEVENS") AS TRIM FROM Dual;
T
-

SQL>



Rtrim: removes a set of characters from the right of a string

SQL> -- RTRIM stands for "right trim."
SQL> -- The general format for this function is:
SQL>
SQL> -- RTRIM(string, characters_to_remove)
SQL>
SQL>
SQL> SELECT RTRIM("Computers", "s") FROM dual;
RTRIM("C
--------
Computer



Use rtim to remove space

 
SQL>
SQL>  select """ || rtrim( "Some String     " ) || """ "A String"
  2      from dual
  3    /
A String
-------------
"Some String"
1 row selected.
SQL>
SQL> --