When testing GBase 8s, the China‑domestically developed OLTP database from GBASE, you often need to generate strings of exact lengths — for boundary checks, large‑volume insert tests, or constructing long table comments. That's where RPAD shines. This article covers the syntax, practical examples, and a reusable stored procedure that leverages RPAD for stress testing.
Function Syntax
RPAD returns a copy of source_string, right‑padded with pad_string to the total byte length specified by length. The mirror function for left padding is LPAD.
RPAD(source_string, length, pad_string)
- source_string — the original string to be padded.
- length — total byte length of the returned value.
- pad_string — one or more characters used for padding; repeated if necessary.
Basic Examples
Example 1: Simple Padding
SELECT RPAD('Where are you', 18, '?!') FROM dual;
Output:
(CONSTANT)
Where are you?!?!?
The string is shorter than 18 bytes, so ?! is repeatedly appended to the right until the target length is met.
Example 2: Inserting Fixed‑Width Data
CREATE TABLE test_table (
id INT AUTO_INCREMENT PRIMARY KEY,
data_field VARCHAR(10)
);
INSERT INTO test_table (data_field) VALUES (LPAD('123', 10, ' '));
SELECT * FROM test_table;
This is handy for verifying column length constraints or generating uniformly‑formatted sample rows in a gbase database.
Advanced Use: Generating Ultra‑Long Table Comments
You can combine RPAD with a stored procedure to dynamically create strings of any length — perfect for boundary‑value testing of table comments or column definitions.
CREATE PROCEDURE pro_comcol(table_name VARCHAR, strlen INT)
AS
var_str VARCHAR2(5000);
vlength INT;
BEGIN
SELECT RPAD('Table comment test :=++1234', strlen, '----+ghjkghjmk')
INTO var_str FROM dual;
EXECUTE IMMEDIATE 'ALTER TABLE ' || table_name || ' COMMENT= ''' || var_str || ''' ';
END;
/
CREATE TABLE t1 (col1 VARCHAR(5000));
-- Set t1's comment to 4096 bytes
CALL pro_comcol('t1', 4096);
Whether you need to test extremely long column comments, oversized column values, or just want to construct massive strings for load testing, this stored procedure provides a reusable template.
Mastering RPAD (and LPAD) in GBase 8s will save you from manually typing filler text, letting you focus on actual test logic. If you run into any issues, the GBASE community is there to help.

Top comments (0)