0
I have a PLSQL code: in which I receive two values one numerical and another varchar.
Code:
create or replace FUNCTION hospitalTeste123(MatriculaMedico in number, nomeSchema in varchar2 ) return varchar is
type Tmedicos is record(
matMedico nomeSchema.Tmedico.matricula%type,
especialidade nomeSchema.Tmedico.especialidade%type,
cd_setor nomeSchema.Tmedico.cd_setor%type
);
medico Tmedicos;
begin
medico.matMedico := 123;
medico.especialidade := 'geral';
medico.cd_setor := 'urgencia';
RETURN medico.MatMedico;
end;
Script for Creating Tables
create table TMedico(
matMedico number(10) NOT NULL,
especialidade varchar2(50) NOT NULL,
cd_setor varchar2(50) NOT NULL
);
insert into TMedico(matMedico,especialidade,cd_setor) Values (120,'clinico-geral','UTI');
insert into TMedico(matMedico,especialidade,cd_setor) Values (150,'cardiologista','UTI');
insert into TMedico(matMedico,especialidade,cd_setor) Values (180,'pediatria','UTI');
Error message:
PLS-00487: Invalid reference to Variabel 'chemName'
Error(3,3): PL/SQL: Item Ignored Error(4,19): PLS-00487: Invalid Reference to variable 'SCHEMNAME' Error(13,3): PL/SQL: Statement Ignored Error(13,10): PLS-00320: the declaration of the type of this Expression is incomplete or malformed Error(14,3): PL/SQL: Statement Ignored Error(14,10): PLS-00320: the declaration of the type of this Expression is incomplete or malformed Error(15,3): PL/SQL: Statement Ignored Error(15,10): PLS-00320: the declaration of the type of this Expression is incomplete or malformed Error(17,2): PL/SQL: Statement Ignored Error(17,16): PLS-00320: the declaration of the type of this Expression is incomplete or malformed
The error is when I pass the name of the schema in which the table is saved. Like every hospital has a different Schema.
Screenshot of the table with Schema
Calling the function
declare
begin
DBMS_OUTPUT.PUT_LINE(hospitalTeste123(123,'dbamv'));
end;
Error message:
Bug report - ORA-06550: row 4, column 24: PLS-00905: Object DBAMV.HOSPITALTESTE123 is invalid ORA-06550: row 4, column 3: PL/SQL: Statement Ignored 06550. 00000 - "line %s, column %s: n%s" *Cause: Usually a PL/SQL Compilation error. *Action:
The reference you are using to make this type, is it a valid table? Try to take the name of the schema and declare Tmedico.matricula%type
– Diego
Another thing, came to check if you have Grant in these tables?
– Diego
This valid. The point is that there is a schema for each hospital
– alexjosesilva
I do have permission to record in the tables
– alexjosesilva
The big question is to make this Generic process
– alexjosesilva
As each hospital has a schema and step it by reference, so each doctor can be registered in a different hospital
– alexjosesilva
I get it. The call would be correct, I think it’s something in releasing the schema access to the table
– Diego
Let’s go continue this discussion in chat.
– alexjosesilva
There is no OWNER named Schema on the server. There is?
– Reginaldo Rigo
The table exists. I posted the photo with her schema
– alexjosesilva
It is not possible to do this implementation by passing the Owner parameter in a varchar2, as oracle cannot guarantee that there will be these table definitions coming from a string, so it cannot compile. What you can do is create a global type on a User that all other users would have access Grant and use this type for their function, thus ensuring the necessary structure.
– Confundir
Could I give example of this implementation @Confuse ?
– alexjosesilva
@alexjosesilva, yes I can, but first get me one more question about the structure you’re working on. I understand you have the same table in each schema, but you want to access this same table in another schema, correct? It would no longer be feasible to have a "Template" schema with the definition of this table (since all need to be equal) and create the function in this same user?
– Confundir
A table however with different schemas. Your suggestion is welcome but I can not change the system. I found it like this.
– alexjosesilva
@Confound, I await your example.
– alexjosesilva