The analogy connecting selectors to CSS doesn’t just extend to events. Table 1 and Table 2 respectively map the syntax and data structures between PL/SQL and JavaScript.
Table 1. Typical PL/SQL Expressions and Their JavaScript Equivalent
| PL/SQL | JavaScript |
concat | ‘Hello ’||‘Universe’ | ‘Hello ’+“Universe” |
Built-ins | UPPER(‘Hello’) | “Hello”.toUpperCase() |
length | LENGTH(‘Hello’) | “Hello”.length |
conversion | 2 = TO_NUMBER(2) | 2 == parseInt(“2”) |
Variables | planet VARCHAR2(20) := ‘Earth’; | var planet = ‘Earth’; |
Output | dbms_output.put_line(planet); | console.log(planet); |
If boolean | If 1 = 2 then end if; | if (1==2) { } |
Null function | COALESCE(planet, ‘Mars’) | planet == ‘’ ? ‘Mars’ : planet |
Table 2. Forms Events and Their JavaScript Equivalent
| PL/SQL | JavaScript |
records | Me person%ROWTYPE; me.name := ‘Scott’; me.vintage := 1979; | var me = { name : “Scott” ,vintage : 1979 } console.log(me.name); |
arrays | type t_array is varray(3) of number; v_array t_array; v_array := t_array(1, 2, 3); | var y = [1, 2, 3] y[0] == 1 // true |
loops | for rec in 1..v_array.count loop dbms_output.put_line(‘val:’||v_array(rec)); end loop; | For { var i=0; i<y.length; i++) { console.log(‘val:’+y[i]); } |
functions | Function do_something(p_id number) return number is begin … end; | function do_something(p_id) { … } |
Note strings in JavaScript can use either single or double quotation marks to bound the string, and nested strings can use alternating quotes:
$("#p2_emps td[headers=’ENAME’]")
Nulls are handled by JavaScript in its own peculiar way. It’s worth researching their behaviors in media more specific to JavaScript itself. There are plenty of references available online for handling nulls in any language.
JavaScript will also accept your concatenation attempt if you used ’Hello’||"Universe", though the double pipe will be treated as an OR boolean expression and will only return the string ‘Hello’:
apex.debug(’p1_value: ’ || p1_value);
This slip up can make debugging harder as this expression is syntactically valid but will always return a string that makes the parameter look empty.