PLS-00103: Encountered the symbol "G_OUTPUT" when expecting one of the following: := - plsql

--script2.sql
--Krishan Billa
ACCEPT p_make PROMPT 'ENTER MAKE OF THE CAR';
ACCEPT p_model PROMPT 'ENTER MODEL OF THE CAR';
ACCEPT p_year PROMPT 'ENTER YEAR OF THE CAR';
ACCEPT p_color PROMPT 'ENTER COLOR OF THE CAR';
VARIABLE g_output VARCHAR2(500);
DECLARE
CURSOR allprospects
IS
SELECT b.cname,
TRIM(b.cstreet),
TRIM(b.ccity),
TRIM(b.cprov),
TRIM(b.cpostal)
FROM s9.prospect a
INNER JOIN s9.customer b
ON(a.cname =b.cname)
WHERE UPPER(a.make)=UPPER('&p_make')
AND UPPER(a.model) =UPPER('&p_model')
AND a.cyear ='&p_year'
AND UPPER(a.color) =UPPER('&p_color');
BEGIN
:g_output := '&p_make'||CHR(10);
FOR v_prospect IN allprospects LOOP
:g_output := :g_output||'test';
--:g_output := :g_output || v_prospect.cname || CHR(10)|| v_prospect.ccity || CHR(10);
--:g_output := :g_output || v_prospect.ccity ||','|| v_prospect.cprov || ' ' || v_prospect.cpostal || CHR(10);
END LOOP;
END;
PRINT g_output;
--select make,model,cyear,color,count(*)from s9.prospect group by model,make,cyear,color;
--desc s9.prospect;
--desc s9.customer;
--JAGUAR XL 2016 RED 2
Please see the error below when i run this code. It looks pretty fine to me. Can anyone please help? Thankyou
ORA-06550: line 24, column 7:
PLS-00103: Encountered the symbol "G_OUTPUT" when expecting one of the following: := . ( # % ; 06550. 00000 - "line %s, column %s:\n%s"

You're missing the terminator SQLPlus is looking at the end of the plsql block. So the line "print g_output" is included in the block sent to the plsql "compiler". The compiler doesn't know what to do with it, and is not expecting it. That is the error. Try:
END;
/
PRINT g_output;

Related

How to remove error code and print only message | PLSQL

I have to print only error message and remove code number
BEGIN
IF :MY_TEXT is null THEN
raise_application_error(-20001,'Text field cannot be empty')
END IF;
Exception
when others then
:MSG := replace(SQLERRM,'^ORA-+:','');
END;
Expected output :
Text filed cannot be empty
You need to use something like this SUBSTR(MSG, INSTR(MSG, ':', 1, 1)+2 )
DECLARE
MY_TEXT VARCHAR2(100);
MSG VARCHAR2(100);
BEGIN
IF MY_TEXT is null THEN
raise_application_error(-20001,'Text field cannot be empty');
END IF;
Exception
when others then
MSG := SQLERRM ;
dbms_output.put_line( SUBSTR(MSG, INSTR(MSG, ':', 1, 1)+2 ) );
END;
/
You could also just change your REPLACE call to a REGEXP_REPLACE as it appears you were trying to use a regular expression to match the error:
:MSG := REGEXP_REPLACE(SQLERRM,'^ORA-[0-9]+: ', NULL);
Match a pattern of 'ORA-' at the start of the line, followed by 1 or digits, then a colon followed by a space and replace with NULL.
Note technically the ', NULL' is not needed in this call but including makes it clear to future maintainers what the intention is here and I would argue would be best practice.

ORA-00933 runtime plsql throwing the error

I am trying to query the dba_tables, if table "SPLIT_EXT_INFO" not present i am getting correct output, if table "SPLIT_EXT_INFO" exist i am getting below error,
SET serveroutput ON
DECLARE
t_cnt NUMBER;
v_schema_name VARCHAR2(40) := 'DBA';
v_table_name VARCHAR2(40) := 'SPLIT_EXT_INFO';
refcur SYS_REFCURSOR;
split_mapper VARCHAR2(40);
info_tab VARCHAR2(40);
tracker VARCHAR2(40);
BEGIN
SELECT Count(1)
INTO t_cnt
FROM dba_tables
WHERE owner = v_schema_name
AND table_name = v_table_name;
dbms_output.Put_line(t_cnt);
IF t_cnt = 0 THEN
dbms_output.Put_line('NO_SPLIT_TAB');
ELSE
OPEN refcur FOR 'SELECT split_mapper, info_tab, tracker FROM '
||v_schema_name
||'.'
||v_table_name
|| 'where nodename = ''host1.world.com''';
LOOP
FETCH refcur INTO split_mapper,info_tab,tracker;
EXIT WHEN refcur%NOTFOUND;
dbms_output.Put_line(split_mapper
||':'
||info_tab
||':'
||tracker);
END LOOP;
IF refcur%rowcount = 0 THEN
dbms_output.Put_line('NO_SPLIT_ENTRY');
END IF;
END IF;
CLOSE refcur;
END;
/
Error:
1
DECLARE
*
ERROR at line 1:
ORA-00933: SQL command not properly ended
ORA-06512: at line 21
can someone add help in this, thanks !
Regards
Kannan
The apostrophe symbol is on a wrong place before WHERE clause is being concatenated
your code: || 'where nodename = ''host1.world.com''';
right is : ||' where nodename = ''host1.world.com''';
In your version the sql will look like
select ... FROM tableWHERE nomename = ...
The missing space symbol between table name and WHERE causing this problem

PLS-00653 Error on an empty line (Aggregate/table functions are not allowed in PL/SQL scope)

I'm trying to run a PL/SQL Script I made but I'm getting an error:
PLS-00653: aggregate/table functions are not allowed in PL/SQL scope
The problem here is not the error in itself but the line where it's being thrown from.
Here's my PL/SQL block which throws this error:
DECLARE
TYPE l_code_arr_typ IS VARRAY(3) OF VARCHAR2(100);
l_code_arr l_code_arr_typ;
l_objet objet_interface_pkg.objet_interface_typ;
l_resultat CLOB;
l_valeur valeur_pkg.valeur_typ;
l_liens lien_objet_interface_pkg.lien_objet_interface_tab;
l_rows NUMBER;
BEGIN
l_code_arr := l_code_arr_typ('champ.fonctions.dossier.particulier',
'champ.fonctions.region.admin',
'champ.fonctions.ministere.organisme');
l_resultat := '{';
FOR l_idx IN 1 .. l_code_arr.count LOOP
l_objet := objet_interface_pkg.obtenir_fnc(p_code => l_code_arr(l_idx),
p_acron_sys => :acronyme);
l_resultat := l_resultat || '"' || l_objet.code || '":[';
l_liens := lien_objet_interface_pkg.obtenir_par_objet_fnc(p_id_objet => l_objet.id_obj);
FOR l_lien IN (SELECT * FROM TABLE(l_liens)) LOOP
l_valeur := valeur_pkg.obtenir_fnc(p_id => l_lien.id_valeur);
l_resultat := l_resultat || '"' || l_valeur.valeur || '"';
FOR l_enfant IN (SELECT *
FROM TABLE(valeur_pkg.obtenir_enfants_fnc(p_id_parent => l_lien.id_valeur,
p_code => l_valeur.valeur))) LOOP
l_resultat := l_resultat || ',"' || l_enfant.valeur || '"';
END LOOP;
END LOOP;
l_resultat := l_resultat || '],';
END LOOP;
<<<<<<<<<< ERROR THROWN HERE (EMPTY LINE)
l_resultat := substr(l_resultat, 1, length(l_resultat) - 1) || '}';
dbms_output.put_line(l_resultat);
END;
The error throws on 34:17 (line:column) which is the fourth line from the end of the code block. As you can see the real problem is that this line is an empty line. Moreover, none of the lines near that empty line contains a call to an aggregate function. So where's the aggregate/table function's call located?
I'm wondering if the problem really comes from my code or if my PL/SQL Developer is broken.
I hope someone can help me...
I found the solution!
The problem is that the function lien_objet_interface_pkg.obtenir_par_objet is PIPELINED and a pipelined return cannot be stored in a variable.
So these 2 lines...
l_liens := lien_objet_interface_pkg.obtenir_par_objet_fnc(p_id_objet => l_objet.id_obj);
FOR l_lien IN (SELECT * FROM TABLE(l_liens)) LOOP
...need to be merge into one single line like so:
FOR l_lien IN (SELECT * FROM TABLE(lien_objet_interface_pkg.obtenir_par_objet_fnc(p_id_objet => l_objet.id_obj))) LOOP
However, I still don't know why PL\SQL Developer said my error comes from line 34 and It'll probably remain a mystery. If anyone have answer to this mystery, please feel free to let me know.

Unable to get user input in PL in sqldeveloper

I'm trying to get user input in SQLDeveloper in a procedure. But however , I'm getting some error like "missing defines". Please help me to solve this. Thanks in advance.
DECLARE
a NUMBER(5);
BEGIN
a := :a;
DBMS_OUTPUT.PUT_LINE('We took the number as ' || a);
END;
The error looks like this.
Error starting at line : 1 in command -
DECLARE
a NUMBER(5);
BEGIN
a := :a;
DBMS_OUTPUT.PUT_LINE('We took the number as ' || a);
END;
Error report -
Missing defines
We took the number as 15
Although I'm getting the correct answer at bottom, still why this errors?
Please execute the below statement:
DECLARE
a NUMBER(5):=15;
BEGIN
a := a;
DBMS_OUTPUT.PUT_LINE('We took the number as ' || a);
END;
In order to get user input in PLSQL Block, we use &, &givenumber will get the user input at run time.
DECLARE
a NUMBER(5);
BEGIN
a := &givenumber;
DBMS_OUTPUT.PUT_LINE('We took the number as ' || a);
END;

Dynamic column name to record type variable

DECLARE
TYPE t IS RECORD (
col_name VARCHAR2 (100)
);
t_row t;
cname VARCHAR (100) := 'col_name';
BEGIN
t_row.col_name := 'col';
DBMS_OUTPUT.put_line ('out');
IF t_row.cname IS NULL THEN
DBMS_OUTPUT.put_line ('in');
END IF;
END;
Error at line 1
ORA-06550: line 12, column 12:
PLS-00302: component 'CNAME' must be declared
ORA-06550: line 12, column 3:
PL/SQL: Statement ignored
How can I assign dynamic column name to type variable of record?
You can do that with dynamic sql:
To make the example simpler I'll make your type t a schema object (but basically you don't have to - you can put it in the dynamic part as well)
create or replace type t is object(col_name varchar2(100));
/
Then you can look at this script:
declare
t_row t;
cname varchar2(100) := 'col_name';
begin
t_row := new t('col');
execute immediate 'declare t_in t := :0; begin if t_in.' || cname ||
' is null then dbms_output.put_line(''in''); end if; end;'
using t_row;
end;
Though, I must say, that this is a strange requirement ...
The error is because record t doesn't have a field cname, but col_name:
type t is record (
col_name varchar2(100)
);
One have to know record fields during compile time.
Could tell us what is the real problem you're going to solve ?

Resources