agentleFS
MathiasPaulenkoMathiasPaulenko/ai-toolkit/skills/db2-oracle/SKILL.md

db2-oracle

Skill2 starsChanged 4 months agoMITView on GitHub

Enterprise database development for IBM DB2 and Oracle. Covers PL/SQL, SQL/PL, partitioning, performance tuning, XML/JSON handling, and migration patterns.

The file

We split this skill into the rules it gives an agent

1 rule. About 0 are common, 0 are distinctive, and 1 is very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈0

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 1

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Use SERIAL or GENERATED ALWAYS AS IDENTITY instead of sequences + triggers.

    line 254

≈ “Common” is an estimate: at least 1 in 5 of the 213,895 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

DB2 and Oracle

1. Oracle PL/SQL

Basic Procedure

CREATE OR REPLACE PROCEDURE sp_create_order (
    p_user_id   IN  NUMBER,
    p_total     IN  NUMBER,
    p_order_id  OUT NUMBER
) AS
BEGIN
    INSERT INTO orders (user_id, total, status, created_at)
    VALUES (p_user_id, p_total, 'pending', SYSTIMESTAMP)
    RETURNING id INTO p_order_id;

    COMMIT;
EXCEPTION
    WHEN DUP_VAL_ON_INDEX THEN
        RAISE_APPLICATION_ERROR(-20001, 'Duplicate order detected');
    WHEN OTHERS THEN
        ROLLBACK;
        RAISE;
END;
/

Cursor and Bulk Collect

DECLARE
    TYPE t_user_tab IS TABLE OF users%ROWTYPE;
    v_users t_user_tab;
BEGIN
    SELECT * BULK COLLECT INTO v_users
    FROM users
    WHERE is_active = 1;

    FORALL i IN 1..v_users.COUNT
        UPDATE users
        SET last_login = SYSTIMESTAMP
        WHERE id = v_users(i).id;

    COMMIT;
END;
/

2. DB2 SQL/PL

Stored Procedure

CREATE PROCEDURE create_order (
    IN p_user_id INT,
    IN p_total DECIMAL(10,2),
    OUT p_order_id INT
)
BEGIN
    DECLARE v_status VARCHAR(20) DEFAULT 'pending';

    INSERT INTO orders (user_id, total, status, created_at)
    VALUES (p_user_id, p_total, v_status, CURRENT_TIMESTAMP);

    SET p_order_id = IDENTITY_VAL_LOCAL();
END

MERGE (DB2)

MERGE INTO inventory AS target
USING (SELECT product_id, quantity FROM staging_inventory) AS source
ON target.product_id = source.product_id
WHEN MATCHED THEN
    UPDATE SET target.quantity = target.quantity + source.quantity
WHEN NOT MATCHED THEN
    INSERT (product_id, quantity) VALUES (source.product_id, source.quantity);

3. Oracle Partitioning

TypeUse Case
RangeTime-series data (by month/year)
ListDiscrete categories (by region/status)
HashEven distribution for I/O balance
CompositeRange + Hash or Range + List
CREATE TABLE sales (
    sale_id NUMBER,
    sale_date DATE,
    amount NUMBER(10,2)
) PARTITION BY RANGE (sale_date) (
    PARTITION p2023q1 VALUES LESS THAN (TO_DATE('2023-04-01','YYYY-MM-DD')),
    PARTITION p2023q2 VALUES LESS THAN (TO_DATE('2023-07-01','YYYY-MM-DD')),
    PARTITION p2023q3 VALUES LESS THAN (TO_DATE('2023-10-01','YYYY-MM-DD')),
    PARTITION p2023q4 VALUES LESS THAN (TO_DATE('2024-01-01','YYYY-MM-DD')),
    PARTITION pmax VALUES LESS THAN (MAXVALUE)
);

4. DB2 Partitioning (Table Partitioning + MDC)

CREATE TABLE sales (
    sale_id INT,
    sale_date DATE,
    amount DECIMAL(10,2)
) PARTITION BY RANGE (sale_date) (
    STARTING FROM '2023-01-01' ENDING AT '2024-01-01' EVERY 3 MONTHS
)
ORGANIZE BY DIMENSIONS (EXTRACT(YEAR FROM sale_date), EXTRACT(MONTH FROM sale_date));

5. Performance Tuning

Oracle Execution Plan

EXPLAIN PLAN FOR
SELECT * FROM orders WHERE user_id = 42;

SELECT * FROM TABLE(DBMS_XPLAN.DISPLAY);

DB2 Explain

EXPLAIN PLAN FOR SELECT * FROM orders WHERE user_id = 42;

SELECT * FROM EXPLAIN_INSTANCE;

Index Hints (Oracle)

SELECT /*+ INDEX(orders idx_orders_user) */ *
FROM orders
WHERE user_id = 42;

6. JSON Handling

Oracle JSON

-- Query JSON column
SELECT id, json_data.name, json_data.address.city
FROM customers,
     JSON_TABLE(
         json_col, '$'
         COLUMNS (
             name VARCHAR2(100) PATH '$.name',
             city VARCHAR2(100) PATH '$.address.city'
         )
     ) json_data
WHERE json_exists(json_col, '$.premium' PASSING 'true' AS "premium");

DB2 JSON

-- JSON column operations
SELECT id, JSON_VAL(json_col, 'name') AS name
FROM customers
WHERE JSON_EXISTS(json_col, '$.premium');

-- Update JSON
UPDATE customers
SET json_col = JSON_SET(json_col, '$.last_visit', CURRENT_DATE)
WHERE id = 1;

7. Sequences and Identity

Oracle

CREATE SEQUENCE seq_users START WITH 1 INCREMENT BY 1 CACHE 100;

-- Trigger for auto-increment feel
CREATE TRIGGER trg_users_bi
BEFORE INSERT ON users
FOR EACH ROW
BEGIN
    :NEW.id := seq_users.NEXTVAL;
END;

DB2

-- Identity column
CREATE TABLE users (
    id INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
    name VARCHAR(100)
);

-- Sequence
CREATE SEQUENCE seq_orders START WITH 1 INCREMENT BY 1 NO CACHE;

8. Python Connectivity

Oracle (cx_Oracle)

import cx_Oracle

dsn = cx_Oracle.makedsn("host", 1521, service_name="ORCL")
with cx_Oracle.connect("user", "password", dsn) as conn:
    cursor = conn.cursor()
    cursor.execute("SELECT * FROM users WHERE id = :id", {"id": 1})
    row = cursor.fetchone()

DB2 (ibm_db)

import ibm_db

conn_str = (
    "DATABASE=mydb;HOSTNAME=host;PORT=50000;"
    "PROTOCOL=TCPIP;UID=user;PWD=pass;"
)
conn = ibm_db.connect(conn_str, "", "")

stmt = ibm_db.exec_immediate(conn, "SELECT * FROM users FETCH FIRST 10 ROWS ONLY")
result = ibm_db.fetch_both(stmt)

9. Migration Patterns

Oracle to PostgreSQL

  • Replace SYSTIMESTAMP with CURRENT_TIMESTAMP.
  • Replace ROWNUM with LIMIT.
  • Replace NVL with COALESCE.
  • Replace DECODE with CASE.
  • Use SERIAL or GENERATED ALWAYS AS IDENTITY instead of sequences + triggers.

DB2 to PostgreSQL

  • Replace FETCH FIRST n ROWS ONLY with LIMIT n.
  • Replace CURRENT DATE / CURRENT TIMESTAMP with CURRENT_DATE / CURRENT_TIMESTAMP.
  • Replace IDENTITY_VAL_LOCAL() with RETURNING id.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.