Plsql directives schema name
Hi,
Is it possible to get the schema name of a package easily, just like you could use $$PLSQL_UNIT for the package name?
Thanks,
Jan
Assuming you have a definer rights package (not invoker rights) and you want to get the package owner (not the user who called the package), then you can simply:
select username from user_users;You can use package variable and package initialization section:
CREATE OR REPLACE PACKAGE BODY mypkg AS
g_schemaowner user_users.username%TYPE;
-- your functions and procedures here
BEGIN
SELECT username INTO g_schemaowner FROM user_users;
END;
/
Similar Messages
-
hi there,
who knows how to cheat a little and add schema name dynamically in report query?
curently trying PLSQL function body returning SQL
...from ' || '&P1_SCHEMA.' ||'.IM_INVOICES_V
where...
any bright thoughts?
crazy SimonHi,
You could try something like this...
CREATE OR REPLACE FORCE VIEW IM_INVOICES_V_VW AS
SELECT 'SCHEMA_1'.the_schema,
IM_INVOICES_V.*
FROM schema1.IM_INVOICES_V
UNION ALL
SELECT 'SCHEMA_2'.the_schema,
IM_INVOICES_V.*
FROM schema2.IM_INVOICES_V;
and then...
SELECT *
FROM IM_INVOICES_V_VW
WHERE the_schema = :P1_SCHEMA
AND ...Cheers
Ben -
JCA SOA 11g - PLSQL bounded to Name of Parameters
Hi
I am calling a PLSQL package using JCA in BPEL11g. When i create the JCA, i have to connected to the DB and selected the package. As a result i have the XSD and WSDL for the same in terms of In and Out parameters. But when i change the "name" of IN & OUT parameters (Not the type or sequence of parameters) in the PLSQL package, BPEL throws the error as "Wrong number or type of parameters" while executing.
In Java , we use registerOutParameters for all the OUT parameters by their type and sequence & we never need to know the name of the parameter. But why JCA is bounded to the "name" of the IN/OUT parameters.? Do we have any workaround to handle this situation?
Since BES (which is PLSQL package provider) need not share the name of their internal variables (say IN/OUT parameter names, they will share the type and sequence of IN/OUT parameters) to the consumers( BPEL).
Please help me here on this.
Thanks
SeshaPrabhu,
I totally agree that the XSD names should be matching to the PLSQL package IN and OUT parameter names. But in my case as i interact to a remote PLSQL package for which the details given to me are just the Package name , Procedure name , schema name & DB Type of IN/OUT parameters along with the sequence of them.
Since BES have rights to change the name of IN/OUT parameters since those are internal variables of the package/procedure . Is there any means that - based on type and sequence to make a PLSQL call to BES ?
thanks
Sesha
Edited by: Sesha on Aug 16, 2010 5:19 PM -
Schema name stripped out in apex
I can get the results in SQLPlus with following query (same user as apex)but if, for example, I try and run the query below within apex I get the following error
select T_SEQ_ID, ALIGNMENT_LENGTH,
Q_SEQ_START, Q_SEQ_END, Q_FRAME, T_SEQ_START,
T_SEQ_END, T_FRAME, score, EXPECT as evalue
from TABLE(BLASTP_ALIGN (
'MHPKVDALLSRFPRITLIPWETPIQYLPRISRELGVDVYVKRDDLTGLGIGGNKIRKLEFLLGDALSRGCDTVIT
IGAVH',
CURSOR(SELECT seq_id, seq_data
FROM swissprot),
1,
-1,
0,
0,
'BLOSUM62',
10,
0,
0,
3,
0,
0)) t
where t.score > 25;
ORA-22303: type ""."DMBGOS" not found
I checked that DMBGOS is a valid type within the DMSYS schema. It seems the schema name gets stripping out in apex for some reason. Can someone take a close look at it?
Thanks,
Ke LinHello,
How did you grant privileges on BLASTP_ALIGN etc to the user? Was it via a role perhaps? (That won't work in APEX, it needs to be a direct grant).
John
Blog: http://jes.blogs.shellprompt.net
Work: http://www.apex-evangelists.com
Author of Pro Application Express: http://tinyurl.com/3gu7cd
REWARDS: Please remember to mark helpful or correct posts on the forum, not just for my answers but for everyone! -
How to Get the schema name that contains the current procedure?
I have try select sys_context( 'userenv', 'current_schema' ) from dual; but it returns the schema name of the login user. How to return the schema name of the procedure instead? For example, procedure A is in ControlDB, and I login as sys, when query procedure A it should return ControlDB instead of sys.
I have searched in Google but no luck to find the answer so far, please help. Thank youIt works!
I am quite confused now. I did try to use select username from user_users in GetSchemaName procedure, but it always return the login user instead of the owner of the procedure. Why it return the procedure owner if I put the query inside a function then call it from the procedure?
Is it because when the login user call the procedure and the procedure call the function, it's the procedure owner is calling the function so the user_users return the user that is calling it which is the procedure owner. And if the query is directly put inside the procedure, when the login user call the procedure, user_users return the login user directly? Does it imply that if the procedure call any function or other procedures etc, it would be the procedure's owner calling them instead of the login user?
(sys_context works as well if I move the query into the function then call the function from the procedure)
Cheers
Message was edited by:
user500168 -
Parse schema name - Avoiding hard-coded schema names
Hi all,
I have been trying to find a similar thread but had no luck. I want to avoid hard-coding schema names in my reports. I have tried to use a Substitution string but I don't seem to be able to reference it by just doing :default_schema. I already reference the parsing schema like this: #OWNER# which is saving me a lot of time. Is there any way to create additional variables like that one instead of those substitution strings that can't be parsed in a query?
Thanks a lot for your help.
Regards,
werot.Werot wrote:
I have been trying to find a similar thread but had no luck. I want to avoid hard-coding schema names in my reports. I have tried to use a Substitution string but I don't seem to be able to reference it by just doing :default_schema. I already reference the parsing schema like this: #OWNER# which is saving me a lot of time. Is there any way to create additional variables like that one instead of those substitution strings that can't be parsed in a query?
Will you actually get any benefit from using substitution strings? They are also hard-coded at design time. You could use application items if you need something dynamic.
Bind variable syntax (:default_schema) will not work for lexical substitution of substitution string and application item values in report queries. You have to use static text (&DEFAULT_SCHEMA.) references (and be aware of the potential for SQL injection that this exposes).
I wouldn't recommend using schema qualifiers directly in APEX applications. I would use grants, synonyms and views at the database level. -
Passing a Schema Name to a Procedure
Hi,
I'm hoping there's a really simple answer to this...
We have an Oracle database containing many schemata, all customer schemata are identical but hold different data pertaining to each customer.
We also have a 'reporting' schema which has select privileges on all the other schemata.
In this reporting schema we have various ref cursor returning procedures, and we use dot notation to reference the required schema - E.g. 'select * from SCHEMA1.Customers'.
What I'd like to do is pass a schema name as a parameter to a procedure so the one procedure could cover all schemata. - E.g. call p_GetCustomers('SchemaNameParameter'). The procedure would then return the customer data for a given schema.
All I've come up with (thus far) is using EXECUTE IMMEDIATE.
E.g. (very simplified)
create or replace procedure p_GetCustomers(pSchema in varchar2) as
vExecuteString varchar2(100);
begin
vExecuteString := 'select * from '|| pSchema ||'.ICustomers';
execute immediate vExecuteString ;
end;
This does the job in extremely simple procedures/functions, but we have some heavy-duty procedures that would make it extremely hard to do the concatenation as they mention the schema all over the place.
What I'd ideally like is something like...
create or replace procedure p_GetCustomers(pSchema in varchar2) as
begin
select * from pSchema.Customers;
end;
But the above won't compile (table or view does not exist...).
I'd be extremely grateful if somebody could advise on this...
Thanking you in advance (and hope!)...
Mike
Oracle 10.g - Windows - Oracle SQL Developer 1.1.2The owner of the procedure needs to have the ALTER SESSION system privilege granted directly to them, but that is all. The SET CURRENT_SCHEMA <name> just defines the namespace to look in, it does not make you that user. The reporting user (presumably the procedure owner) still needs to have SELECT privileges on all of the tables.
SQL> show user
USER is "OPS$ORACLE"
SQL> CREATE USER a IDENTIFIED BY a;
User created.
SQL> GRANT CREATE SESSION, ALTER SESSION to a;
Grant succeeded.
SQL> CREATE TABLE t (id NUMBER, descr VARCHAR2(10));
Table created.
SQL> INSERT INTO t VALUES (1, 'OP$ORACLE');
1 row created.
SQL> COMMIT;
Commit complete.
SQL> GRANT SELECT ON t TO a;
Grant succeeded.
SQL> connect mpprod/********
Connected.
SQL> CREATE TABLE t (id NUMBER, descr VARCHAR2(10));
Table created.
SQL> INSERT INTO t VALUES (1, 'MPPROD');
1 row created.
SQL> COMMIT;
Commit complete.
SQL> GRANT SELECT ON t TO a;
Grant succeeded.
SQL> connect a/a
Connected.
SQL> ALTER SESSION SET CURRENT_SCHEMA = ops$oracle;
Session altered.
SQL> SELECT * FROM t;
ID DESCR
1 OP$ORACLE
SQL> ALTER SESSION SET CURRENT_SCHEMA = mpprod;
Session altered.
SQL> SELECT * FROM t;
ID DESCR
1 MPPRODJohn -
Any Function module or BAPIs are available to get scheme name for the inter
I have internal order no value in table AUFK-AUFNR , and the internal order corresponding Scheme value is available in IMPR-PRNAM . Now I want to inner join both the tables to extract the data , but there is no common field . Is there any Function module or BAPIs are available to get scheme name for the internal orders?
look at DB-VIEW "V_IVP_OR".
Regards,
Laurent -
How to configure the schema name dynamically based on user input.
configure the schema name dynamically based on user input.
For ex:
We have two schemas:
Schema1 - base schema having 15 tables.
Schema2 - tables which is specific to modules. Having only 10 tables which is also available in Schema1
Login to application using Schema 1
Access a particlular module and select the country. Here country selection is identified.
Based on the country selection, we need to connect the schema respectively.
If the user selects France --> It should connect Schema1
If the user selects Germeny --> It should connect schema2.
Used: EclipselinkYou may want to have a different persistence unit for each country, then you just need to switch persistence units, and can put the schema in your orm.xml file.
You may also want to investigate EclipseLink multi-tenant support,
http://www.eclipse.org/eclipselink/documentation/2.5/jpa/extensions/a_multitenant.htm
You can the schema in a persistence unit in code using a SessionCustomizer and the tableQualifier. -
How to get the current schema name
Hi,
Can anybody please tell me how to get the current schema name, there is some inbuilt function for this,but i am not getting that. Please help me.
Thanks
Jogeshok folks, I found the answer at Tom's as usual.
http://asktom.oracle.com/tkyte/who_called_me/index.html
I rewrote it into a function for kicks. just pass the results of DBMS_UTILITY.FORMAT_CALL_STACK to this function and you will get back the owner of the code making the call as well some extra goodies like the name of the code and the type of code depending on the parameter. This ignores the AUTHID CURRENT_USER issues which muddles the schemaid. Quick question, does the average user always have access to DBMS_UTILITY.FORMAT_CALL_STACK or does this get locked down on some systems?
cheers,
paul
create or replace
FUNCTION SELF_EXAM (
p_call_stack VARCHAR2,
p_type VARCHAR2 DEFAULT 'SCHEMA'
) RETURN VARCHAR2
AS
str_stack VARCHAR2(4000);
int_n PLS_INTEGER;
str_line VARCHAR2(255);
found_stack BOOLEAN DEFAULT FALSE;
int_cnt PLS_INTEGER := 0;
str_caller VARCHAR2(30);
str_name VARCHAR2(30);
str_owner VARCHAR2(30);
str_type VARCHAR2(30);
BEGIN
str_stack := p_call_stack;
-- Loop through each line of the call stack
LOOP
int_n := INSTR( str_stack, chr(10) );
EXIT WHEN int_cnt = 3 OR int_n IS NULL OR int_n = 0;
-- get the line
str_line := SUBSTR( str_stack, 1, int_n - 1 );
-- remove the line from the stack str
str_stack := substr( str_stack, int_n + 1 );
IF NOT found_stack
THEN
IF str_line like '%handle%number%name%'
THEN
found_stack := TRUE;
END IF;
ELSE
int_cnt := int_cnt + 1;
-- cnt = 1 is ME
-- cnt = 2 is MY Caller
-- cnt = 3 is Their Caller
IF int_cnt = 1
THEN
str_line := SUBSTR( str_line, 22 );
dbms_output.put_line('->' || str_line);
IF str_line LIKE 'pr%'
THEN
int_n := LENGTH('procedure ');
ELSIF str_line LIKE 'fun%'
THEN
int_n := LENGTH('function ');
ELSIF str_line LIKE 'package body%'
THEN
int_n := LENGTH('package body ');
ELSIF str_line LIKE 'pack%'
THEN
int_n := LENGTH('package ');
ELSIF str_line LIKE 'anonymous%'
THEN
int_n := LENGTH('anonymous block ');
ELSE
int_n := null;
END IF;
IF int_n IS NOT NULL
THEN
str_type := LTRIM(RTRIM(UPPER(SUBSTR( str_line, 1, int_n - 1 ))));
ELSE
str_type := 'TRIGGER';
END IF;
str_line := SUBSTR( str_line, NVL(int_n,1) );
int_n := INSTR( str_line, '.' );
str_owner := LTRIM(RTRIM(SUBSTR( str_line, 1, int_n - 1 )));
str_name := LTRIM(RTRIM(SUBSTR( str_line, int_n + 1 )));
END IF;
END IF;
END LOOP;
IF UPPER(p_type) = 'NAME'
THEN
RETURN str_name;
ELSIF UPPER(p_type) = 'SCHEMA.NAME'
OR UPPER(p_type) = 'OWNER.NAME'
THEN
RETURN str_owner || '.' || str_name;
ELSIF UPPER(p_type) = 'TYPE'
THEN
RETURN str_type;
ELSE
RETURN str_owner;
END IF;
END SELF_EXAM; -
Schema name not present on filename for "Save Package Spec and Body"
In versions previous to 3.0 EA, the filename defaulted to schema.object.sql when using the "Save Package Spec and Body" on the right click of the package/body. This appears to have disappeared. Also, it now defaults to the .PLS ext/type, which I prefer to save them as .SQL (which i can override, but it would be nice in the file type dropdown). Also, I had posted a suggestion about the actual file not including the schema name prefixing the object name when using the "Save Package Spec and Body". i.e. it does create or replace package reader_package instead of what it should be doing which is create or replace package schema.reader_package
Would be nice indeed having the real name as default, and all supported PL/SQL types (as in the preferences) in the extensions dropdown.
As for the schema name inside, I reckon that would do damage for more users than it would do good for others. But a preference would be best of course.
K. -
Using dbms_datapump package to export the schema with the schema name as pa
Hi,
I am using the pl/sql block to export schema using dbms_datapump package,Now I want to pass the scheme name as the parameter to the procedure and get the .dmp and .log files with the schema name included.
CREATE OR REPLACE PROCEDURE export
IS
h1 number;
begin
h1 := dbms_datapump.open (operation => 'EXPORT', job_mode => 'SCHEMA', job_name => 'export1', version => 'COMPATIBLE');
dbms_datapump.set_parallel(handle => h1, degree => 1);
dbms_datapump.add_file(handle => h1, filename => 'EXPDAT.LOG', directory => 'DATA_PUMP_DIR', filetype => 3);
dbms_datapump.set_parameter(handle => h1, name => 'KEEP_MASTER', value => 0);
dbms_datapump.metadata_filter(handle => h1, name => 'SCHEMA_EXPR', value => 'IN(''CHECKOUT'')');
dbms_datapump.set_parameter(handle => h1, name => 'ESTIMATE', value => 'BLOCKS');
dbms_datapump.add_file(handle => h1, filename => 'EXPDAT%U' || to_char(sysdate,'dd-mm-yyyy') || '.DMP', directory => 'DATA_PUMP_DIR', filetype => 1);
dbms_datapump.set_parameter(handle => h1, name => 'INCLUDE_METADATA', value => 1);
dbms_datapump.set_parameter(handle => h1, name => 'DATA_ACCESS_METHOD', value => 'AUTOMATIC');
dbms_datapump.start_job(handle => h1, skip_current => 0, abort_step => 0);
dbms_datapump.detach (handle => h1);
exception
when others then
raise_application_error(-20001,'An error was encountered - '||SQLCODE||' -ERROR- '||SQLERRM);
end;
Thank you in advanced
Sriuser12062360 wrote:
Hi,
I am using the pl/sql block to export schema using dbms_datapump package,Now I want to pass the scheme name as the parameter to the procedure and get the .dmp and .log files with the schema name included.
OK, please proceed to do so
>
CREATE OR REPLACE PROCEDURE export
IS
h1 number;
begin
h1 := dbms_datapump.open (operation => 'EXPORT', job_mode => 'SCHEMA', job_name => 'export1', version => 'COMPATIBLE');
dbms_datapump.set_parallel(handle => h1, degree => 1);
dbms_datapump.add_file(handle => h1, filename => 'EXPDAT.LOG', directory => 'DATA_PUMP_DIR', filetype => 3);
dbms_datapump.set_parameter(handle => h1, name => 'KEEP_MASTER', value => 0);
dbms_datapump.metadata_filter(handle => h1, name => 'SCHEMA_EXPR', value => 'IN(''CHECKOUT'')');
dbms_datapump.set_parameter(handle => h1, name => 'ESTIMATE', value => 'BLOCKS');
dbms_datapump.add_file(handle => h1, filename => 'EXPDAT%U' || to_char(sysdate,'dd-mm-yyyy') || '.DMP', directory => 'DATA_PUMP_DIR', filetype => 1);
dbms_datapump.set_parameter(handle => h1, name => 'INCLUDE_METADATA', value => 1);
dbms_datapump.set_parameter(handle => h1, name => 'DATA_ACCESS_METHOD', value => 'AUTOMATIC');
dbms_datapump.start_job(handle => h1, skip_current => 0, abort_step => 0);
dbms_datapump.detach (handle => h1);
exception
when others then
raise_application_error(-20001,'An error was encountered - '||SQLCODE||' -ERROR- '||SQLERRM);
end;
EXCEPTION handler is a bug waiting to happen.
eliminate it entirely -
Function not found when package name exists with same name as schema name
Hi all, any help would be appreciated :)
I found an issue with pl/sql resolving a functions location when the db has a package name with the same as the db schema name.
My example:
-- arbitrary test function, not in any package
create or replace FUNCTION testFunc
inTest IN VARCHAR2
RETURN VARCHAR2
AS
BEGIN
RETURN 'a';
END;
-- There is a package called "FM" with functions that are not referenced or used in this example and the db schema is "FM".
-- The following PL/SQL fails with the message: "ORA-00904: "FM"."TESTFUNC": invalid identifier"
select cursor (select testFunc('a') from dual) from dual;
-- The following PL/SQL works:
select * from (select testFunc('a') from dual);
As mentioned the function testFunc is NOT in the FM package. This issue does not happen when I remove the FM package. So it seems like there is an issue with cursors calling functions when there exists any package with the same name as the db schema.
Can anyone tell me why this happens and also what I can add to force the function that is not in any package to be referenced (without Oracle trying to look in the FM package)?
DB: Oracle 11.2.0.2
thanks!
PaulHi Paul,
In general I would not advice to have schema and objects with the same name.
Here is what documentation is saying here: How Name Resolution Differs in PL/SQL and SQL
PL/SQL uses the same name-resolution rules as SQL when the PL/SQL compiler processes a SQL statement, such as a DML statement. For example, for a name such as HR.JOBS, SQL matches objects in the HR schema first, then packages, types, tables, and views in the current schema.
PL/SQL uses a different order to resolve names in PL/SQL statements such as assignments and subprogram calls. In the case of a name HR.JOBS, PL/SQL searches first for packages, types, tables, and views named HR in the current schema, then for objects in the HR schema.As you can see above when using PL/SQL for your case Oracle searches first for packages, types, tables, and views named FM in the current schema, then for objects in the FM schema.
And because a package FM is found it is raising an error due to the fact that the procedure could not be found in that package.
I hope this clarify.
Regards.
Al -
How to parameterize the schema name in APEX
Hi,
How to parameterize the schema name in APEX , in order to access different tables from the respective schema.
For example:-
select NAME display_value, CODE return_value
from paramSchema.DESC_LIST WHERE SELECTION_FLG = 'Y'
order by 1
in the above code, paramSchema will be replaced with the actual schema name duing runtime. I tried doing so by some hidden fields on page, but it didn't worked out.
I took the schema name from the respective server as per the IPof the server.
stored in a hidden field named as schema.
And replaced the same in place of schema name. But no luck.
select NAME display_value, CODE return_value
from :schema.DESC_LIST WHERE SELECTION_FLG = 'Y'
order by 1
Please help me in shorting it out.
Thanks,
AnuradhaHi
In order to do that, you would need to use dynamic SQL by changing the report type to PL/SQL Function Body Returning SQL Query and have code along the lines of
DECLARE
l_sql VARCHAR2(32767);
BEGIN
l_sql := 'select NAME display_value, CODE return_value
from '||:schema||'.DESC_LIST WHERE SELECTION_FLG = 'Y'
order by 1';
RETURN l_sql;
END;However, by doing this, you lose alot of flexibility. The other options would be...
To have seperate report regions that are conditional on the value of the variable.
To use a WITH clause at the tope of the query like...
WITH src_data AS
(SELECT * FROM schema1.my_table
WHERE :schema = 'schema1'
UNION ALL
SELECT * FROM schema2.my_table
WHERE :schema = 'schema2')
SELECT *
FROM src_dataOther than that you could look at using synonyms and doing something similar.
Hope this helps.
Cheers
Ben -
Need to include table name,schema name in select output
I need to output the table name and schema name of the current user into a table.. I have tried including
within a select statement..
table_name,
from user_tables
where table_name='mnme';
no rows returnedHi,
Its in upper case 'MNME'
Best.
EA
Maybe you are looking for
-
No apply button in import settings
unable to apply mp3 settings from the advanced page, tryed reloading 7.4.3 still having same problem cannot switch from acc to mp3
-
Has anyone else had this problem. This piece of code works fine: RowSet rs = new JdbcRowSetImpl(); rs.setDataSourceName("java:/comp/env/jdbc/ChemNetDB"); rs.setCommand("Select * from TBL_DISPLAY_FIELDS where DEFAULT_FIELD=1"); rs.execute(); this one
-
How do I get 12 hardware counter channels?
Hello, I am wanting to count 12 seperate pulse signals. The USB device I am currently using (6501) has only 1 counter channel that works great for one signal, but the extremely short pulses (@5us) makes software programming a nightmare for 12 signals
-
Oracle Buisness Intellegence Administration Tool/Multiple users
I am trying to have two people work together on a project on 1 server, both people are remoteing into the server. The built in administrator account can use the administration tool without any problems but any other user I create on the server level
-
Sales Order and Pick List reports will not attach to Email message
My client wants to email both the Sales Order and Pick List that is created from the Sales Order in the same email message. It appears that SAP B1 will not do this. Is this a bug or just the way B1 works. My client is running version 8.8 PL 19.