Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can define <code>NUMBER</code> variables no problem:</p> <pre><code>SQL&gt; VARIABLE myNum NUMBER; SQL&gt; EXEC :myNum := 123.456; PL/SQL procedure successfully completed. SQL&gt; print myNum; MYNUM ---------- 123.456 </code></pre> <p>Lots of other types are supported as well. Here's the <code>USAGE</code> help text from the VARIABLE command:</p> <pre><code>Usage: VAR[IABLE] [ &lt;variable&gt; [ NUMBER | CHAR | CHAR (n [CHAR|BYTE]) | VARCHAR2 (n [CHAR|BYTE]) | NCHAR | NCHAR (n) | NVARCHAR2 (n) | CLOB | NCLOB | BLOB | BFILE REFCURSOR | BINARY_FLOAT | BINARY_DOUBLE ] ] </code></pre> <p>If you type <code>VARIABLE</code> (or just <code>VAR</code>) without anything else, SQL*Plus will list all your variables with their values.</p> <p><strong>Addendum</strong>: contrast the two variable assignment styles in the original question.</p> <p>When you do this...</p> <pre><code>define first_name = Joe select * from customer where name = '&amp;first_name'; </code></pre> <p>... It's more like a <code>#define</code> in C/C++. You can't treat it like a variable; it's just text that gets pasted every time SQL*Plus sees <code>&amp;first_name</code>.</p> <p>When you do this...</p> <pre><code>variable first_name CHAR; exec :first_name:= 'Joe'; select * from customer where name = :first_name; </code></pre> <p>You're creating a real variable that you can manipulate.</p> <p>Note that if you use <code>CHAR</code> in the definition (without a size), the first assignment will determine its size and you can't make it longer after that. If you define it as <code>CHAR(50)</code> it'll always be 50 characters long and padded with spaces. That can get confusing so I'd recommend <code>VARCHAR2</code> in most cases for strings.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload