PLSQL :NEW and :OLD

You normally use the terms in a trigger using :old to reference the old value and :new to reference the new value. Here is an example from the Oracle documentation linked to above CREATE OR REPLACE TRIGGER Print_salary_changes BEFORE DELETE OR INSERT OR UPDATE ON Emp_tab FOR EACH ROW WHEN (new.Empno > 0) DECLARE sal_diff … Read more

Oracle SQL: Use sequence in insert with Select Statement

Assuming that you want to group the data before you generate the key with the sequence, it sounds like you want something like INSERT INTO HISTORICAL_CAR_STATS ( HISTORICAL_CAR_STATS_ID, YEAR, MONTH, MAKE, MODEL, REGION, AVG_MSRP, CNT) SELECT MY_SEQ.nextval, year, month, make, model, region, avg_msrp, cnt FROM (SELECT ‘2010’ year, ’12’ month, ‘ALL’ make, ‘ALL’ model, REGION, … Read more

What is the max size of VARCHAR2 in PL/SQL and SQL?

See the official documentation (http://docs.oracle.com/cd/B19306_01/server.102/b14200/sql_elements001.htm#i54330) Variable-length character string having maximum length size bytes or characters. Maximum size is 4000 bytes or characters, and minimum is 1 byte or 1 character. You must specify size for VARCHAR2. BYTE indicates that the column will have byte length semantics; CHAR indicates that the column will have character semantics. … Read more

PL/MySQL does it exist?

While MySQL does have similar components, no, you cannot use PL\SQL in MySQL. The same goes for T-SQL used by MS SQL Server. MySQL has plenty of documentation on it at their website. You’ll see that both PL\SQL and T-SQL are Turing-complete, and probably provide slightly more functionality. But MySQL has plenty of ways to … Read more

PL/SQL exception handling: do nothing (ignore exception)

While I agree that 99% of the time it is bad practice to silently ignore exceptions without at least logging them somewhere, there are specific situations where this is perfectly acceptable. In these situations, NULL is your friend: […] EXCEPTION WHEN OTHERS THEN NULL; END; Two typical situations where ignoring exceptions might be desirable are: … Read more