Lý Thành
07/24/2026, 8:12 AMRocky
07/24/2026, 8:12 AMLý Thành
07/24/2026, 8:15 AMRocky
07/24/2026, 8:15 AMNOT NULL, and the Primary Key table requires a DISTRIBUTED BY HASH clause.
sql
CREATE TABLE ptkd.card_update_type (
card_account_no VARCHAR(255) NOT NULL,
card_type VARCHAR(50) NOT NULL
)
PRIMARY KEY (card_account_no)
DISTRIBUTED BY HASH(card_account_no)
PROPERTIES (
"replication_num" = "3",
"enable_persistent_index" = "true"
);
Key Changes:
* Data Types: Oracle's VARCHAR2 is mapped to VARCHAR in StarRocks.
* Primary Key: I have designated card_account_no as the primary key. If your unique identifier consists of both columns, you should include both in the PRIMARY KEY (...) clause.
* Distribution: StarRocks uses a distributed architecture. DISTRIBUTED BY HASH(card_account_no) determines how data is spread across the cluster nodes.
* Persistent Index: The property "enable_persistent_index" = "true" is recommended for Primary Key tables to ensure stable performance when the data volume exceeds memory capacity.
* Collation: StarRocks uses UTF-8 by default; the Oracle-specific COLLATE clause is omitted as it is not supported in this format-not supported in that format-not directly applicable. directly corresponds to StarRocks' default string handling.
References
• sql-reference/sql-statements/table_bucket_part_index/CREATE_TABLE.md
• table_design/table_types/primary_key_table.mdLý Thành
07/24/2026, 8:31 AMRocky
07/24/2026, 8:31 AMNOT NULL. I have also included enable_persistent_index which is highly recommended for Primary Key tables to maintain high performance as data grows.
sql
CREATE TABLE ptkd.chikh_card_account_eom (
card_account_no VARCHAR(255) NOT NULL,
los_contract_no VARCHAR(255) NOT NULL,
last_update_date DATE,
los_cif VARCHAR(255),
main_card_number VARCHAR(255),
main_embossing_name VARCHAR(255),
billing_day_of_month VARCHAR(255),
issuing_date DATE,
active_date DATE,
eligible_active CHAR(1),
observation_date DATE,
expiry_date DATE,
overall_limit VARCHAR(255),
interest_rate VARCHAR(255),
sub_card VARCHAR(3),
sale_code VARCHAR(50),
card_type VARCHAR(50),
xsell_card VARCHAR(255),
scheme_product VARCHAR(255)
)
PRIMARY KEY (card_account_no, los_contract_no)
DISTRIBUTED BY HASH(card_account_no, los_contract_no)
PROPERTIES (
"replication_num" = "3",
"enable_persistent_index" = "true"
);
Key Considerations:
1. Primary Key Requirements: Both card_account_no and los_contract_no are set as the Primary Key and must be NOT NULL.
2. Data Types: Oracle VARCHAR2 is converted to VARCHAR. Oracle DATE is converted to StarRocks DATE (which stores YYYY-MM-DD). If your Oracle DATE fields contain timestamps (hours/minutes/seconds), you should use DATETIME instead.
3. Distribution: The table is distributed by a hash of the primary keys. This ensures that updates to the same key are handled by the same node.
4. Persistent Index: The "enable_persistent_index" = "true" property allows the primary key index to be stored on disk, preventing memory issues if the number of unique keys becomes very large.
References
• sql-reference/sql-statements/table_bucket_part_index/CREATE_TABLE.md
• table_design/table_types/primary_key_table.mdLý Thành
07/24/2026, 8:37 AMRocky
07/24/2026, 8:37 AMsql
SELECT
last_day(ISSUING_DATE) AS LAST_UPDATE_DATE,
A.card_account_no,
A.LOS_CIF,
A.LOS_CONTRACT_NO,
A.MAIN_CARD_NUMBER,
A.MAIN_EMBOSSING_NAME,
A.BILLING_DAY_OF_MONTH,
A.ISSUING_DATE,
A.ACTIVE_DATE,
CASE
WHEN A.ACTIVE_DATE <= date_add(A.ISSUING_DATE, INTERVAL 30 DAY) THEN 'Y'
ELSE 'N'
END AS ELIGIBLE_ACTIVE,
date_add(A.ACTIVE_DATE, INTERVAL 7 DAY) AS OBSERVATION_DATE,
A.EXPIRY_DATE,
A.OVERALL_LIMIT,
A.INTEREST_RATE,
A.SUB_CARD,
A.SALE_CODE,
C.CARD_TYPE,
CASE
WHEN B.SCHEME_PRODUCT LIKE '%CHS%' OR B.SCHEME_PRODUCT LIKE '%TOPUP%' THEN 'Y'
ELSE 'N'
END AS XSELL_CARD,
B.SCHEME_PRODUCT
FROM CHIKH_CARD_ACCOUNT_INFOR A
LEFT JOIN CARD_UPDATE_TYPE C
ON A.CARD_ACCOUNT_NO = C.CARD_ACCOUNT_NO
LEFT JOIN CHIKH_APPLICATION_TRACKING_V3 B
ON A.LOS_CONTRACT_NO = B.CONTRACT_NUMBER
WHERE last_day(ISSUING_DATE) >= last_day(add_months(date_sub(current_date(), 1), -2));
Key Mapping & Changes:
1. last_day(): StarRocks supports this function natively. It returns the last day of the month for the given date.
2. TRUNC(date): In Oracle, TRUNC removes the time portion. In StarRocks, if your column is a DATE type, it has no time. If it is DATETIME, you can use curdate() or cast it via ::DATE. However, for last_day and comparisons, StarRocks handles DATETIME automatically, so explicit truncation is often unnecessary.
3. Date Arithmetic (+ 30, + 7): StarRocks uses date_add(date, INTERVAL n DAY) for adding days.
4. SYSDATE: Replaced with current_date() (for the date only) or now() (for date and time).
5. ADD_MONTHS(): StarRocks supports add_months(date, n) natively, which functions similarly to Oracle.
6. SYSDATE - 1: Replaced with date_sub(current_date(), 1) to get yesterday's date.
References
• sql-reference/sql-functions/date-time-functions/last_day.md
• sql-reference/sql-functions/date-time-functions/add_months.md
• sql-reference/sql-functions/date-time-functions/date_add.md
References
• sql-reference/sql-functions/date-time-functions/months_add.md
• sql-reference/sql-functions/date-time-functions/add_months.md
• sql-reference/sql-functions/date-time-functions/date_add.md
• sql-reference/sql-functions/date-time-functions/last_day.md
• sql-reference/sql-functions/date-time-functions/adddate.md
• sql-reference/sql-functions/date-time-functions/months_diff.md
• sql-reference/sql-functions/date-time-functions/days_add.md
• sql-reference/sql-functions/date-time-functions/years_add.mdLý Thành
07/24/2026, 8:42 AMRocky
07/24/2026, 8:42 AMCHIKH_CARD_TRANSACTION_EOM table using the Primary Key model.
In StarRocks, primary key columns must be explicitly defined as NOT NULL. I have mapped the Oracle NUMBER type to DECIMAL for precision, which is standard for financial or volume data.
sql
CREATE TABLE ptkd.chikh_card_transaction_eom (
card_account_no VARCHAR(255) NOT NULL,
los_contract_no VARCHAR(255) NOT NULL,
disburse_month DATE,
los_cif VARCHAR(255),
sale_code VARCHAR(254),
issuing_date DATE,
active_date DATE,
observation_date DATE,
actual_volume DECIMAL(18, 2),
ord_month INT,
first_loan DATE,
loan DECIMAL(18, 2),
volume_adjust DECIMAL(18, 2),
xsell_card VARCHAR(1),
scheme_product VARCHAR(100)
)
PRIMARY KEY (card_account_no, los_contract_no)
DISTRIBUTED BY HASH(card_account_no, los_contract_no)
PROPERTIES (
"replication_num" = "3",
"enable_persistent_index" = "true"
);
Key Mapping Notes:
* Primary Keys: card_account_no and los_contract_no are designated as the Primary Key and must be NOT NULL.
* Data Types:
* Oracle NUMBER is mapped to DECIMAL(18, 2) (for volumes/loans) and INT (for ord_month). You can adjust the precision/scale of DECIMAL as needed.
* Oracle VARCHAR2 is mapped to VARCHAR.
* Collation: The Oracle-specific COLLATE "USING_NLS_COMP" is omitted as StarRocks uses UTF-8 by default.
* Persistent Index: The property "enable_persistent_index" = "true" is included to ensure the primary key index is stored on disk, which maintains performance and reduces memory consumption for large datasets.
References
• table_design/table_types/primary_key_table.md
• sql-reference/sql-statements/table_bucket_part_index/CREATE_TABLE.md
• sql-reference/data-types/numeric-types/DECIMAL.mdLý Thành
07/24/2026, 8:46 AMRocky
07/24/2026, 8:46 AMRocky
07/24/2026, 8:46 AMtrunc(date, 'MM') with StarRocks' date_trunc('month', date).
2. Date Arithmetic: Replaced date + 7 with date_add(date, INTERVAL 7 DAY).
3. Null Handling: Replaced NVL with ifnull (or coalesce).
4. Current Date: Replaced SYSDATE - 1 with date_sub(current_date(), 1).
5. Group By: StarRocks allows GROUP BY using column positions (1, 2, 3...) which is helpful for long expressions like your DISBURSE_MONTH logic.
6. Aggregate Handling: StarRocks is stricter about SUM results. I've wrapped the SUM(CASE...) blocks in ifnull(..., 0) to ensure math operations don't return NULL.
References
• sql-reference/sql-functions/date-time-functions/date_trunc.md
• sql-reference/sql-functions/date-time-functions/date_add.md
• sql-reference/sql-functions/conditional-functions/ifnull.md
• sql-reference/sql-functions/date-time-functions/last_day.mdLý Thành
07/27/2026, 4:31 AMRocky
07/27/2026, 4:32 AMRocky
07/27/2026, 4:32 AMfn_bo_dau): StarRocks does not have a built-in "remove accents" function. You will need to create a Java UDF or WASM UDF in StarRocks to replicate the logic of PTKD.fn_bo_dau. I have used PTKD_fn_bo_dau as a placeholder.
2. Date Conversion:
* Oracle's TO_DATE(str, 'DD-MM-YYYY') is replaced by StarRocks' str_to_date(str, '%d-%m-%Y').
* Note that StarRocks uses Python-style format strings (e.g., %d, %m, %Y).
3. String Manipulation:
* SUBSTR(col, LENGTH(col) - 4, 5) is simplified to RIGHT(col, 5).
* SUBSTR(CUSTOMER_ID, 2, LENGTH(CUSTOMER_ID)) is simplified to SUBSTR(CUSTOMER_ID, 2).
4. TRUNC(date): Replaced with CAST(date AS DATE) or date_trunc('day', date).
5. INSTR: StarRocks supports instr(string, substring) natively.
6. GROUP BY: In StarRocks, you can use column aliases or ordinal positions (e.g., GROUP BY 1, 2, 3) for cleaner`) in CTEs.
Reference Links:
• StarRocks str_to_date
• StarRocks RIGHT function
• StarRocks User Defined Functions (UDF)Lý Thành
07/27/2026, 8:11 AMRocky
07/27/2026, 8:11 AMCHIKH_CARD_ACCOUNT_INFOR table using the Primary Key model with CARD_ACCOUNT_NO as the primary key.
In StarRocks, primary key columns must be defined as NOT NULL. I have mapped Oracle's DATE to DATETIME to preserve time information and NUMBER to BIGINT for ID-related fields.
sql
CREATE TABLE ptkd.chikh_card_account_infor (
card_account_no VARCHAR(255) NOT NULL COMMENT "Primary Key",
create_date_time DATETIME,
los_cif VARCHAR(255),
los_contract_no VARCHAR(255),
e6_cust_id BIGINT,
order_id BIGINT,
card_program VARCHAR(255),
card_profile_name VARCHAR(255),
main_card_number VARCHAR(255),
main_pan_first6 VARCHAR(255),
main_pan_last4 VARCHAR(255),
main_embossing_name VARCHAR(255),
sub_card_number_1 VARCHAR(100),
sub_pan_first6_1 VARCHAR(100),
sub_pan_last4_1 VARCHAR(100),
sub_embossing_name_1 VARCHAR(100),
sub_card_number_2 VARCHAR(100),
sub_pan_first6_2 VARCHAR(100),
sub_pan_last4_2 VARCHAR(100),
sub_embossing_name_2 VARCHAR(100),
billing_day_of_month VARCHAR(255),
issuing_date DATETIME,
active_date DATETIME,
expiry VARCHAR(255),
expiry_date DATETIME,
close_date VARCHAR(255),
e6_status VARCHAR(100),
e6_block_status VARCHAR(3),
card_service_status VARCHAR(100),
overall_limit VARCHAR(255),
limit_day VARCHAR(255),
limit_month VARCHAR(255),
limit_year VARCHAR(255),
limit_tran VARCHAR(255),
interest_rate VARCHAR(255),
cash_interest_rate VARCHAR(20),
purchase_interest_rate VARCHAR(20),
fee_interest_rate VARCHAR(20),
sub_card VARCHAR(3),
sale_code VARCHAR(50)
)
PRIMARY KEY (card_account_no)
DISTRIBUTED BY HASH(card_account_no)
PROPERTIES (
"replication_num" = "3",
"enable_persistent_index" = "true"
);
Key Mapping & Design Notes:
* Primary Key Requirement: card_account_no is set to NOT NULL as required by the Primary Key model.
* Data Types:
* Oracle DATE is mapped to StarRocks DATETIME because Oracle's DATE type typically stores both date and time.
* Oracle NUMBER (for IDs) is mapped to BIGINT.
* Oracle VARCHAR2 is mapped to VARCHAR.
* Persistent Index: The property "enable_persistent_index" = "true" is enabled. This is highly recommended for Primary Key tables to ensure that the primary key index is stored on disk, reducing memory usage while maintaining high performance.
* Bucket Count: By not specifying BUCKETS, StarRocks will automatically determine the number of tablets based on the cluster scale (available in newer versions).
References
• table_design/table_types/primary_key_table.md
• sql-reference/data-types/date-time-types/DATETIME.md
• sql-reference/sql-statements/table_bucket_part_index/CREATE_TABLE.mdLý Thành
07/27/2026, 8:51 AMRocky
07/27/2026, 8:51 AMDTM_CLZB_AMOUNT_PAID table using the Duplicate Key model.
In the Duplicate Key model, StarRocks sorts and indexes data based on the columns specified in the DUPLICATE KEY clause. For best performance, the key column (ACCOUNT_NUMBER) should be defined at the beginning of the table.
sql
CREATE TABLE dmapp.dtm_clzb_amount_paid (
account_number VARCHAR(35) NOT NULL COMMENT "Key column",
sys_run_date DATETIME,
branch_code VARCHAR(35),
component_name VARCHAR(35),
due_date DATE,
paid_date DATETIME,
event_seq_no BIGINT,
amount_paid DECIMAL(18, 2),
amount_waived DECIMAL(18, 2),
amount_capitalized DECIMAL(18, 2),
exec_date DATETIME,
paid_status VARCHAR(1),
start_date DATE
)
DUPLICATE KEY(account_number)
DISTRIBUTED BY HASH(account_number)
PROPERTIES (
"replication_num" = "3"
);
Key Mapping & Design Notes:
* Duplicate Key Model: This model is ideal for raw data or logs where you want to keep every record (even if the ACCOUNT_NUMBER is the same) without merging or overwriting.
* Data Types:
* Oracle NUMBER (for sequence/ID) is mapped to BIGINT.
* Oracle NUMBER (for financial amounts) is mapped to DECIMAL(18, 2). You can increase precision to (38, 4) if very high precision is required.
* Oracle DATE is mapped to DATETIME for timestamp fields and DATE for fields typically used as calendar dates.
* Column Order: The account_number is placed first. In StarRocks, the order of columns in the schema determines the sort order on disk for Duplicate Key tables, which significantly speeds up queries filtering by those leading columns.
* Distribution: Data is partitioned/distributed across the cluster based on the hash of account_number, ensuring data for the same account is stored on the same node (which optimizes joins and aggregations on that column).
References
• table_design/table_types/duplicate_key_table.md
• sql-reference/data-types/numeric-types/DECIMAL.md
• table_design/data_distribution/Data_distribution.mdLý Thành
07/28/2026, 1:54 AMRocky
07/28/2026, 1:55 AMsql
SHOW CREATE CATALOG <catalog_name>;
2. List All Catalogs
To see a list of all catalogs in the cluster and their basic types:
sql
SHOW CATALOGS;
3. Describe Catalog
You can also view the comment or basic metadata of a catalog using:
sql
DESC CATALOG <catalog_name>;
──────────
References:
* SHOW CREATE CATALOG
* SHOW CATALOGS
References
• sql-reference/sql-statements/Catalog/CREATE_EXTERNAL_CATALOG.md
• data_source/catalog/jdbc_catalog.mdLý Thành
07/28/2026, 2:35 AMRocky
07/28/2026, 2:35 AMCHIKH_LOAN_EOM table using the Primary Key model.
In StarRocks, all columns defined in the PRIMARY KEY must be declared as NOT NULL. I have mapped the financial NUMBER fields to DECIMAL for precision and ID/count fields to BIGINT.
sql
CREATE TABLE ptkd.chikh_loan_eom (
last_update_date DATE NOT NULL,
ld_no VARCHAR(50) NOT NULL,
ld_di_key BIGINT,
ld_di_no VARCHAR(5) NOT NULL,
lms_cif_no VARCHAR(20),
los_cif_no VARCHAR(20),
customer_name VARCHAR(250),
branch_code VARCHAR(250),
lms_prod_group VARCHAR(10),
lms_prod_code VARCHAR(10),
int_rate DECIMAL(13, 8),
contract_no VARCHAR(30),
app_code VARCHAR(50),
ld_di_date DATE,
disbursement_date DATE,
signed_date DATE,
maturity DATE NOT NULL,
product_code VARCHAR(20),
product_name VARCHAR(750),
channel VARCHAR(7),
loan_term BIGINT,
acct_no VARCHAR(20),
emi_amount DECIMAL(18, 2),
collection_fee DECIMAL(18, 2),
total_emi_amount DECIMAL(18, 2),
first_payment_date DATE,
second_payment_date DATE,
third_payment_date DATE,
fourth_payment_date DATE,
insurance_fee DECIMAL(18, 2),
insurance_code VARCHAR(20),
loan_amount_insured DECIMAL(18, 2),
partner_code VARCHAR(20),
loan_purpose VARCHAR(50),
loan_purpose_lbl VARCHAR(250),
disbursement_channel VARCHAR(50),
agency_payment VARCHAR(50),
mob3_date DATE,
mob4_date DATE,
sale_code VARCHAR(50),
sale_name VARCHAR(250),
loan_amt DECIMAL(18, 2) NOT NULL,
currency VARCHAR(3) NOT NULL,
total_overdue_amount DECIMAL(18, 2),
int_received DECIMAL(18, 2),
od_received DECIMAL(18, 2),
pri_received DECIMAL(18, 2),
fee_received DECIMAL(18, 2),
fee_coll_received DECIMAL(18, 2),
last_payment_date DATE,
last_payment_amount DECIMAL(18, 2),
payment_vol VARCHAR(20),
check_fpd VARCHAR(3),
check_spd VARCHAR(3),
check_tpd VARCHAR(3),
overdue_amount_1fst DECIMAL(18, 2),
overdue_amount_2snd DECIMAL(18, 2),
overdue_amount_3trd DECIMAL(18, 2),
max_dpd_1fst BIGINT,
max_dpd_2snd BIGINT,
max_dpd_3trd BIGINT,
total_overdue_period BIGINT,
current_payment_period BIGINT,
next_payment_period BIGINT,
remaining_amount DECIMAL(18, 2),
fpd10_case_risk CHAR(1),
fpd_case_10 CHAR(1),
fpd30_case_risk CHAR(1),
fpd_case_30 CHAR(1),
spd10_case_risk CHAR(1),
spd_case_10 CHAR(1),
spd30_case_risk CHAR(1),
spd_case_30 CHAR(1),
tpd10_case_risk CHAR(1),
tpd_case_10 CHAR(1),
tpd30_case_risk CHAR(1),
tpd_case_30 CHAR(1),
mob3_case_risk CHAR(1),
mob3_case CHAR(1),
mob3_case_kpi CHAR(1),
mob4_case_risk CHAR(1),
mob4_case CHAR(1),
over_due_days_ld BIGINT,
next_repay_date DATE,
contract_status VARCHAR(20)
)
PRIMARY KEY (last_update_date, ld_no)
DISTRIBUTED BY HASH(ld_no)
PROPERTIES (
"replication_num" = "3",
"enable_persistent_index" = "true"
);
Mapping & Design Notes:Rocky
07/28/2026, 2:35 AMlast_update_date and ld_no are included in the Primary Key and are set to NOT NULL.
* Financial Precision: Oracle NUMBER fields representing amounts are mapped to DECIMAL(18, 2) (supporting 18 digits total, 2 decimal places). INT_RATE uses DECIMAL(13, 8) to match your specific Oracle precision.
* Persistent Index: Enabled to optimize primary key lookups and memory efficiency.
* Distribution: I chose ld_no for distribution as it likely provides better cardinality than a date for even data balancing across the cluster.
References
• table_design/table_types/primary_key_table.md
• sql-reference/data-types/numeric-types/DECIMAL.mdLý Thành
07/28/2026, 2:41 AMRocky
07/28/2026, 2:41 AMDATE type includes hours, minutes, and seconds, mapping it to StarRocks DATETIME is the best practice to avoid losing time-level precision.
Here is the updated DDL for the Primary Key table with all date fields converted to `DATETIME`:
sql
CREATE TABLE ptkd.chikh_loan_eom (
last_update_date DATETIME NOT NULL COMMENT "Primary Key component",
ld_no VARCHAR(50) NOT NULL COMMENT "Primary Key component",
ld_di_key BIGINT,
ld_di_no VARCHAR(5) NOT NULL,
lms_cif_no VARCHAR(20),
los_cif_no VARCHAR(20),
customer_name VARCHAR(250),
branch_code VARCHAR(250),
lms_prod_group VARCHAR(10),
lms_prod_code VARCHAR(10),
int_rate DECIMAL(13, 8),
contract_no VARCHAR(30),
app_code VARCHAR(50),
ld_di_date DATETIME,
disbursement_date DATETIME,
signed_date DATETIME,
maturity DATETIME NOT NULL,
product_code VARCHAR(20),
product_name VARCHAR(750),
channel VARCHAR(7),
loan_term BIGINT,
acct_no VARCHAR(20),
emi_amount DECIMAL(18, 2),
collection_fee DECIMAL(18, 2),
total_emi_amount DECIMAL(18, 2),
first_payment_date DATETIME,
second_payment_date DATETIME,
third_payment_date DATETIME,
fourth_payment_date DATETIME,
insurance_fee DECIMAL(18, 2),
insurance_code VARCHAR(20),
loan_amount_insured DECIMAL(18, 2),
partner_code VARCHAR(20),
loan_purpose VARCHAR(50),
loan_purpose_lbl VARCHAR(250),
disbursement_channel VARCHAR(50),
agency_payment VARCHAR(50),
mob3_date DATETIME,
mob4_date DATETIME,
sale_code VARCHAR(50),
sale_name VARCHAR(250),
loan_amt DECIMAL(18, 2) NOT NULL,
currency VARCHAR(3) NOT NULL,
total_overdue_amount DECIMAL(18, 2),
int_received DECIMAL(18, 2),
od_received DECIMAL(18, 2),
pri_received DECIMAL(18, 2),
fee_received DECIMAL(18, 2),
fee_coll_received DECIMAL(18, 2),
last_payment_date DATETIME,
last_payment_amount DECIMAL(18, 2),
payment_vol VARCHAR(20),
check_fpd VARCHAR(3),
check_spd VARCHAR(3),
check_tpd VARCHAR(3),
overdue_amount_1fst DECIMAL(18, 2),
overdue_amount_2snd DECIMAL(18, 2),
overdue_amount_3trd DECIMAL(18, 2),
max_dpd_1fst BIGINT,
max_dpd_2snd BIGINT,
max_dpd_3trd BIGINT,
total_overdue_period BIGINT,
current_payment_period BIGINT,
next_payment_period BIGINT,
remaining_amount DECIMAL(18, 2),
fpd10_case_risk CHAR(1),
fpd_case_10 CHAR(1),
fpd30_case_risk CHAR(1),
fpd_case_30 CHAR(1),
spd10_case_risk CHAR(1),
spd_case_10 CHAR(1),
spd30_case_risk CHAR(1),
spd_case_30 CHAR(1),
tpd10_case_risk CHAR(1),
tpd_case_10 CHAR(1),
tpd30_case_risk CHAR(1),
tpd_case_30 CHAR(1),
mob3_case_risk CHAR(1),
mob3_case CHAR(1),
mob3_case_kpi CHAR(1),
mob4_case_risk CHAR(1),
mob4_case CHAR(1),
over_due_days_ld BIGINT,
next_repay_date DATETIME,
contract_status VARCHAR(20)
)
PRIMARY KEY (last_update_date, ld_no)
DISTRIBUTED BY HASH(ld_no)
PROPERTIES (
"replication_num" = "3",
"enable_persistent_index" = "true"
);Rocky
07/28/2026, 2:41 AMDATE field is now DATETIME (which stores YYYY-MM-DD HH:MM:SS), preserving the time data from the source.
* Primary Key Model: last_update_date and ld_no together uniquely identify a record. If a record with the same key is loaded again, StarRocks will automatically perform an Upsert (update the existing row).
References
• sql-reference/data-types/date-and-time/DATETIME.md
• table_design/table_types/primary_key_table.md
References
• unloading/Spark_connector.md
• data_source/External_table.md
• data_source/catalog/maxcompute_catalog.md
• data_source/catalog/paimon_catalog.md
• table_design/data_distribution/dynamic_partitioning.md
• table_design/table_types/primary_key_table.mdLý Thành
07/28/2026, 7:53 AMnamespace) BUCKETS 4
PROPERTIES (
"replication_num" = "2"
);
fix my sqlRocky
07/28/2026, 7:54 AM') to backticks (`` ` ``) for identifiers and remove the ON UPDATE CURRENT_TIMESTAMP clause, as StarRocks does not currently support automatic updates for timestamps on record modification.
Fixed SQL
sql
CREATE TABLE IF NOT EXISTS long_term_store (
`namespace` VARCHAR(255) NOT NULL,
`key` VARCHAR(255) NOT NULL,
`value` JSON NOT NULL,
`updated_at` DATETIME DEFAULT CURRENT_TIMESTAMP
) ENGINE=OLAP
PRIMARY KEY(`namespace`, `key`)
DISTRIBUTED BY HASH(`namespace`) BUCKETS 4
PROPERTIES (
"replication_num" = "2",
"enable_persistent_index" = "true"
);
Key Changes & Improvements:
1. Backticks instead of Single Quotes: In SQL, single quotes ('key') are for string literals. For column names (identifiers), use backticks (`` key ``) or no quotes at all. This is especially important for reserved keywords like key and value.
2. Removed ON UPDATE: StarRocks supports DEFAULT CURRENT_TIMESTAMP for the initial insert, but it does not support the ON UPDATE trigger. You must manually update the updated_at column in your INSERT (UPSERT) statements using the now() function.
3. Persistent Index: Added "enable_persistent_index" = "true". For Primary Key tables, this is highly recommended as it keeps the primary key index on disk (optimized for SSDs), preventing high memory consumption as your data grows.
4. JSON Support: Your use of the JSON type in a Primary Key table is correct (available since version 2.5+).
Note on Replication
If you are running a single-node test cluster, you may need to set "replication_num" = "1". For a standard production cluster, the recommended value is "3".
References
• sql-reference/sql-functions/date-and-time-functions/current_timestamp.md
• table_design/table_types/primary_key_table.md
• sql-reference/data-types/semi_structured/JSON.md
References
• sql-reference/data-types/semi_structured/JSON.md
• table_design/table_types/table_capabilities.md
• table_design/table_types/primary_key_table.mdLý Thành
07/28/2026, 8:03 AMRocky
07/28/2026, 8:03 AMREVOKE statement.
Basic Syntax
sql
REVOKE <role_name> FROM USER <user_identity>;
Examples
* Revoke a single role:
sql
REVOKE analyst_role FROM USER 'jack'@'%';
* Revoke multiple roles at once:
sql
REVOKE role1, role2 FROM USER 'jack'@'192.168.1.1';
Important Notes:
1. Permissions: Only users with the user_admin role (or the root user) have the privilege to revoke roles from other users.
2. User Identity: The user identity must match exactly as it appears in StarRocks (e.g., 'username'@'host'). You can find this by running SHOW USERS;.
3. Default Role: If you revoke a role that was set as the user's default role, the user may lose those permissions upon their next login unless another default role is assigned.
4. PUBLIC Role: You cannot revoke the system-defined PUBLIC role from any user.
References
• sql-reference/sql-statements/account-management/REVOKE.md
• administration/user_privs/authorization/User_privilege.md
References
• sql-reference/sql-statements/account-management/REVOKE.md
• administration/user_privs/authorization/User_privilege.mdLý Thành
07/28/2026, 9:07 AMRocky
07/28/2026, 9:07 AMmonths_diff function as an equivalent to MONTHS_BETWEEN. Since your logic applies LAST_DAY to both inputs, the result will be an integer, which matches StarRocks' months_diff behavior.
StarRocks Version
sql
SELECT
LAST_DAY(BONUS_MONTH) AS BONUS_MONTH
, P.SALE_NAME
, P.SALE_CODE
, SUB_REGION
, CONTRACT_DATE
, months_diff(LAST_DAY(ADD_MONTHS(TO_DATE(BONUS_MONTH), -1)), LAST_DAY(CONTRACT_DATE)) + 1 AS VINTAGE
, P.CONTRACT_TYPE
FROM your_table_name P;
Key Mapping Changes:
1. MONTHS_BETWEEN(newer, older) → months_diff(newer, older):
In StarRocks, months_diff(expr1, expr2) calculates expr1 - expr2 and returns a BIGINT.
2. LAST_DAY(date):
This works exactly the same in StarRocks (available from version 3.1 onwards). It returns the last day of the month for the given date.
3. ADD_MONTHS(date, n):
StarRocks supports this function natively. It behaves similarly to Oracle, though it returns a DATETIME (you can wrap it in TO_DATE() if you only need the date part).
4. TO_DATE(string):
StarRocks' TO_DATE converts a string (in YYYY-MM-DD format) or a DATETIME to a DATE.
Important Note on `months_diff`:
Oracle's MONTHS_BETWEEN can return a decimal (e.g., 1.5) if the days of the month don't match. StarRocks' months_diff always returns a whole number (BIGINT). However, because your query uses LAST_DAY on both dates, they are both aligned to the end of the month, meaning the Oracle result would have been a whole number anyway. This translation is therefore accurate for your specific "Vintage" calculation.
References
• sql-reference/sql-functions/date-time-functions/months_diff.md
• sql-reference/sql-functions/date-time-functions/last_day.md
• sql-reference/sql-functions/date-time-functions/add_months.md
References
• sql-reference/sql-functions/date-time-functions/add_months.md
• sql-reference/sql-functions/date-time-functions/months_add.md
• sql-reference/sql-functions/date-time-functions/last_day.md
• sql-reference/sql-functions/date-time-functions/date_add.md
• sql-reference/sql-functions/date-time-functions/months_diff.md
• sql-reference/sql-functions/date-time-functions/adddate.md
• sql-reference/sql-functions/date-time-functions/months_sub.md
• sql-reference/sql-functions/date-time-functions/days_add.md