1

I want to create a button using JavaScript/ Apex, so that when I click on it, a PL-SQL procedure is being "called". Similar to a regular html button, but the onClick="JavaScript function()" will be a pl-sql procedure instead. I'm trying to do this in a PL-SQL package.

Is it even possible? If it is, I'd really appreciate a simple example of how it's done.

a i
  • 11
  • 2
  • 1
    Is there a specific reason for you to call the procedure from JS? Otherwise just create a dynamic action of type execute PL/SQL code and call the procedure, set the dynamic action to be called on button clicked and voila, you're a wizard Harry – damir huselja Nov 01 '19 at 09:31

1 Answers1

3

As you tagged the question with the "oracle-apex" tag, then this is the situation:

  • there's an (Oracle) Apex application
  • it has a page
  • you want to create a button on it and - when it is pressed - call a procedure (which is part of the package) (for example, pkg_emp.p_employee(par_empno in number))
  • you want to involve JavaScript into it

No problem until the last statement. Why JavaScript? This is Apex. Once you created a button (let's call it P1_BTN_EMP), create a process :

  • its type will be "PL/SQL Code"
  • PL/SQL code will be

    pkg_emp.p_employee(:P1_EMPNO);
    

    where :P1_EMPNO represents a page item you're about to pass to the procedure

  • under "Server-side condition", set "When button pressed" to P1_BTN_EMP (i.e. button name you previously created).

That's all.

If I completely missed the point, I apologize; and no, I don't know how to do what you explicitly stated, sorry.

Littlefoot
  • 131,892
  • 15
  • 35
  • 57
  • I agree. This is the way it should be done unless you want to use Ajax for a specific reason. In that case, the comment from Damir is relevant because Dynamic Actions make this much easier than raw JavaScript. – Dan McGhan Nov 01 '19 at 14:37