Oracle basic test (Part 1)

Create testing table "test" as Drupal 7.x, with auto increment sequence + trigger (http://www.databaseanswers.org/sql_scripts/ora_sequence.htm):

CREATE TABLE "test" (
  "id" INT NOT NULL CHECK ("id" >= 0),
  "name" VARCHAR2(255) DEFAULT '' NOT NULL,
  "age" INT DEFAULT 0 NOT NULL CHECK ("age" >= 0),
  "job" VARCHAR2(255) DEFAULT 'Undefined' NOT NULL
);

CREATE SEQUENCE "test_id_seq" MINVALUE 1 INCREMENT BY 1 START WITH 1 NOCACHE NOORDER NOCYCLE;

CREATE OR REPLACE TRIGGER "test_id_tgr"
  BEFORE INSERT ON "test"
  FOR EACH ROW
  WHEN (NEW."id" IS NULL)
  BEGIN   
    SELECT "test_id_seq".NEXTVAL
    INTO :NEW."id"
    FROM DUAL;
  END;
/

Insert sample data:

INSERT INTO "test" ("name", "age", "job") VALUES ('John', 25, 'Singer');
INSERT INTO "test" ("name", "age", "job") VALUES ('George', 27, 'Singer');
INSERT INTO "test" ("name", "age", "job") VALUES ('Ringo', 28, 'Drummer');
INSERT INTO "test" ("name", "age", "job") VALUES ('Paul', 26, 'Songwriter');


Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <h1> <h2> <h3> <h4> <h5> <h6> <em> <strong> <code> <del> <blockquote> <q> <sub> <p> <br> <ul> <ol> <li> <dl> <dt> <dd> <a> <b> <u> <i> <sup> <acronym> <pre> <img>
  • Lines and paragraphs break automatically.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • Images can be added to this post.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.