Skip to content
Discussion options

You must be logged in to vote

本贴子给社区用户作为参考提供帮助,执行脚本操作造成的后果自行承担
目前的方法(连接数据库,手动执行脚本,删除对应的订单数据)
数据库开源工具:DBeaver

-- ============================================
-- Halo商城按订单编号清理脚本(PostgreSQL版本)
-- 执行顺序:从子表到主表(外键约束)
-- ============================================

DO $$
DECLARE
    target_order_code VARCHAR := 'ab9e097afb7a5546d4140f85555bffe8';  -- 替换为要清理的订单编号
    target_order_id INTEGER;
    rec RECORD;  -- 声明循环变量
BEGIN
    -- 1. 查找订单ID
    SELECT id INTO target_order_id 
    FROM orders 
    WHERE order_code = target_order_code;
    
    IF target_order_id IS NULL THEN
        RAISE EXCEPTION '未找到订单编号为 % 的订单', target_order_code;
    END IF;
    
    -- 2. 验证目标订单
    RAISE NOTICE '目标订单信息:';
    FOR rec IN (
        SELECT o

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by XJY00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant