Oracle RPAD函数

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Oracle RPAD函数相关的知识,希望对你有一定的参考价值。

A few examples of the Oracle RPAD function, with some tables being set up.
  1. DROP TABLE customers;
  2.  
  3. CREATE TABLE customers (
  4. first_name varchar2(100),
  5. last_name varchar2(100),
  6. country varchar2(20),
  7. full_address CLOB,
  8. employees NUMBER,
  9. start_date DATE
  10. );
  11.  
  12. INSERT INTO customers (first_name, last_name, country, full_address, employees, start_date) VALUES ('John', 'Smith', 'USA', '10 Long Road', 4, '12-APR-2010');
  13. INSERT INTO customers (first_name, last_name, country, full_address, employees, start_date) VALUES ('Sally', 'Jones', 'USA', '50 Market Street', 10, '04-JUL-2011');
  14. INSERT INTO customers (first_name, last_name, country, full_address, employees, start_date) VALUES ('Steve', 'Brown', 'Canada', '201 Flinders Lane', 15, '21-MAR-2009');
  15. INSERT INTO customers (first_name, last_name, country, full_address, employees, start_date) VALUES ('Mark', 'Allan', 'UK', '8 Smith Street', 23, '1-FEB-2001');
  16. INSERT INTO customers (first_name, last_name, country, full_address, employees, start_date) VALUES ('Adam', 'Cooper', 'USA', '14 Wellington Road', 55, NULL);
  17. INSERT INTO customers (first_name, last_name, country, full_address, employees, start_date) VALUES ('Josh', 'Thompson', NULL, '80 Victoria Street', 1, '10-FEB-2012');
  18. INSERT INTO customers (first_name, last_name, country, full_address, employees, start_date) VALUES ('Peter', 'Manson', 'France', '5 Johnson St', NULL, '16-OCT-2012');
  19. INSERT INTO customers (first_name, last_name, country, full_address, employees, start_date) VALUES (NULL, '', NULL, '155 Long Road', NULL, '16-OCT-2012');
  20.  
  21. SELECT * FROM customers;
  22.  
  23.  
  24. --Example 1
  25. SELECT first_name, RPAD(last_name, 15) AS padded_value
  26. FROM customers;
  27.  
  28. --Example 2
  29. SELECT first_name, RPAD(last_name, 15, '*') AS padded_value
  30. FROM customers;
  31.  
  32. --Example 3
  33. SELECT first_name, RPAD(last_name, 5, ' ') AS padded_value
  34. FROM customers;
  35.  
  36. --Example 4
  37. SELECT employees, RPAD(employees, 4, ' ') AS padded_value
  38. FROM customers;
  39.  
  40. --Example 5
  41. SELECT last_name, RPAD(LPAD(last_name, 10, '#'), 15, '*') AS padded_value
  42. FROM customers;
  43.  
  44. --Example 6
  45. SELECT country, RPAD(NVL(country, ' '), 10, '_') AS padded_value
  46. FROM customers;
  47.  
  48. --Example 7
  49. SELECT country, RPAD(country, 8, NULL) AS padded_value
  50. FROM customers;
  51.  
  52. --Example 8
  53. SELECT country, RPAD(country, 15, '-*') AS padded_value
  54. FROM customers;
  55.  
  56. --Example 9
  57. SELECT country, RPAD(country, LENGTH(country)*2, '*') AS padded_value
  58. FROM customers;

以上是关于Oracle RPAD函数的主要内容,如果未能解决你的问题,请参考以下文章

oracle Lpad()函数及Rpad()函数

Oracle中Lpad函数和Rpad函数的用法

Oracle中的填充函数lpad和rpad的用法(转)

Oracle汉字用户名数据脱敏长度不变,rpad函数使用

oracle中LPAD和RPAD函数的使用方法(加个人总结)

oracle函数 RPAD(c1,n[,c2])