Oracle LPAD函数

Posted

tags:

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

A few examples of the Oracle LPAD function.
  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.  
  20. SELECT * FROM customers;
  21.  
  22.  
  23. --Example 1
  24. SELECT first_name, LPAD(first_name, 10) AS padded_value
  25. FROM customers;
  26.  
  27. --Example 2
  28. SELECT first_name, LPAD(first_name, 10, '*') AS padded_value
  29. FROM customers;
  30.  
  31. --Example 3
  32. SELECT first_name, LPAD(first_name, 4, ' ') AS padded_value
  33. FROM customers;
  34.  
  35. --Example 4
  36. SELECT employees, LPAD(employees, 5, ' ') AS padded_value
  37. FROM customers;
  38.  
  39. --Example 5
  40. SELECT last_name, RPAD(LPAD(last_name, 10, '#'), 15, '*') AS padded_value
  41. FROM customers;
  42.  
  43. --Example 6
  44. SELECT country, LPAD(NVL(country, ' '), 10, '_') AS padded_value
  45. FROM customers;
  46.  
  47. --Example 7
  48. SELECT country, LPAD(country, 10, NULL) AS padded_value
  49. FROM customers;
  50.  
  51. --Example 8
  52. SELECT country, LPAD(country, 10, '-*') AS padded_value
  53. FROM customers;
  54.  
  55. --Example 9
  56. SELECT country, LPAD(country, LENGTH(country)*2, '*') AS padded_value
  57. FROM customers;

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

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

oracle lpad 函数使用介绍

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

Oracle LPAD函数

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

oracle lpad是啥