# 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;


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://hanfak.gitbook.io/workspace/persistance1/plsql.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
