> For the complete documentation index, see [llms.txt](https://hanfak.gitbook.io/workspace/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://hanfak.gitbook.io/workspace/persistance1/plsql.md).

# PL SQL

* Programming with SQL
* Generally using procedural paragdigm

## General

* To run a function
  * 'SELECT  FROM DUAL;'
* Format of function:

  \`\`\`SQL

  CREATE OR REPLACE FUNCTION ( arg1 IN VARCHAR2, arg2 IN NUMBER )

  &#x20; RETURN VARCHAR2

  AS

  \-- variables used in function

  var1 VARCHAR2(20 BYTE);

  BEGIN

  \-- function body, can use the arg and var, as well as loops, if etc

  \-- Can access the tables and columns, use sql

END ;

\`\`\`

## Debugging

* When working with plsql, it helps to run it in an ide like SQL developer, where you can run the script against data
  * This can be done via code which will call the script, and have tests written, but sometimes feedback can be slow
  * In SQL developer (or alt) can split apart sections, replace variables with actual data, add print statements, check if it works quickly&#x20;
