![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
|
PL/SQL - get DB name
Hey,
I want to get the database name in a PL/SQL trigger. At the SQLPlus prompt, these are some examples I've tried: fsdevl75@fsdev> select sys_context('userenv', 'db_name') from dual;
SYS_CONTEXT('USERENV','DB_NAME
---------------------------------------------------------------------------
13
fsdevl75@fsdev> select '&_CONNECT_IDENTIFIER' from dual;
old 1: select '&_CONNECT_IDENTIFIER' from dual
new 1: select 'fsdev' from dual
'FSDEV'
--------------------------------
fsdev
fsdevl75@fsdev> desc v$database;
ERROR:
ORA-04043: object "SYS"."V_$DATABASE" does not existI want what _CONNECT_IDENTIFIER returns (fsdev in this case), but I can't figure out any way to do this in a trigger. Can anybody help with this? |
|
|
|
|
|
#2 | |
|
Programming Guru
![]() ![]() |
Quote:
I would probably see if i could do a SELECT INTO into a var, then return the var (or do what ever you want with the results). here's a example on SELECT INTO: http://www.postgresql.org/docs/8.1/i...QL-SELECT-INTO
__________________
Profanity is the one language that all programmers understand. Check out my Blog <---updated Nov 30 2007! |
|
|
|
|
|
|
#3 | |
|
Newbie
|
Quote:
select '&_CONNECT_IDENTIFIER' into myVar from dual; On a side note, I can also do this: fsdevl75@fsdev> select * from PS.PSDBOWNER where ownerid = user; DBNAME OWNERID S ---------- ---------- - FSDEV FSDEVL75 U FSDEVL75 FSDEVL75 U fsdevl75@fsdev> |
|
|
|
|
|
|
#4 |
|
Programming Guru
![]() ![]() |
give this a try:
SELECT GLOBAL_NAME FROM GLOBAL_NAME; i have seen that on a few pages i have been reading about your subject. Here's the link to the page: http://www.bijoos.com/oracle/ora_qa.htm I have never used SQLPlus, so i am kinda in the dark on what works on your system.
__________________
Profanity is the one language that all programmers understand. Check out my Blog <---updated Nov 30 2007! |
|
|
|
|
|
#5 |
|
Hobbyist Programmer
Join Date: Jun 2005
Location: New Mexico
Posts: 228
Rep Power: 4
![]() |
SET SERVEROUT ON SIZE 10000
DECLARE
DBNAME VARCHAR2(32):=null;
BEGIN
SELECT name
INTO DBNAME
FROM v$database;
DBMS_OUTPUT.ENABLE;
DBMS_OUTPUT.PUT_LINE('DATABASE NAME = ' || DBNAME);
END;
/This is the basic code to get the db name - it displays it. For a trigger you would not want a display. |
|
|
|
|
|
#6 | |
|
Newbie
|
Quote:
Yes, that would make life much easier, but unfortunately, I don't have access to v$database. From what I've heard when similar problems to this cropped up in the past, they're not going to grant access to it either. Beuacracy is fun! |
|
|
|
|
|
|
#7 |
|
Newbie
|
Well, thank you all for your help - I'm just going to do a workaround. I made a new table that mapped the server names to the database names, then wrote a function that selects global_name from global_name (which gives me the server name), strips the .world from the end of it, and then uses that to find the database name.
|
|
|
|
|
|
#8 | |
|
Programming Guru
![]() ![]() |
Quote:
__________________
Profanity is the one language that all programmers understand. Check out my Blog <---updated Nov 30 2007! |
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|