Need Procedure or trigger for My query
Hi,
I want to know all the tables which are going to be affected by deleting a row in a particular table.For an example suppose i delete a row in TABLE A,it has relationship with TABLE B,TABLE c.But i don't know the relationship and the tables.I want to write a trigger or procedure to know the tables which are affected by that DML operations.
Kindly answer the above question,it helps me lot.
Thanking YOu
If by "has a relationship", you mean that you want to find tables that have a foreign key relationship with A, then you could do something like:
SELECT table_name
FROM all_constraints
WHERE r_constraint_name IN (SELECT constraint_name
FROM all_constraints
WHERE table_name = 'A' and
constraint_type IN ('P', 'U');If that is not what you meant, please clarify.
TTFN
John
Similar Messages
-
Need (procedure or function or sql query )for Email filter
Hi All,
in (procedure or function or sql query ) ,if i pass the a input parameter like (anbu@y or anbu@ or anbu@yahjjj ) ,i need to get output like [email protected] .
please give me code for this ...SQL> with t
2 as
3 (
4 select 'anbu@y' email from dual union all
5 select 'anbu@' from dual union all
6 select 'anbu@yahjjj' from dual
7 )
8 select email, regexp_replace(email, '@.*','@yahoo.com') email_new
9 from t
10 /
EMAIL
EMAIL_NEW
anbu@y
[email protected]
anbu@
[email protected]
anbu@yahjjj
[email protected] -
Help on Procedure and trigger for updating(urgent please)
SQL> / Table A
CTUT_ID CTUT_COMPANY_NAME CURRT_USER_ID FMIS_ID CREATE_DA UPDATE_BY UPDATE_DATE
1234 A 15-APR-03
2222 B 15-APR-03
3333 C 15-APR-03
4444 D 15-APR-03
5555 E 15-APR-03
6666 F 15-APR-03
150282 G oRACLE 23-APR-03
1 H 15-APR-03
2 I 15-APR-03
3 J 15-APR-03
150343 K TIGER 24-APR-03
150305 L EXAMPLE 23-APR-03
150342 M SCOTT 24-APR-03
sQL >/ Table B
Empno Empname UPDATE_BY UPDATE_DATE
1 AA
2 BB
3 CC
4 DD
What i need to do is i need to create an update trigger on both tables
like create a procedure
1)In procedure i need to check like
IF TABLEA.CURRT_USER_ID = (SELECT USER FROM DUAL)
THEN
UPDATE_BY = (CURRENT_USER_ID of CTUT_ID)
FOR EXAMPLE CURRENT USER_ID IS SCOTT THEN
UPDATE_BY = 150342
UPDATE_DATE = SYSDATE
ELSIF
UPDATE_BY <=> (CURRENT_USER_ID of CTUT_ID)
THEN
MESSAGE('USER IS NOT IN TABLE);
END IF;
and call that procedure in the update triggers
FOR BOTH TABLES TABLEA,TABLEB
i CREATED A PROCEDURE BUT IT IS NOT WORKING
ANY HELP PLEASE
CREATE OR REPLACE PROCEDURE UPDATE(
UPDATE_DATE out DATE,
UPDATE_BY out VARCHAR2)
IS
Uuser varchar2(20);
Udate date;
Ufound number(1);
BEGIN
SELECT USER,SYSDATE
INTO Uuser,Udate from dual;
SELECT count(*),CTUT_ID into Ufound,Uctut_id
FROM TABLEA
WHERE CURRT_USER_ID = Uuser
Group by Ctut_id;
IF (UFOUND = 1) THEN
UPDATE_DATE := UDATE;
UPDATE_BY := UCTUT_ID;
END IF;
EXCEPTION WHEN NO_DATA_FOUND THEN
RAISE_APPLICATION_ERROR(-20001,'User Does not Exist');
END UPD_CONSTITUENT;
CREATE A TRIGGER :
CREATE OR REPLACE TRIGGER TU
BEFORE INSERT ON TABLEA
FOR EACH ROW
BEGIN
UPDATE(:NEW.update_date,
:NEW.update_BY);
END IF;
END;
SQL> update TABLEA
2 set CTUT_COMPANY_NAME = 'SCOTT TEST'
3 WHERE FMIS_USER_ID = 'N';
update TABLEA
ERROR at line 1:
ORA-04091: table TABLEA is mutating, trigger/function may not see it
ORA-06512: at "UPDATE", line 12
ORA-06512: at "TU", line 1
ORA-04088: error during execution of trigger 'TU'Hi Mara,
You are right thats what i want
I have a table A
EmpNo Empname Currtuser_id Update_date Updateby
1 Denis Oracle
2 Scott Scott
3 Mara MMara
1)what i need to do is when any user tries to update the table Table A
Then the Trigger or procedure should check whether user is exits in table A in column currtuser_id
If his user id exits in table A
Then allow him to update the TABLE A
and insert his EMPNO in UPDATE_BY
and SYSDATE in UPDATE_BY
He will do all this process using forms
But i need to have trigger or procedure in database level for table
2) I have another table like 10 tables
Suppose TABLE B
When user tries to update TABLE B
Then the Trigger or procedure should check whether user is exits in table A in column currtuser_id
If his user id exits in table A
Then allow him to update the TABLE B
and insert his EMPNO in UPDATE_BY
and SYSDATE in UPDATE_BY
3) I need to have a common Procedure and call that procedure in all tables in UPDATE TRIGGER
Thanks for your help
Thanks -
Reg: mail need to be trigger for salary change
Hi gurus,
I have one requirement.
If any one does the changes in salary I mean in infotype 0008 then one mail need to be trigger.
Can any one tell me the procedure how to do this requirement?
Regards
RameshHI Soumya,
Thank you very much .
I have found one BOR for this workflow
BOR name : BSAICPAY
if any changes happen in infotype 0008 then changes event will tiger in this bor.
I completed this requirement trough simple workflow
Thank you all
Thank you for your support
Regards
RameshG -
Need help with trigger for whitespace and caps validation
I need to create a table trigger that will generate an error whenever a specific column does not contain all caps or has whitespace when records are either inserted or updated. I'm new to writing SQL, so any help is appreciated!
In 10g
SQL> create or replace trigger trigg_sample
2 before update or insert on sample
3 for each row
4 declare
5 lv_pos number;
6 begin
7 select regexp_instr(:new.col1,'[a-z|( )]') into lv_pos from dual;
8 if lv_pos > 0 then
9 raise_application_error(20000,'The column contains lowercase or white space characters');
10 end if;
11 end;
12 /
Trigger created.
SQL> desc sample;
Name Null? Type
COL1 VARCHAR2(20)
SQL> insert into sample values('DFD') ;
1 row created.
SQL> insert into sample values('dfdfd') ;
insert into sample values('dfdfd')
ERROR at line 1:
ORA-21000: error number argument to raise_application_error of 20000 is out of
range
ORA-06512: at "XLS_ADMIN.TRIGG_SAMPLE", line 6
ORA-04088: error during execution of trigger 'XLS_ADMIN.TRIGG_SAMPLE'
SQL> insert into sample values('DFDF ') ;
insert into sample values('DFDF ')
ERROR at line 1:
ORA-21000: error number argument to raise_application_error of 20000 is out of
range
ORA-06512: at "XLS_ADMIN.TRIGG_SAMPLE", line 6
ORA-04088: error during execution of trigger 'XLS_ADMIN.TRIGG_SAMPLE'
SQL> -
Need to use Hint for Select Query 11g
Hi,
I have a select query which is fetching data from multiple table.
I just need 10 or less rows, already I m using rownum <=10
Could you tell which is the better choice for using HINT.
/*+ FIRST_ROWS(10) */ (or) /*+ all_rows */
Thanks.On Oracle 11.2.0.3 and 11.1.0.7 on my test table with an ORDER BY in the query, I found FIRST_ROWS using the index to get sorted rows and ALL_ROWS retrieving 10 rows from a full scan and then sorting them.
On Oracle I didn't find any difference in plan on a different, physically smaller, table.
For the ALL_ROWS version the optimiser already knows that there will only be 10 rows returned.
The performance difference: As usual, only use FIRST_ROWS if you actually intend to fetch less than the full data set. If you intend to fetch all 10 rows, use ALL_ROWS, which should be the default (taken from the optimizer_mode system parameter). -
HI,
In my query I had a User entry Variable (Multiple Single Values) on 0DEPARTMENT.
I had give a list of 2000 departments in a excel file.
When I execute a query in WEB (7X Template) my requirement is to create a Variant so that if selected all the 2000 departments are included
How can I paste all the 2000 values in the variable screen and save it as a variant
ThanksHi,
For this you will need to create variant for the query in RSRT transaction. Just goto RSRT transaction. Provide the query name and click on Query Variants button. You will get a n option to create variant for the query. paste all the 2000 values for that particular variable of the query and save it as variant.
Now when you will execute the query in the web you will get an option to select that variant from the query.
Navesh -
Single Trigger for muliple tables
Hi All,
I have one requirement to create a trigger to populate a table (X) based on the any insert or update on few tables (A,B,C,D,E,F).
Do I need to create trigger for each table ??. any idea of using all tables in one trigger.Hi,
this is not possible.
but you can use multiple trigger on single table
if you can use view, then you can use INSTEAD OF Trigger on view
for example
CREATE OR REPLACE VIEW manager_info AS
SELECT e.ename, e.empno, d.dept_type, d.deptno, p.prj_level,
p.projno
FROM Emp_tab e, Dept_tab d, Project_tab p
WHERE e.empno = d.mgr_no
AND d.deptno = p.resp_dept;
CREATE OR REPLACE TRIGGER manager_info_insert
INSTEAD OF INSERT ON manager_info
REFERENCING NEW AS n -- new manager information
FOR EACH ROW
DECLARE
rowcnt number;
BEGIN
SELECT COUNT(*) INTO rowcnt FROM Emp_tab WHERE empno = :n.empno;
IF rowcnt = 0 THEN
INSERT INTO Emp_tab (empno,ename) VALUES (:n.empno, :n.ename);
ELSE
UPDATE Emp_tab SET Emp_tab.ename = :n.ename
WHERE Emp_tab.empno = :n.empno;
END IF;
SELECT COUNT(*) INTO rowcnt FROM Dept_tab WHERE deptno = :n.deptno;
IF rowcnt = 0 THEN
INSERT INTO Dept_tab (deptno, dept_type)
VALUES(:n.deptno, :n.dept_type);
ELSE
UPDATE Dept_tab SET Dept_tab.dept_type = :n.dept_type
WHERE Dept_tab.deptno = :n.deptno;
END IF;
SELECT COUNT(*) INTO rowcnt FROM Project_tab
WHERE Project_tab.projno = :n.projno;
IF rowcnt = 0 THEN
INSERT INTO Project_tab (projno, prj_level)
VALUES(:n.projno, :n.prj_level);
ELSE
UPDATE Project_tab SET Project_tab.prj_level = :n.prj_level
WHERE Project_tab.projno = :n.projno;
END IF;
END;see more : http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14251/adfns_triggers.htm
Edited by: Mahir M. Quluzade on Oct 12, 2011 9:23 AM -
help needed for writing query
i have the following tables(with data) as mentioned below
FK*-foregin key (SUBJECTS)
FK**-foregin key (COMBINATION)
1)SUBJECTS(table name)
SUB_ID(NUMBER) SUB_CODE(VARCHAR2) SUB_NAME (VARCHAR2)
2 02 Computer Science
3 03 Physics
4 04 Chemistry
5 05 Mathematics
7 07 Commerce
8 08 Computer Applications
9 09 Biology
2)COMBINATION
COMB_ID(NUMBER) COMB_NAME(VARCHAR2) SUB_ID1(NUMBER(FK*)) SUB_ID2(NUMBER(FK*)) SUB_ID3(NUMBER(FK*)) SUBJ_ID4(NUMBER(FK*))
383 S1 9 4 2 3
384 S2 4 2 5 3
---------I actually designed the ABOVE table also like this
3) a)COMBINATION
COMB_ID(NUMBER) COMB_NAME(VARCHAR2)
383 S1
384 S2
b)COMBINATION_DET
COMBDET_ID(NUMBER) COMB_ID(FK**) SUB_ID(FK*)
1 383 9
2 383 4
3 383 2
4 383 3
5 384 4
6 384 2
7 384 5
8 384 3
Business rule: a combination consists of a maximum of 4 subjects (must contain)
and the user is less relevant to a COMB_NAME(name of combinations) but user need
the subjects contained in combinations
i need the following output
COMB_ID COMB_NAME SUBJECT1 SUBJECT2 SUBJECT3 SUBJECT4
383 S1 Biology Chemistry Computer Science Physics
384 S2 Chemistry Computer Science Mathematics Physics
or even this is enough(what i actually needed)
COMB_ID subjects
383 Biology,Chemistry,Computer Science,Physics
384 Chemistry,Computer Science,Mathematics,Physics
you can use any of the COMBINATION table(either (2) or (3))
and i want to know
1)which design is good in this case
(i think SUB_ID1,SUB_ID2,SUB_ID3,SUB_ID4 is not a
good method to link with same table but if 4 subjects only(and must) comes
detail table is not neccessary )
now i am achieving the result by program-coding in C# after getting the rows from oracle
i am using oracle 9i (also ODP.NET)
i want to know how can i get the result in the stored procedure itsef.
2)how it could be designed in any other way.
any help/suggestion is welcome
thanks for your time --PradeeshWell I forgot the table-alias, here now with:
SELECT C.COMB_ID
, C.COMB_NAME
, (SELECT SUB_NAME
FROM SUBJECTS
WHERE SUB_ID = C.SUB_ID1) AS SUBJECT_NAME1
, (SELECT SUB_NAME
FROM SUBJECTS
WHERE SUB_ID = C.SUB_ID2) AS SUBJECT_NAME2
, (SELECT SUB_NAME
FROM SUBJECTS
WHERE SUB_ID = C.SUB_ID3) AS SUBJECT_NAME3
, (SELECT SUB_NAME
FROM SUBJECTS
WHERE SUB_ID = C.SUB_ID4) AS SUBJECT_NAME4
FROM COMBINATION C;
As you need exactly 4 subjects, the columns-solution is just fine I would say. -
I need return the result of a query on a stored procedure
I need return the result of a query on a stored procedure, I mean when I execute a stored procedure it returns a result set as a select query.
Best regards...If you want some pl/sql code that can be used in a query as it were a table you may be interested in table functions:
SQL> create or replace type
2 t_emp is object (
3 name varchar2(30),
4 hire_date date,
5 salary number);
6 /
Tipo creato.
SQL> create or replace type
2 t_emptab is table of t_emp;
3 /
Tipo creato.
SQL> create or replace function tab_fun(p_dept in number)
2 return t_emptab is
3 e t_emptab;
4 begin
5 select t_emp(ename,hiredate,sal)
6 bulk collect into e
7 from emp
8 where deptno=p_dept;
9
10 return dip;
11 end;
12 /
Funzione creata.
SQL> select *
2 from table(tab_fun(20));
NAME HIRE_DATE SALARY
SMITH 17-DIC-80 800
JONES 02-APR-81 2975
SCOTT 09-DIC-82 3000
ADAMS 12-GEN-83 1100
FORD 03-DIC-81 3000A procedure cannot be used in a select statement.
Max
http://oracleitalia.wordpress.com -
Need example for BAPI query. Please, help.
Hi,
badly need help on BAPI_ACC_ACTIVITY_ALLOC_POST.
Does anybody have some example code for jCO query?
Thanks.
VladimirHi,
Try this code...
package jco;
import com.sap.mw.jco.*;
public class jcosample
public static void main(String args[])
JCO.Client myConnection = null;
JCO.Repository mRepository = null;
JCO.Function myFunction = null;
try
myConnection = JCO.createClient("client","username","password" ,"language","ip address","system no");
myConnection.connect();
mRepository = new JCO.Repository("WIPRO",myConnection);
try
if (mRepository == null )
System.out.println("NuLL");
try
IFunctionTemplate ft=mRepository.getFunctionTemplate("BAPI_COMPANYCODE_GETLIST");
myFunction=ft.getFunction();
}catch (Exception ex)
throw new Exception(ex + "Problem retrieving JCO.Function object.");
if (myFunction == null)
System.exit(1);
myConnection.execute(myFunction);
}catch (Exception ex)
ex.printStackTrace();
System.exit(1);
myConnection.execute(myFunction);
JCO.Table codes = null;
codes =myFunction.getTableParameterList().getTable("COMPANYCODE_LIST");
int size;
size =codes.getNumRows();
if (size == 0)
System.out.println("No value matches the selection cretaria");
else
for (int i = 0;i<=size; i++)
codes.setRow(i); System.out.print(codes.getString("COMP_CODE")); System.out.println(codes.getString("COMP_NAME"));
}catch( Exception e)
e.printStackTrace();
Hope that helps...
Note: in case for the BAPI that inserts or modified data you must call the BAPI_TRANSACTION_COMMIT also for the changes to get reflected in the Database.
Please let me if that helps you.
Cheers
Kathir~ -
I need solution for this query
hi all,
could anyone please send me solution for this query these are the database tables am having
TABLE NAME :USERS
ATTRIBUTES
UNAME
PASSWORD
GROUPNAME
TABLE NAME:GROUPS
ATTRIBUTES
GROUPID
GROUPNAME
my requirement is that i need 2 acces the groupname of a particular user and the reamining groups to which i doesn't belong in A SINGLE QUERY
my result needs to be like this
Authorised group
consultant
UNAuthorised groups
sales
vender
recruiter
admin
if any body got the solution please sendhi All,
I have 3 tables 1)PREVILEGES (groupname, previleges(values y or n only))
2)GROUPS (groupid, groupname)
3) USERS (uname, groupname).
Here each user belongs to one group, each user hav a default previlege means example if user is consutant then he can access only consultant group. Means default previlege will be used. For default previleges, there is no record in Previleges table.
The Problem is that, I need to reterive the groupname from users which de doesn't belong as well as his previleges from previleges, If there is no values in previleges in the table it should return n. or value what is therey.
the different groups are
SALES,CONSULTANT,VENDER,RECRUTER,ADMIN -
I need some Important Trigger Programs for Objects
I need some Important Trigger Programs for Objects.
If the program includes the V-array appln, that would be better to.There are some drawbacks, running Windows 7 (only) on a Mac via Bootcamp yields less than stellar results, especially with the Retina display.
And of your traveling, the Mac's high power needs (especially the Retina display) and lack of removable battery are going to be a serious issue. The Retina display is glossy, not ideal for viewing on the road and in varied environments.
CS4 won't run on the OS X version that comes with a Mac, so your looking at purchasing CS6.
Support for Windows is more widespread than for Mac's, also if you ever need to redownload OS X to fix a issue, requires a fast reliable Internet connection of the broadband kind.
If your running Windows on your Mac, you can expect to be on your own and not get support as easily as if you were running it on a regular PC.
If you can't afford to keep up with CS upgrades, then you shouldn't be considering a Mac because there are more paid upgrades on that than on Windows 7, it's like a annual nightmare.
IMMO your still better off on a decent, 1920 x 1080 res, matte screen, removable battery (with extras), Win 7 Pro i7 machine (Pro+ runs XP programs) which will stay like it is and get security updates until 2020.
OS X changes every year and if you don't upgrade, + all your third party software, then about 3 years later your left behind for updates.
Also you will have to buy Win 7 to run on your Mac, the OEM disks won't work.
If your trying to budget, then a Mac is certainly not for you. -
SQ01 - Need an input field for query report as mandatory
Hi Guys
I have created a report using SQ03,SQ02 & SQ01. The report is running fine. But i want to make one of the input field as manadatory
Guys have any suggestion for the same
I tried in SQ02, a field named DBPAOBLIG
I got the above mentioned field when i clicked the extras tab in SQ02 - But the field is not in change mode
Please suggest me how to make the field as mandatory
Warm Regards
BalaHi,
Create a variant, when you run a query - make it to be run only with this variant (via definition in a transaction for this query). In variant, you can define required fields.
Regards,
Eli -
Bulk insert using stored procedure or trigger
Hi ,
I have to insert around 40,000 rows in a table querying other database using database link.
Please advice whether I do using stored procedure or trigger.
Thanks.Here is a basic benchmark that illustrates the difference between maximising SQL, or doing it in PL/SQL instead.
Care needs to be taken with such a benchmark in order for physical I/O not to negatively impact a test, and then have no impact in the second test as that data read from disk now sits in the cache.
So I ran it a couple of times in order to "warm up" the cache. I also put the maximise-SQL test first in order to show that it is still faster, despite any physical I/O it may do (which will likely be faster logical I/O with the second test).
Run on Oracle XE 10.2.0.1.
SQL> drop table my_objects_copy purge;
Table dropped.
SQL> create table my_objects_copy as select * from all_objects;
Table created.
SQL>
SQL> set timing on
SQL> begin
2 delete from my_objects_copy;
3
4 insert into my_objects_copy
5 select * from all_objects;
6
7 commit;
8 end;
9 /
PL/SQL procedure successfully completed.
Elapsed: 00:00:01.11
SQL> set timing off
SQL>
SQL> drop table my_objects_copy purge;
Table dropped.
SQL> create table my_objects_copy as select * from all_objects;
Table created.
SQL>
SQL> set timing on
SQL> declare
2 cursor c is select * from all_objects;
3 objRow ALL_OBJECTS%ROWTYPE;
4 begin
5 delete from my_objects_copy;
6
7 open c;
8 loop
9 fetch c into objRow;
10 exit when c%NOTFOUND;
11
12 insert into my_objects_copy
13 values objRow;
14
15 end loop;
16 commit;
17 end;
18 /
PL/SQL procedure successfully completed.
Elapsed: 00:00:03.21
SQL>
The cursor-fetch-loop is almost 3 times slower. The more rows there are to process, the slower the cursor-fetch-loop will become, as it will create more and more context switching and copying data between the SQL and PL engines and back.
Maybe you are looking for
-
MacBook Pro (2011) Won't Charge Without Restart
Hi guys, I searched the forums for this problem but couldn't find a match. When I plug the power cable into my 2011 17" MacBook Pro it won't take a charge and the light on the cable doesn't come on. However if I restart the computer, the light will c
-
Wifi unable to connect when tv streams media
We just got a new Sony TV tonight that has a non wifi, LAN connection, and the Netflix application on it. As soon as I logged into Netflix on the TV, my iPad is unable to connect to wifi. I've tried disconnecting, reconnecting, renewing, and restart
-
How do I return a device licence to my deployment pool?
How do I return a device license to my deployment pool. I have created a package using CCP and deployed it to a test machine but now I need to return the license to my deployment pool. There is no obvious way of doing this via the deployed app or via
-
10.4.9 broke my mabcbook
I tried to update to 10.4.9 via Software Update. It downloaded the whole update file and then i got an error mesage saying that the update was not expanded correctly and the package file for it appeared in Trash. I tried to download the update manual
-
Going from 4 FM areas to 1 FM area
Dear experts, I work for a customer who uses ERP 600 PSM Former Budgeting. I need to offer an improvement of their system like migrationg to BCS but also some restructuring of master data and organizations. So my question is, is it possible to reassi