I am new to PL/SQL but have plenty of other SQL experience, including Oracle (just not so much scripting). I want to declare a numeric (integer) var, set it to a row count, and display it in a sentence-wrapped string. The end goal of this exercise is to have a SQL*Plus script that prints the string “There are 1 rows”.
In SQL*Plus on Unix, I do:
SQL> variable v_dCnt number;
SQL> select count(*) into :v_dCnt from dual;
COUNT(*)
----------
1
SQL> select 'There are ' || :v_dCnt || ' rows' as MESSAGE from dual;
MESSAGE
-------------------------------------------------------
There are rows
Note how it displays blank for v_dCnt rather than a value of 1
In Rapid SQL on Win7, I do
variable v_dCnt number;
select count(*) into :v_dCnt from dual;
select 'There are ' || :v_dCnt || ' rows' from dual;
and get ORA-01008: not all variables bound
What am I doing wrong?
In SQL*Plus, you most likely just need to put the
SELECT INTOin a PL/SQL block