惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

aimingoo的专栏
aimingoo的专栏
I
InfoQ
B
Blog RSS Feed
D
Docker
GbyAI
GbyAI
N
Netflix TechBlog - Medium
Y
Y Combinator Blog
F
Fortinet All Blogs
P
Proofpoint News Feed
Microsoft Azure Blog
Microsoft Azure Blog
人人都是产品经理
人人都是产品经理
Martin Fowler
Martin Fowler
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
M
MIT News - Artificial intelligence
C
Check Point Blog
Vercel News
Vercel News
云风的 BLOG
云风的 BLOG
博客园 - Franky
Google DeepMind News
Google DeepMind News
WordPress大学
WordPress大学
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
V
V2EX
Last Week in AI
Last Week in AI
L
LangChain Blog

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
INSERT ALL and INSERT FIRST in GBase 8s: Usage and Examples
Michael · 2026-05-01 · via DEV Community

Michael

When you need to insert the same batch of data into multiple tables efficiently and consistently, GBASE's GBase 8s offers INSERT ALL and INSERT FIRST. They read the source table only once, eliminating the risk of data inconsistency that comes with running separate INSERT statements.

Syntax Overview

  • WHEN…THEN…: Can appear multiple times. INSERT FIRST acts on the first true WHEN and then stops; INSERT ALL continues evaluating and executing all subsequent true conditions.
  • Requires Oracle compatibility mode: SET ENVIRONMENT SQLMODE 'ORACLE';

Sample Data Setup

CREATE TABLE testab(id INT, name VARCHAR(20), sex VARCHAR(20), age INT);
INSERT INTO testab VALUES(101, 'lisi', 'female', 18);
INSERT INTO testab VALUES(102, 'lisi', 'female', 18);
INSERT INTO testab VALUES(103, 'xiaowu', 'male', 19);

CREATE TABLE tab1 AS SELECT * FROM testab WHERE 1 = 2;
CREATE TABLE tab2 AS SELECT * FROM testab WHERE 1 = 2;

Enter fullscreen mode Exit fullscreen mode

Unconditional Insert (INSERT ALL)

Without WHEN, every row is inserted into each listed table.

INSERT ALL
    INTO tab1 VALUES(id, name, sex, age)
    INTO tab2 VALUES(id, name, sex, age)
SELECT * FROM testab;

Enter fullscreen mode Exit fullscreen mode

The 3 rows from testab land in both tab1 and tab2, returning 6 inserted rows. To insert a single static row, use SELECT … FROM dual:

INSERT ALL
    INTO tab1 VALUES(111, 'xiaowang', 'female', 18)
    INTO tab2 VALUES(111, 'xiaowang', 'female', 18)
SELECT 1 FROM dual;

Enter fullscreen mode Exit fullscreen mode

Conditional Inserts

INSERT ALL WHEN

Executes every matching WHEN; unhandled rows can be caught by ELSE.

INSERT ALL
    WHEN id = 101 THEN
        INTO tab1 VALUES(id, name, sex, age)
    WHEN id = 102 THEN
        INTO tab2 VALUES(id, name, sex, age)
    ELSE
        INTO tab1 VALUES(id, name, sex, age)
SELECT id, name, sex, age FROM testab;

Enter fullscreen mode Exit fullscreen mode

  • id=101 → tab1
  • id=102 → tab2
  • id=103 falls to ELSE → tab1

INSERT FIRST WHEN

Only the first matching WHEN executes; subsequent conditions are skipped.

INSERT FIRST
    WHEN id = 101 THEN
        INTO tab1 VALUES(id, name, sex, age)
    WHEN id = 101 THEN
        INTO tab2 VALUES(id, name, sex, age)
SELECT id, name, sex, age FROM testab;

Enter fullscreen mode Exit fullscreen mode

Here, only id=101 goes into tab1; tab2 remains empty.

Row-to-Column Unpivot

Convert a single row's column values into multiple rows.

CREATE TABLE testab1(id INT, name VARCHAR(20), wagemon FLOAT, wagetue FLOAT, wagewed FLOAT);
INSERT INTO testab1 VALUES(111, 'xiaowang', 1.1, 1.2, 1.3);

CREATE TABLE testmp(id INT, name VARCHAR(20), wage FLOAT);

INSERT ALL
    INTO testmp VALUES(id, name, wagemon)
    INTO testmp VALUES(id, name, wagetue)
    INTO testmp VALUES(id, name, wagewed)
SELECT * FROM testab1;

Enter fullscreen mode Exit fullscreen mode

testmp receives 3 rows, with the wage column holding wagemon, wagetue, and wagewed.

Restrictions

  • Only works on tables — not views, materialized views, or remote tables.
  • Cannot use table collection expressions.
  • Target columns must not exceed 999.
  • Cannot run in parallel on RAC, on an index‑organized table, or when a BITMAP index exists.
  • Plan stability is not supported.
  • Sequences cannot appear in the subquery.

Mastering INSERT ALL and INSERT FIRST helps you build cleaner, more consistent multi‑table data flows in your gbase database environment.