Anonymous and named PL/SQL block

  • Anonymous PL/SQL block
    • Need to compile every time
    • Not stored
  • Named PL/SQL block
    • Can be stored in DB

Stored Procedure


Procedure ::= CREATE [OR REPLACE] PROCEDURE ProcedureName '(' Parameters ')' (AS|IS) RETURN ReturnType DECLARE Declaration BEGIN Body END ';'
Parameters ::= Nothing | Parameter {, Parameter}
Parameter ::= ParameterName (IN|OUT|IN OUT) Type ':=' DefaultValue
  • Note:
    • In the parameter list, varchar cannot be specified with a length.
    • MySQL has no AS|IS in the procedure, and IN/OUT is put before the parameter name.
    • In MySQL ,one has to change the delimiter before defining a procedure or function.

Loop statement

  • for x in [Reverse] 1..20 loop … end loop;
  • while … loop … end loop;
    To escape from a loop:
  • exit when …;

Conditional statement

  • if … then … elseif … end if;


  • Used to process a set of records. PL/SQL record variable can only store one record at a time.
  • Technically, it acts like an iterator, which means one cannot process multiple records at the same time(though we can store them as a whole).
  • In declaration, a cursor is declared with a SELECT statement, and we can use this cursor to access the data returned by that SELECT statement
  • A cursor is bind to one specific SELECT clause, that is, one cannot bind it to another SELECT statement
  • The SELECT statement is and only is executed when the cursor is OPENed(see below).
  • CLOSE the cursor to free the memory space.
  1. Declaration

    cursor cursor_name is select statement;

  2. Open cursor

    OPEN cursor_name;

  3. Get the data

    FETCH cursor_name into variable;

  • The cursor will move forward, just like python’s next function do.
  1. Check if there is no more entry

    IF NOT cursor_name%FOUND THEN …;

  2. Close the cursor

    CLOSE cursor_name;

  3. For loop
    Unique to Oracle.
    No need to open, close, or fetch from a cursor.

    FOR variable in cursor_name LOOP
    – do something to the variable

Artificial Intelligence

Knowledge base && Inferrence

* Truth table

* Brute force search

* Forward chaining
    * reliable
    * completeness
        * -> only have these two properties for the knowledge bases able to be expressed with Horn clauses
        * Horn clause: a disjunction of literals with at most one unnegated literal
            * E.g. $\neg x_1 \vee \neg x_2 \vee \cdots \vee x_n \vee u$

* Backward chaining
    * To prove q, with p->q now prove p
    * Avoid repeating by check if a clause is already proved or disproved


Panning derives from panorama.

4/11 Record

Programming Languages

Polymorphic Functions

  • Static: cost grows exponentially with parameters
  • Dynamic:
    • supply a tag when calling the function

Example: Overloading Equality

  1. Equality was overloaded as an operator
  2. Make type of equality fully polymorphic
  3. Make equality polymorphic in a limited way
    • (==) :: ''t -> ''t -> Bool, ''t is a type t with equality
    • will be a static error if t is not Eq type

Type Classes

  1. Merchanism in Haskell
  2. Dictionary-passing style implementation [ESOP1988]
    • Type class declaration – dictionary
    • Name of a type class method – label in the dictionary
    • Parametric overloading – passing the dictionary to the function
class Show a where
show :: a -> String

instance Show Bool where
show True = "True"
show False = "False"

print :: Show a => a -> IO ()
print x = putStrLn $ show x
type 'a show = {show: 'a -> string}
let show_bool : bool show =
show = function
| true -> "True"
| false -> "False"

let print : 'a show -> 'a -> unit =
fun {show=show} x -> print_endline (show x)

Smalltalk: subtyping

  • Object -> super class

    -> method table
  • If interface A contains all of interface B, then A objects can also be used as B objects

    • need to look up all instances(members) at runtime

Javascript has the same problem

  • v8 engine: hidden class
    function Person(first_name, last_name) {
    this.first_name = first_name;
    this.last_name = last_name;

    var potus = new Person('D.', 'Trump');
    var potrf = new Person('V.', 'Putin');

Computer Architecture

Optimizing cache

Merging write cache



最低だ 最低だ 最低だ