How can I fix this “SQL Statement ignored” error? [closed] - sql

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
I have the following small function that does not compile:
CREATE OR REPLACE PROCEDURE insertarVentas(ID NUMBER, IDCliente NUMBER, nombre VARCHAR2, calle VARCHAR2, poblacion VARCHAR2, cp NUMBER, provincia VARCHAR2, dni VARCHAR2,
telef1 VARCHAR2, telef2 VARCHAR2, telef3 VARCHAR2, fechaventa date, numerolinea NUMBER, IDProducto NUMBER, descripcion VARCHAR2, pvp NUMBER, stockactual NUMBER, cantidad NUMBER) AS
BEGIN
INSERT INTO TABLA_VENTAS VALUES (ID, TIP_CLIENTE(IDCliente, nombre, TIP_DIRECCION(calle, poblacion, cp, provincia), dni, TIP_TELEFONOS(telef1, telef2, telef3)), fechaventa,
TIP_LINEAS_VENTA(numerolinea, TIP_PRODUCTO(IDProducto, descripcion, pvp, stockactual), cantidad));
END insertarVentas;
The compiler gives me the following errors:
Error at line 4: PL/SQL: SQL Statement ignored
2. telef1 VARCHAR2, telef2 VARCHAR2, telef3 VARCHAR2, fechaventa date, numerolinea NUMBER, IDProducto NUMBER, descripcion VARCHAR2, pvp NUMBER, stockactual NUMBER, cantidad NUMBER) AS
3. BEGIN
4. INSERT INTO TABLA_VENTAS VALUES (ID, TIP_CLIENTE(IDCliente, nombre, TIP_DIRECCION(calle, poblacion, cp, provincia), dni, TIP_TELEFONOS(telef1, telef2, telef3)), fechaventa,
5. TIP_LINEAS_VENTA(numerolinea, TIP_PRODUCTO(IDProducto, descripcion, pvp, stockactual), cantidad));
6. END insertarVentas;
This is an insert into a object table, this is the code that table
CREATE TABLE TABLA_VENTAS OF TIP_VENTA(
IDVENTA PRIMARY KEY
)NESTED TABLE LINEAS STORE AS TABLA_LINEAS;
CREATE TYPE TIP_VENTA AS OBJECT(
IDVENTA NUMBER,
IDCLIENTE REF TIP_CLIENTE,
CREATE TYPE TIP_CIENTE AS OBJECT(
IDCLIENTE NUMBER,
NOMBRE VARCHAR2(50),
DIREC TIP_DIRECCION,
CREATE TYPE TIP_DIRECCION AS OBJECT(
CALLE VARCHAR2(50),
POBLACION VARCHAR2(50),
CODPOSTAL NUMBER(5),
PROVINCIA VARCHAR2(40)
);
NIF VARCHAR2(9),
TELEF TIP_TELEFONOS
CREATE TYPE TIP_TELEFONOS AS VARRAY(3) OF VARCHAR2(15);
);
FECHAVENTA DATE,
LINEAS TIP_LINEAS_VENTA,
CREATE TYPE TIP_LINEAVENTA AS OBJECT(
NUMEROLINEA NUMBER,
IDPRODUCTO REF TIP_PRODUCTO,
CREATE TYPE TIP_PRODUCTO AS OBJECT(
IDPRODUCTO NUMBER,
DESCRIPCION VARCHAR2(80),
PVP NUMBER,
STOCKACTUAL NUMBER
);
CANTIDAD NUMBER
);
CREATE TYPE TIP_LINEAS_VENTA AS TABLE OF TIP_LINEAVENTA;
);
What is causing this error and how can I fix it?

The PL/SQL: SQL Statement ignored message is usually just the top of the error stack and a following line will indicate what the actual issue is.
Having untangled your object creation statements and got them in an order that lets them all compile (and fixed at least one typo, and guess that a dangling comma was also a typo), creating your procedure gets:
LINE/COL ERROR
-------- ------------------------------------
4/1 PL/SQL: SQL Statement ignored
4/13 PL/SQL: ORA-00947: not enough values
You've defined TIP_VENTA with five fields:
CREATE TYPE TIP_VENTA AS OBJECT(
IDVENTA NUMBER,
IDCLIENTE REF TIP_CLIENTE,
FECHAVENTA DATE,
LINEAS TIP_LINEAS_VENTA,
CANTIDAD NUMBER
);
But the object you create during your insert only has four values (reformatted to make it a bit more readable):
INSERT INTO TABLA_VENTAS VALUES (
ID,
TIP_CLIENTE(
IDCliente,
nombre,
TIP_DIRECCION(calle, poblacion, cp, provincia),
dni,
TIP_TELEFONOS(telef1, telef2, telef3)
),
fechaventa,
TIP_LINEAS_VENTA(
numerolinea,
TIP_PRODUCTO(IDProducto, descripcion, pvp, stockactual),
cantidad
)
);
You've got cantidad inside the TIP_LINEAS_VENTA() constructor call, instead of after it:
INSERT INTO TABLA_VENTAS VALUES (
ID,
TIP_CLIENTE(
IDCliente,
nombre,
TIP_DIRECCION(calle, poblacion, cp, provincia),
dni,
TIP_TELEFONOS(telef1, telef2, telef3)
),
fechaventa,
TIP_LINEAS_VENTA(
numerolinea,
TIP_PRODUCTO(IDProducto, descripcion, pvp, stockactual)
),
cantidad
);
But that now gets:
LINE/COL ERROR
-------- ------------------------------------------------------------------
9/1 PL/SQL: SQL Statement ignored
20/5 PL/SQL: ORA-00932: inconsistent datatypes: expected UDT got NUMBER
The fourth field of the TIP_VENTA is type TIP_LINEAS_VENTA, so you need to have a TIP_LINEAVENTA within that table constructor:
TIP_LINEAS_VENTA(
TIP_LINEAVENTA(
numerolinea,
TIP_PRODUCTO(IDProducto, descripcion, pvp, stockactual)
)
Which then gets:
LINE/COL ERROR
-------- -----------------------------------------------------------------------------------------------------------------
9/1 PL/SQL: SQL Statement ignored
22/7 PL/SQL: ORA-00932: inconsistent datatypes: expected X.TIP_PRODUCTO got REF X.TIP_PRODUCTO
... because you're using actual objects instead of REFs to them, as the other type definitions expect. You'll need to decide whether to make them actual objects or fix the REFs...

I think the issue is that you're trying to insert into a table of an object something that isn't an object.
I've split out your object type populations into variables (rather than leaving them nested inside the insert statement as you did) which hopefully enables you to see what it is you're actually trying to insert:
create or replace procedure insertarventas (id number,
idcliente number,
nombre varchar2,
calle varchar2,
poblacion varchar2,
cp number,
provincia varchar2,
dni varchar2,
telef1 varchar2,
telef2 varchar2,
telef3 varchar2,
fechaventa date,
numerolinea number,
idproducto number,
descripcion varchar2,
pvp number,
stockactual number,
cantidad number)
as
v_tip_venta tip_venta;
v_tip_cliente tip_cliente;
v_tip_direccion tip_direccion;
v_tip_telefonos tip_telefonos;
v_tip_lineaventa tip_lineaventa;
v_tip_lineas_venta tip_lineas_venta;
v_tip_producto tip_producto;
begin
v_tip_direccion := tip_direccion (calle,
poblacion,
cp,
provincia);
v_tip_telefonos := tip_telefonos (telef1,
telef2,
telef3);
v_tip_cliente := tip_cliente (idcliente,
nombre,
v_tip_direccion,
dni,
v_tip_telefonos);
v_tip_producto := tip_producto (idproducto,
descripcion,
pvp,
stockactual);
v_tip_lineaventa := tip_lineaventa (numerolinea,
v_tip_producto,
cantidad);
v_tip_lineas_venta := tip_lineas_venta (v_tip_lineaventa);
-- this is the step you were missing
v_tip_venta := tip_venta (id,
v_tip_cliente,
fechaventa,
v_tip_lineas_venta);
insert into tabla_ventas
values (v_tip_venta);
end insertarventas;
/
N.B. untested.
Ok, the presence of the REFs in the object type descriptions is what is causing the problems. However, I don't think it's necessary to use REF (not to mention that I couldn't work out how to make the code work with them! *{;-) ), so here is a working test case without the REFs:
drop procedure insertarventas;
drop table tabla_ventas;
drop type tip_venta;
drop type tip_lineas_venta;
drop type tip_lineaventa;
drop type tip_producto;
drop type tip_cliente;
drop type tip_telefonos;
drop type tip_direccion;
create type tip_direccion as object (calle varchar2(50),
poblacion varchar2(50),
codpostal number(5),
provincia varchar2(40));
create type tip_telefonos as varray(3) of varchar2(15);
create type tip_cliente as object (idcliente number,
nombre varchar2(50),
direc tip_direccion,
nif varchar2(9),
telef tip_telefonos);
create type tip_producto as object (idproducto number,
descripcion varchar2(80),
pvp number,
stockactual number);
create type tip_lineaventa as object (numerolinea number,
idproducto tip_producto,
cantidad number);
create type tip_lineas_venta as table of tip_lineaventa;
create type tip_venta as object (idventa number,
idcliente tip_cliente,
fechaventa date,
lineas tip_lineas_venta);
create table tabla_ventas of tip_venta (idventa primary key)
nested table lineas store as tabla_lineas;
create or replace procedure insertarventas (id number,
idcliente number,
nombre varchar2,
calle varchar2,
poblacion varchar2,
cp number,
provincia varchar2,
dni varchar2,
telef1 varchar2,
telef2 varchar2,
telef3 varchar2,
fechaventa date,
numerolinea number,
idproducto number,
descripcion varchar2,
pvp number,
stockactual number,
cantidad number)
as
v_tip_venta tip_venta;
v_tip_cliente tip_cliente;
v_tip_direccion tip_direccion;
v_tip_telefonos tip_telefonos;
v_tip_lineaventa tip_lineaventa;
v_tip_lineas_venta tip_lineas_venta;
v_tip_producto tip_producto;
begin
v_tip_direccion := tip_direccion (calle,
poblacion,
cp,
provincia);
v_tip_telefonos := tip_telefonos (telef1,
telef2,
telef3);
v_tip_cliente := tip_cliente (idcliente,
nombre,
v_tip_direccion,
dni,
v_tip_telefonos);
v_tip_producto := tip_producto (idproducto,
descripcion,
pvp,
stockactual);
v_tip_lineaventa := tip_lineaventa (numerolinea,
v_tip_producto,
cantidad);
v_tip_lineas_venta := tip_lineas_venta (v_tip_lineaventa);
-- this is the step you were missing
v_tip_venta := tip_venta (id,
v_tip_cliente,
fechaventa,
v_tip_lineas_venta);
insert into tabla_ventas
values (v_tip_venta);
end insertarventas;
/

Related

Is it possible to set a constraint to a type attribute in Oracle PL/SQL?

I want to create a type with an attribute which should be expect three possible values. Something like following statement:
CREATE TYPE my_type AS OBJECT(
attrib1 VARCHAR2(30),
attrib2 VARCHAR2(30),
attrib3 VARCHAR2(30) -- this attribute should accept three possible values: val1, val2, or val3
);
Is there any way to do this, just like in the case of tables?
Thank you in advance.
You may use custom type constructor and perform this check inside PL/SQL code.
create type my_type as object(
attrib1 varchar2(30),
attrib2 varchar2(30),
attrib3 varchar2(30),
constructor function my_type (
attrib1 in varchar2,
attrib2 in varchar2,
attrib3 in varchar2
) return self as result
);
/
create type body my_type as
constructor function my_type (
attrib1 in varchar2,
attrib2 in varchar2,
attrib3 in varchar2
) return self as result
as
invalid_attr_value exception;
pragma exception_init(invalid_attr_value, -20001);
begin
if attrib3 not in ('val1', 'val2', 'val3') then
raise_application_error(-20001, 'Invalid attrib3 value supplied');
end if;
self.attrib1 := attrib1;
self.attrib2 := attrib2;
self.attrib3 := attrib3;
return;
end;
end;/
with a(col) as (
select my_type('a', 'b', 'val1')
from dual
)
select
a.col.attrib1,
a.col.attrib2,
a.col.attrib3
from a a
COL.ATTRIB1
COL.ATTRIB2
COL.ATTRIB3
a
b
val1
with a(col) as (
select my_type('a', 'b', 'val10')
from dual
)
select
a.col.attrib1,
a.col.attrib2,
a.col.attrib3
from a a
ORA-20001: Invalid attrib3 value supplied
ORA-06512: at "FIDDLE_INSFSVTZEJFLABZQAKDJ.MY_TYPE", line 12
fiddle
This is what you'd be happy with, but - unfortunately - it won't work:
SQL> create or replace type my_type as object
2 (attrib1 varchar2(30),
3 attrib2 varchar2(30),
4 attrib3 varchar2(30) check(attrib3 in ('A', 'B'))
5 );
6 /
create or replace type my_type as object
*
ERROR at line 1:
ORA-06545: PL/SQL: compilation error - compilation aborted
ORA-06550: line 4, column 23:
PLS-00103: Encountered the symbol "CHECK" when expecting one of the following:
:= ) , not null default external character
The symbol ":= was inserted before "CHECK" to continue.
ORA-06550: line 0, column 0:
PLS-00565: MY_TYPE must be completed as a potential REF target (object type)
Therefore, create the type as is ...
SQL> create or replace type my_type as object
2 (attrib1 varchar2(30),
3 attrib2 varchar2(30),
4 attrib3 varchar2(30)
5 );
6 /
Type created.
... and then apply check constraint on attrib3 while using that type in create table statement, e.g.
SQL> create table test of my_type
2 (attrib1 primary key,
3 attrib2 not null,
4 attrib3 default 'A' check (attrib3 in ('A', 'B'))
5 );
Table created.
SQL>
Is there any way to do this, just like in the case of tables?
No, you cannot apply a CHECK constraint to an OBJECT data-type.
From the CONSTRAINT documentation:
Constraint clauses can appear in the following statements:
CREATE TABLE (see CREATE TABLE)
ALTER TABLE (see ALTER TABLE)
CREATE VIEW (see CREATE VIEW)
ALTER VIEW (see ALTER VIEW)
So you cannot create a constraint in a CREATE TYPE or an ALTER TYPE statement.

How do I execute clob in execute immediate

I have a table with one row and clob as column (whose size is 5239). This column contains a table script extracted with the help of dbms_metadata.get_ddl. Along with table ddl it also extracts the primary key constraint and unique index script.
When I try to execute the script in my plsql block with execute immediate, it throws the following error:
ora-00922: missing or invalid option
Can somebody help me with what might be going wrong?
DECLARE lr_ddl CLOB;
BEGIN
SELECT TEXT INTO lr_ddl FROM DUMMY_1;
EXECUTE IMMEDIATE lr_nvm_ddl;
EXCEPTION WHEN OTHERS
THEN raise_application_error(-20001, chr(10)||' Failed ' || SQLERRM);
END;
Below is the script that I have in clob and I am trying to execute with execute immediate in my anonymous block.
CREATE TABLE abc_PROD.travel_hist
( travel_NO NUMBER NOT NULL ENABLE,
OBJECT_ID VARCHAR2(32) NOT NULL ENABLE,
flight_NO NUMBER,
LIFT_ACCOUNT VARCHAR2(32),
CARR_id VARCHAR2(32),
V_1 NUMBER,
V_2 NUMBER,
V_3 NUMBER,
V_4 NUMBER,
V_5 NUMBER,
V_6 NUMBER,
V_7 NUMBER,
V_8 NUMBER,
V_9 NUMBER,
V_10 NUMBER,
V_11 NUMBER,
V_12 NUMBER,
V_13 NUMBER,
V_14 NUMBER,
V_15 NUMBER,
V_16 NUMBER,
V_17 NUMBER,
V_18 NUMBER,
V_19 NUMBER,
V_20 NUMBER,
V_21 NUMBER,
V_22 NUMBER,
V_23 NUMBER,
V_24 NUMBER,
V_25 NUMBER,
V_26 NUMBER,
V_27 NUMBER,
V_28 NUMBER,
V_29 NUMBER,
V_30 NUMBER,
T_1 VARCHAR2(16),
T_2 VARCHAR2(32),
T_3 VARCHAR2(240),
T_4 VARCHAR2(2000),
T_5 VARCHAR2(240),
T_6 VARCHAR2(240),
T_7 VARCHAR2(240),
T_8 VARCHAR2(240),
T_9 VARCHAR2(240),
T_10 VARCHAR2(240),
T_11 VARCHAR2(2000),
T_12 VARCHAR2(2000),
T_13 VARCHAR2(2000),
T_14 VARCHAR2(2000),
T_15 VARCHAR2(2000),
T_16 VARCHAR2(2000),
T_17 VARCHAR2(2000),
T_18 VARCHAR2(2000),
T_19 VARCHAR2(2000),
T_20 VARCHAR2(2000),
DATE_1 DATE,
DATE_2 DATE,
DATE_3 DATE,
DATE_4 DATE,
DATE_5 DATE,
DATE_6 DATE,
DATE_7 DATE
) ;
CREATE UNIQUE INDEX abc_PROD.PK_TRAVEL ON abc_PROD.travel_hist (travel_NO)
;
ALTER TABLE abc_PROD.travel_hist ADD CONSTRAINT PK_TRAVEL PRIMARY KEY (travel_NO)
USING INDEX abc_PROD.PK_TRAVEL ENABLE;
You could execute those commands one by one in a LOOP. Something like in the code here. I just printed the commands, but you could execute them:
SET SERVEROUTPUT ON
DECLARE
mySQL VarChar2(8000);
mySQLexecute VarChar2(8000);
BEGIN
SELECT TEXT INTO mySQL FROM DUMMY_1;
--
WHILE InStr(mySQL, ';') > 0 LOOP
mySQLexecute := SubStr(mySQL, 1, INSTR(mySQL, ';'));
-- OR mySQLexecute := SubStr(mySQL, 1, INSTR(mySQL, ';')-1); if you want a command without semicolon (;)
DBMS_OUTPUT.PUT_LINE(mySQLexecute);
--EXECUTE IMMEDIATE mySQLexecute;
mySQL := SubStr(mySQL, INSTR(mySQL, ';') + 1);
END LOOP;
EXCEPTION WHEN OTHERS THEN
raise_application_error (-20001, chr(10)||' Failed ' || SQLERRM);
END;

When I compile the package-procedure in oracle, i get error message ' success with compilation error' How to fix the problem?

I am using Apex Oracle online workspace for my final database assignment. I already created a table 'volunteer'. Now I need to insert data into the table using pl-sql procedure statements.
When I try to run this code -
CREATE OR REPLACE PACKAGE pkgVolunteer
AS PROCEDURE uspaddVolunteer(varvl_ID NUMBER, varvl_type NUMBER,
varName VARCHAR2, varAge NUMBER, varGenger VARCHAR2,
varBirthDateVARCHAR2, varPhone NUMBER, varEmail VARCHAR2,
varFaculty VARCHAR2, varCourse VARCHAR2, varYear NUMBER,
varcountry VARCHAR2, varCity VARCHAR2 varstreet VARCHAR2,
varPostCode VARCHAR2);
END pkgVolunteer;
--
CREATE OR REPLACE PACKAGE BODY pkgVolunteer
AS PROCEDURE uspaddVolunteer(varvl_ID NUMBER, varvl_type NUMBER, varName
VARCHAR2, varAge NUMBER, varGenger VARCHAR2, varBirthDate VARCHAR2,
varPhone NUMBER, varEmail VARCHAR2, varFaculty VARCHAR2,
varCourse VARCHAR2, varYear NUMBER, varcountry VARCHAR2,
varCity VARCHAR2, varstreet VARCHAR2, varPostCode VARCHAR2)
IS
BEGIN INSERT INTO Volunteer(vl_id, vl_type, name, age, gender, birth_date,
phone, email, faculty, course, year,addr_country, addr_city,
addr_street, addr_postcode)
VALUE(varvl_ID, varvl_type, varName, varAge, varGenger, vBirthDate,
varPhone, varEmail, varFaculty, varCourse, varYear, varcountry,
varCity, varstreet, varPostCode);
END uspaddVolunteer;
--
BEGIN pkgVolunteer.uspaddVolunteer('vl34322343', 1, 'Jack smith', 23
'Male','02/20/1994', 07400323321, 'jacksmith.example#gmail.com', '',
'Bsc IT', 2, 'United Kingdom', 'London', '42 Hill street', 'EC329RU');
END;
I get error 'ORA-24344: success with compilation error'.
Also here is the sql statement for creating the table -
CREATE TABLE volunteer
(vl_id VARCHAR2(10) NOT NULL, vl_type NUMBER,
name VARCHAR2(50), age NUMBER, gender VARCHAR2(6),
birth_date VARCHAR2(10), phone NUMBER, email VARCHAR2(30),
faculty VARCHAR2(50), course VARCHAR2(50), year NUMBER,
addr_country VARCHAR2(30), addr_city VARCHAR2(50),
addr_street VARCHAR2(50), addr_postcode VARCHAR2(7),
CONSTRAINT pk_volunteer PRIMARY KEY (vl_id));
I tried checking for syntax errors, but could not find any errors. Could someone help me fix the problem?
Try the below , check my comments :
CREATE OR REPLACE PACKAGE pkgVolunteer AS
PROCEDURE uspaddVolunteer(varvl_ID NUMBER,
varvl_type NUMBER,
varName VARCHAR2,
varAge NUMBER,
varGenger VARCHAR2,
varBirthDate VARCHAR2,-- here needs space
varPhone NUMBER,
varEmail VARCHAR2,
varFaculty VARCHAR2,
varCourse VARCHAR2,
varYear NUMBER,
varcountry VARCHAR2,
varCity VARCHAR2 , --> needs comma
varstreet VARCHAR2,
varPostCode VARCHAR2);
END pkgVolunteer;
/
CREATE OR REPLACE PACKAGE BODY pkgVolunteer AS
PROCEDURE uspaddVolunteer(varvl_ID NUMBER, varvl_type NUMBER, varName VARCHAR2, varAge NUMBER, varGenger VARCHAR2, varBirthDate VARCHAR2, varPhone NUMBER, varEmail VARCHAR2, varFaculty VARCHAR2, varCourse VARCHAR2, varYear NUMBER, varcountry VARCHAR2, varCity VARCHAR2, varstreet VARCHAR2, varPostCode VARCHAR2) IS
BEGIN
INSERT INTO Volunteer
(vl_id,
vl_type,
name,
age,
gender,
birth_date,
phone,
email,
faculty,
course,
year,
addr_country,
addr_city,
addr_street,
addr_postcode) VALUEs --> needs s
(varvl_ID,
varvl_type,
varName,
varAge,
varGenger,
vBirthDate,
varPhone,
varEmail,
varFaculty,
varCourse,
varYear,
varcountry,
varCity,
varstreet,
varPostCode);
END;
end; -- add another END;
/

PLS-00103: Encountered the symbol "/"

The error I am receiving depends on whether I remove the "/" or leave it.
With /:
PLS-00103: Encountered the symbol /
Without /:
PLS-00103: Encountered the symbol CREATE
What am I doing wrong?
CREATE OR REPLACE PACKAGE EMP_PACKAGE AS
TYPE EMP_TYPE IS RECORD
( /* Employee Type */
employee_id NUMBER(6,0),
first_name VARCHAR2(20),
last_name VARCHAR2(25),
email VARCHAR2(25),
phone_number VARCHAR2(20),
hire_date DATE,
job_id VARCHAR2(10),
salary NUMBER(6,2),
commission_pct NUMBER(2,2),
manager_id NUMBER(6,0),
department_id NUMBER(4,0)
);
PROCEDURE add_emp(employee_id NUMBER);
PROCEDURE edit_first_name(employee_id NUMBER, first_name employees.first_name%TYPE);
FUNCTION get_emp(employee_id NUMBER) RETURN employee_id;
END;
/
CREATE OR REPLACE PACKAGE BODY EMP_PACKAGE AS
-- procedure will edit an employee's first name
PROCEDURE edit_first_name(employee_id NUMBER) IS
BEGIN
INSERT INTO employees (employees.first_name)
VALUES (first_name);
END edit_first_name;
END;
/
In the package specification you have the line:
FUNCTION get_emp(employee_id NUMBER) RETURN employee_id;
employee_id is not a valid data type.
Once you change that to a valid type then you get to the errors in the package body:
You are missing the ADD_EMP procedure and GET_EMP function.
PROCEDURE edit_first_name(employee_id NUMBER) does not match the declaration in the package specification as its missing the first_name employees.first_name%TYPE argument.
In INSERT INTO employees (employees.first_name) VALUES (first_name); the column is first_name not employees.first_name.
you have some errors in your code.
maybe you need something this?
i compile this in sql developer without any errors
create or replace PACKAGE EMP_PACKAGE AS
TYPE EMP_TYPE IS RECORD
( /* Employee Type */
employee_id NUMBER(6,0),
first_name VARCHAR2(20),
last_name VARCHAR2(25),
email VARCHAR2(25),
phone_number VARCHAR2(20),
hire_date DATE,
job_id VARCHAR2(10),
salary NUMBER(6,2),
commission_pct NUMBER(2,2),
manager_id NUMBER(6,0),
department_id NUMBER(4,0)
);
PROCEDURE add_emp(p_employee_id NUMBER);
PROCEDURE edit_first_name(p_employee_id NUMBER, p_first_name employees.first_name%TYPE);
FUNCTION get_emp(p_employee_id NUMBER) RETURN EMP_TYPE;
END;
/
create or replace PACKAGE BODY EMP_PACKAGE AS
-- procedure will edit an employee's first name
PROCEDURE edit_first_name(p_employee_id NUMBER, p_first_name employees.first_name%TYPE) IS
BEGIN
update employees emp
set emp.first_name = p_first_name
where emp.employee_id = p_employee_id;
END edit_first_name;
PROCEDURE add_emp(p_employee_id NUMBER) IS BEGIN
null;
END;
FUNCTION get_emp(p_employee_id NUMBER) RETURN EMP_TYPE IS
BEGIN
return null;
END;
END;

error- column not allowed here & too many values upon insert

I have this new problem after creating the Subscriber table of Subscriber_T type and its function i cant seem to insert any value in Subscrber table. The error, i keep getting is column not allowed here. But where???
These are the scripts and an insert record.
CREATE OR REPLACE TYPE Surnames_T AS OBJECT (
Surname varchar (20)
);
/
CREATE OR REPLACE TYPE listSurnames_T
AS Varray(4) of Surnames_T;
/
CREATE OR REPLACE TYPE listTels as object(
Tel number (12)
);
/
CREATE OR REPLACE TYPE listTels_T as Varray(5) of listTels;
/
CREATE OR REPLACE TYPE ADDRESS_T AS OBJECT (
NUM number (6),
STREET varchar (20),
TOWN varchar (20)
);
/
CREATE or replace type TAddress
as table of Address_T;
/
create or replace type Subscriber_T as object(
num_s number(6),
sName varchar(30),
surname listSurnames_T,
Adds TAddress,
DateOfBirth date,
phoneNo listTels_T,
member function Age return number
);
/
create table Subscribers of Subscriber_T(
CONSTRAINT subscriber_pk primary key (num_s)
)
nested table Adds store as Tab_Adds;
/
show errors
create or replace type body Subscriber_T as
member function Age return number is
calc_age number;
dob date;
diff date;
begin
select S.dateOfBirth into dob
from Subscribers S
where deref(S.num_s) = self
diff := sysdate - dob
calc_age := to_Char(diff, 'YYYY')
return cal_age;
end;
end;
/
show errors
insert into Subscribers values (34, Chloe, listSurnames_T(Surnames_T('Dave'), Surnames_T('Camille'), Surnames_T('Jones')),
TAddress(Address_T(10, 'ave Foch', 'Ravenwood'), Address_T(30, 'rue des pole', 'England')),
'10-11-1976',
listTels_T(listTels(5839550456), listTels(6834734567)));
I'm guessing the function is raising this problem but it shows no error on compilation.
Some issues:
You don't need to do a SELECT in the member function age.
You haven't quoted the name Chloe so its not a string.
You haven't converted the '10-11-1976' to a date.
You should not use VARCHAR as a datatype - use VARCHAR2 instead.
SQL Fiddle
Oracle 11g R2 Schema Setup:
CREATE OR REPLACE TYPE Surnames_T AS OBJECT (
Surname varchar2 (20)
)
/
CREATE OR REPLACE TYPE listSurnames_T
AS Varray(4) of Surnames_T
/
CREATE OR REPLACE TYPE listTels as object(
Tel number (12)
)
/
CREATE OR REPLACE TYPE listTels_T as Varray(5) of listTels
/
CREATE OR REPLACE TYPE ADDRESS_T AS OBJECT (
NUM number (6),
STREET varchar2 (20),
TOWN varchar2 (20)
)
/
CREATE or replace type TAddress as table of Address_T
/
create or replace type Subscriber_T as object(
num_s number(6),
sName varchar2(30),
surname listSurnames_T,
Adds TAddress,
DateOfBirth date,
phoneNo listTels_T,
member function Age return number
)
/
create or replace type body Subscriber_T as
member function Age return number is
begin
return FLOOR( MONTHS_BETWEEN( SYSDATE, self.DateOfBirth )/12 );
end;
end;
/
create table Subscribers of Subscriber_T(
CONSTRAINT subscriber_pk primary key (num_s)
)
nested table Adds store as Tab_Adds
/
insert into Subscribers values (
34,
'Chloe',
listSurnames_T(
Surnames_T('Dave'),
Surnames_T('Camille'),
Surnames_T('Jones')
),
TAddress(
Address_T(10, 'ave Foch', 'Ravenwood'),
Address_T(30, 'rue des pole', 'England')
),
TO_DATE( '10-11-1976', 'DD-MM-YYYY' ),
listTels_T(
listTels(5839550456),
listTels(6834734567)
)
)
/
Query 1:
SELECT s.age() FROM subscribers s
Results:
| S.AGE() |
|---------|
| 37 |
Edit
I'm not sure why you are wrapping a VARCHAR2 in the Surnames_T type or a NUMBER in the ListTels type. You can omit these and just do:
CREATE OR REPLACE TYPE listSurnames_T
AS Varray(4) of VARCHAR2(20)
/
CREATE OR REPLACE TYPE listTels_T as Varray(5) of NUMBER(12)
/
and:
insert into Subscribers values (
34,
'Chloe',
listSurnames_T(
'Dave',
'Camille',
'Jones'
),
TAddress(
Address_T(10, 'ave Foch', 'Ravenwood'),
Address_T(30, 'rue des pole', 'England')
),
TO_DATE( '10-11-1976', 'DD-MM-YYYY' ),
listTels_T(
5839550456,
6834734567
)
)
/