Delete records from sys.aud$ stored procedure
We have a stored procedure that attempts to move the records from the table of sys.aud$ to a history table (in order to keep sys.aud$ to a more reasonable size, I guess - full disclosure, I have not written this proc). Base flow is:Select count (*) in the number of lines of sys.aud$
If {(rowcount > 1000)
copy all rows in sys.aud$ in the history table
remove from sys.aud$
}
I says this proc used to work perfectly in a troubled past (I'm new on the client) but now has not worked for a while. When we try to compile the proc, we get the error
"table or view does not exist", and the line is the "deletion of sys.aud$. The line "select count (*) from sys.aud$ ' seems to cause no problems, but the proc does not compile as is. If I comment out the line "remove from sys.aud$", however, the proc compiles very well.
Confusingly, if I log in as the same account that owns this proc, I can run both the count (*) select from sys.aud$ AND remove clauses sys.aud$ with no complaint at all (by modifying slightly to work with 1 single record at a time, of course), but I can't seem the same to compile in a stored proc.
I guess that it is related permissions? Can someone point me to the permissions of the owner needs to be able to remove from sys.aud$ in a stored procedure? Or is there something else that needs to be done here? Pointers much appreciated.
Thank you.
956928 wrote:
We have a stored procedure that attempts to move the records from the table of sys.aud$ to a history table (in order to keep sys.aud$ to a more reasonable size, I guess - full disclosure, I have not written this proc). Base flow is:
Select count (*) in the number of lines of sys.aud$
If (rowcount 1000 >) {}
copy all rows in sys.aud$ in the history table
remove from sys.aud$
}I says this proc used to work perfectly in a troubled past (I'm new on the client) but now has not worked for a while. When we try to compile the proc, we get the error
"table or view does not exist", and the line is the "deletion of sys.aud$. The line "select count (*) from sys.aud$ ' seems to cause no problems, but the proc does not compile as is. If I comment out the line "remove from sys.aud$", however, the proc compiles very well.Confusingly, if I log in as the same account that owns this proc, I can run both the count (*) select from sys.aud$ AND remove clauses sys.aud$ with no complaint at all (by modifying slightly to work with 1 single record at a time, of course), but I can't seem the same to compile in a stored proc.
I guess that it is related permissions? Can someone point me to the permissions of the owner needs to be able to remove from sys.aud$ in a stored procedure? Or is there something else that needs to be done here? Pointers much appreciated.
Thank you.
acquired through ROLE privileges are NOT applicable within the named PL/SQL procedures.
GRANT DELETE ON SYS. AUD$
Tags: Database
Similar Questions
-
Use the utilities from the Oracle stored procedure
Hi all
I use Oracle Import to load the data from .dmp file to Oracle table.
Test/test leader IMP = Data .dmp fromuser = user1 touser = test tables = emp
But my requirement is to create a stored procedure that will import data into the table and identify the number of loaded records and how impossible to import.
Can I keep inside the procedure import statement?
Thank you.No, not possible.
IMP is an exe like sql more who can evoke to the command prompt.
If you need all the actions on the imported... table export for example/test table, and then go further.
-
Delete query to delete records from multiple tables
All,
I need a delete query that will delete the records from the tables. Please see the structure of the table & below
Now, I need to delete the records in these tables where the ID is '2000' by using a single delete query. Is this possible? This may be a newbie question. Help, please.CREATE TABLE TEMP1 (ID NUMBER(10),NAME VARCHAR2(40),CLASS VARCHAR2(40),COLLEGE VARCHAR2(40)); CREATE TABLE TEMP2 (ID NUMBER(10),CITY VARCHAR2(40),STATE(40)); INSERT INTO TEMP1 (ID, NAME,CLASS,COLLEGE) VALUES (1000,'SAM','CS','UNIV_1'); INSERT INTO TEMP1 (ID, NAME,CLASS,COLLEGE) VALUES (2000,'RIO','CS','UNIV_1'); INSERT INTO TEMP1 (ID, NAME,CLASS,COLLEGE) VALUES (3000,'CHRIS','CS','UNIV_1'); INSERT INTO TEMP1 (ID, NAME,CLASS,COLLEGE) VALUES (4000,'ALEX','CS','UNIV_1'); INSERT INTO TEMP2 (ID, CITY,STATE) VALUES (1000,'Auburn','NY'); INSERT INTO TEMP2 (ID, CITY,STATE) VALUES (2000,'Ithaca','NY'); INSERT INTO TEMP2 (ID, CITY,STATE) VALUES (3000,'Mount Vernon','NY'); INSERT INTO TEMP2 (ID, CITY,STATE) VALUES (4000,'Port Jervis','NY');
"using a single request deletion. Is this possible?
Nope.
You can insert into multiple tables by using a single query, INSERT ALL job, but you cannot delete more than one table using a single query. -
Delete records from a table of forms
Oracle forms6i
Hai All
I use forms6i and my need is I have generated a forms and the output is displayed through tables and I need to delete all the records from the table of my forms when executing next time pls tell me
Concerning
Srikkanth.MHello
Please try something like that.
Begin Delete From Master_Tbl Cascade; forms_ddl('Commit'); End;
Sarah
-
call a packed stored procedure from within another stored procedure
I have a stored procedure (STROKEQC) on a scheme that is not in a package. I want to be able to call a procedure stored that IS inside a package on the same scheme of STROKEQC. When I try the syntax below, I get an error "no function with name 'PARTICIPANTSPECIFICEDITS' exists in this area." That the procedure exists.
Is not the way to do inside a stored procedure?/*Generate admin field data*/ execute immediate QCPROCEDURES.PARTICIPANTSPECIFICEDITS('ALL'); execute immediate QCPROCEDURES.GENERATE_SURGYEAR_ERRFLAG;
Thank you!
EvaHi, Eva,.
You need not EXECUTE IMMEDIATE to call a stored procedure (including a procedure in a package) on the other. Just use the name and the arguments (if any):
QCPROCEDURES.PARTICIPANTSPECIFICEDITS('ALL'); QCPROCEDURES.GENERATE_SURGYEAR_ERRFLAG;
I guess qcprocedures is the package name, and participantspecificedits and generate_surgyear_errflag are procedures in this package.
In case you're wondering, the error was probably because you do not have a variable called participantspecificedits. If you had a dynamic code in a string called variable x, then "EXECUTE IMMEDIATE x"; would be the way to run it.
-
Record in sys.aud$ can be deleted directly?
We start with Oracle 11 g of August 2011, I am not aware of the audit trail is turned on by default. I'll try to set up the schedule jobs to purge the audit trail regularly, before that, I will not keep track more than a month ago. Can I just delete the record by timestamp? Is - this ntimestamp #?The last_arch_timestamp is used by the procedure, but must be set manually by the ADMINISTRATOR. You may have another procedure set it progressively.
Hemant K Collette
-
How to delete records from a table?
It comes to my table structure:
Here are some insert statements to populate the table. *(About a 100 of them, please Bear with me) *.create table BILLS ( bill_id VARCHAR2(20), trx_no VARCHAR2(20), item_code VARCHAR2(3), amount NUMBER, item_id NUMBER, invoice_dt DATE )
It comes to my select statement.insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT) values ('104173960', '910873', '002', 432, 351, to_date('04-03-2007', 'dd-mm-yyyy')); insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT) values ('104209800', '910873', '002', 432, 351, to_date('04-04-2007', 'dd-mm-yyyy')); insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT) values ('104212747', '263156', '039', 230, 351, to_date('01-04-2007', 'dd-mm-yyyy')); insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT) values ('104269414', '263156', '039', 230, 351, to_date('01-06-2007', 'dd-mm-yyyy')); insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT) values ('104360446', '263156', '039', 230, 351, to_date('01-09-2007', 'dd-mm-yyyy')); insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT) values ('104577673', '910873', '002', 432, 351, to_date('04-04-2008', 'dd-mm-yyyy')); insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT) values ('104608668', '910873', '002', 432, 351, to_date('04-05-2008', 'dd-mm-yyyy')); insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT) values ('104611586', '263156', '039', 230, 351, to_date('01-05-2008', 'dd-mm-yyyy')); insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT) values ('104642560', '910873', '002', 432, 351, to_date('04-06-2008', 'dd-mm-yyyy')); insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT) values ('104699154', '910873', '002', 432, 351, to_date('04-08-2008', 'dd-mm-yyyy')); insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT) values ('104820820', '263156', '039', 230, 351, to_date('01-12-2008', 'dd-mm-yyyy')); insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT) values ('104826028', '910873', '002', 432, 351, to_date('04-12-2008', 'dd-mm-yyyy')); insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT) values ('104850631', '910873', '002', 432, 351, to_date('04-01-2009', 'dd-mm-yyyy')); insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT) values ('104885554', '263156', '039', 230, 351, to_date('01-02-2009', 'dd-mm-yyyy')); insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT) values ('104926901', '910873', '002', 432, 351, to_date('04-03-2009', 'dd-mm-yyyy')); insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT) values ('104936656', '263156', '', 15, 247, null); insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT) values ('104996320', '263156', '039', 230, 351, to_date('01-05-2009', 'dd-mm-yyyy')); insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT) values ('105030104', '263156', '039', 230, 351, to_date('01-06-2009', 'dd-mm-yyyy')); insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT) values ('105176803', '910873', '002', 432, 351, to_date('04-10-2009', 'dd-mm-yyyy')); insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT) values ('105217998', '910873', '002', 432, 351, to_date('04-11-2009', 'dd-mm-yyyy')); insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT) values ('105253306', '263156', '039', 230, 351, to_date('01-12-2009', 'dd-mm-yyyy')); insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT) values ('105280152', '263156', '039', 230, 351, to_date('01-01-2010', 'dd-mm-yyyy')); insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT) values ('105318072', '910873', '002', 432, 351, to_date('04-02-2010', 'dd-mm-yyyy')); insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT) values ('105449712', '910873', '002', 432, 351, to_date('04-06-2010', 'dd-mm-yyyy')); insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT) values ('105579048', '910873', '002', 432, 351, to_date('04-10-2010', 'dd-mm-yyyy')); insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT) values ('105611201', '263156', '039', 230, 351, to_date('01-11-2010', 'dd-mm-yyyy')); insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT) values ('105679991', '263156', '011', 196.56, 351, to_date('06-01-2011', 'dd-mm-yyyy')); insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT) values ('105686749', '910873', '002', 432, 351, to_date('04-01-2011', 'dd-mm-yyyy')); insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT) values ('105816473', '910873', '002', 432, 351, to_date('04-05-2011', 'dd-mm-yyyy')); insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT) values ('105846525', '263156', '011', 230, 351, to_date('01-06-2011', 'dd-mm-yyyy')); insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT) values ('105778111', '910873', '002', 432, 351, to_date('04-04-2011', 'dd-mm-yyyy')); insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT) values ('104958496', '910873', '002', 432, 351, to_date('04-04-2009', 'dd-mm-yyyy')); insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT) values ('105143695', '910873', '002', 432, 351, to_date('04-09-2009', 'dd-mm-yyyy')); insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT) values ('104176755', '263156', '039', 230, 351, to_date('01-03-2007', 'dd-mm-yyyy')); insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT) values ('104365552', '910873', '002', 432, 351, to_date('04-09-2007', 'dd-mm-yyyy')); insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT) values ('104646837', '263156', '039', 230, 351, to_date('01-06-2008', 'dd-mm-yyyy')); insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT) values ('104763596', '910873', '002', 432, 351, to_date('04-10-2008', 'dd-mm-yyyy')); insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT) values ('104936656', '263156', '', 15, 247, null); insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT) values ('105510930', '263156', '039', 230, 351, to_date('01-08-2010', 'dd-mm-yyyy')); insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT) values ('104302780', '263156', '039', 230, 351, to_date('01-07-2007', 'dd-mm-yyyy')); insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT) values ('104793590', '263156', '039', 230, 351, to_date('01-11-2008', 'dd-mm-yyyy')); insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT) values ('104238583', '910873', '002', 432, 351, to_date('04-05-2007', 'dd-mm-yyyy')); insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT) values ('105779115', '263156', '011', 230, 351, to_date('01-04-2011', 'dd-mm-yyyy')); insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT) values ('104394481', '263156', '039', 230, 351, to_date('01-10-2007', 'dd-mm-yyyy')); insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT) values ('105144934', '263156', '039', 230, 351, to_date('01-09-2009', 'dd-mm-yyyy')); insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT) values ('105342823', '263156', '039', 230, 351, to_date('01-03-2010', 'dd-mm-yyyy')); insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT) values ('105747780', '910873', '002', 432, 351, to_date('04-03-2011', 'dd-mm-yyyy')); insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT) values ('105517258', '910873', '002', 432, 351, to_date('04-08-2010', 'dd-mm-yyyy')); insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT) values ('105617909', '910873', '002', 432, 351, to_date('04-11-2010', 'dd-mm-yyyy')); insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT) values ('104480711', '910873', '002', 432, 351, to_date('04-01-2008', 'dd-mm-yyyy')); insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT) values ('105845480', '910873', '002', 432, 351, to_date('04-06-2011', 'dd-mm-yyyy')); insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT) values ('105349031', '910873', '002', 432, 351, to_date('04-03-2010', 'dd-mm-yyyy')); insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT) values ('105382599', '263156', '039', 230, 351, to_date('01-04-2010', 'dd-mm-yyyy')); insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT) values ('104423263', '263156', '039', 230, 351, to_date('01-11-2007', 'dd-mm-yyyy')); insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT) values ('104482370', '263156', '039', 230, 351, to_date('01-01-2008', 'dd-mm-yyyy')); insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT) values ('104892872', '910873', '002', 432, 351, to_date('04-02-2009', 'dd-mm-yyyy')); insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT) values ('105071771', '263156', '039', 230, 351, to_date('01-07-2009', 'dd-mm-yyyy')); insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT) values ('105716829', '910873', '002', 432, 351, to_date('04-02-2011', 'dd-mm-yyyy')); insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT) values ('105251149', '910873', '002', 432, 351, to_date('04-12-2009', 'dd-mm-yyyy')); insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT) values ('105420465', '910873', '002', 432, 351, to_date('04-05-2010', 'dd-mm-yyyy')); insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT) values ('105547036', '910873', '002', 432, 351, to_date('04-09-2010', 'dd-mm-yyyy')); insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT) values ('105450806', '263156', '039', 230, 351, to_date('01-06-2010', 'dd-mm-yyyy')); insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT) values ('105178143', '263156', '039', 230, 351, to_date('01-10-2009', 'dd-mm-yyyy')); insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT) values ('105648407', '910873', '002', 432, 351, to_date('04-12-2010', 'dd-mm-yyyy')); insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT) values ('105718070', '263156', '011', 230, 351, to_date('01-02-2011', 'dd-mm-yyyy')); insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT) values ('104735083', '910873', '002', 432, 351, to_date('04-09-2008', 'dd-mm-yyyy')); insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT) values ('105748707', '263156', '011', 230, 351, to_date('01-03-2011', 'dd-mm-yyyy')); insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT) values ('104570555', '263156', '039', 230, 351, to_date('01-04-2008', 'dd-mm-yyyy')); insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT) values ('105480249', '910873', '002', 432, 351, to_date('04-07-2010', 'dd-mm-yyyy')); insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT) values ('104799512', '910873', '002', 432, 351, to_date('04-11-2008', 'dd-mm-yyyy')); insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT) values ('105036878', '910873', '002', 432, 351, to_date('04-06-2009', 'dd-mm-yyyy')); insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT) values ('105413781', '263156', '039', 230, 351, to_date('01-05-2010', 'dd-mm-yyyy')); insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT) values ('105548204', '263156', '039', 230, 351, to_date('01-09-2010', 'dd-mm-yyyy')); insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT) values ('104510445', '910873', '002', 432, 351, to_date('04-02-2008', 'dd-mm-yyyy')); insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT) values ('104545120', '263156', '039', 230, 351, to_date('01-03-2008', 'dd-mm-yyyy')); insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT) values ('104700608', '263156', '039', 230, 351, to_date('01-08-2008', 'dd-mm-yyyy')); insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT) values ('104765006', '263156', '039', 230, 351, to_date('01-10-2008', 'dd-mm-yyyy')); insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT) values ('105111984', '910873', '002', 432, 351, to_date('04-08-2009', 'dd-mm-yyyy')); insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT) values ('105310993', '263156', '039', 230, 351, to_date('01-02-2010', 'dd-mm-yyyy')); insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT) values ('105481415', '263156', '039', 230, 351, to_date('01-07-2010', 'dd-mm-yyyy')); insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT) values ('105210719', '263156', '039', 230, 351, to_date('01-11-2009', 'dd-mm-yyyy')); insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT) values ('105809981', '263156', '011', 230, 351, to_date('01-05-2011', 'dd-mm-yyyy')); insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT) values ('104328833', '910873', '002', 432, 351, to_date('04-08-2007', 'dd-mm-yyyy')); insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT) values ('104511904', '263156', '039', 230, 351, to_date('01-02-2008', 'dd-mm-yyyy')); insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT) values ('105278905', '910873', '002', 432, 351, to_date('04-01-2010', 'dd-mm-yyyy')); insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT) values ('104421567', '910873', '002', 432, 351, to_date('04-11-2007', 'dd-mm-yyyy')); insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT) values ('104851866', '263156', '039', 230, 351, to_date('01-01-2009', 'dd-mm-yyyy')); insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT) values ('105649424', '263156', '039', 230, 351, to_date('01-12-2010', 'dd-mm-yyyy')); insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT) values ('104729022', '263156', '039', 230, 351, to_date('01-09-2008', 'dd-mm-yyyy')); insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT) values ('105070358', '910873', '002', 432, 351, to_date('04-07-2009', 'dd-mm-yyyy')); insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT) values ('104299829', '910873', '002', 432, 351, to_date('04-07-2007', 'dd-mm-yyyy')); insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT) values ('104920099', '263156', '039', 230, 351, to_date('01-03-2009', 'dd-mm-yyyy')); insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT) values ('104266551', '910873', '002', 432, 351, to_date('04-06-2007', 'dd-mm-yyyy')); insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT) values ('104994904', '910873', '002', 432, 351, to_date('04-05-2009', 'dd-mm-yyyy')); insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT) values ('104910999', '263156', '', 15, 247, null); insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT) values ('104241418', '263156', '039', 230, 351, to_date('01-05-2007', 'dd-mm-yyyy')); insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT) values ('104960203', '263156', '039', 230, 351, to_date('01-04-2009', 'dd-mm-yyyy')); insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT) values ('105381371', '910873', '002', 432, 351, to_date('04-04-2010', 'dd-mm-yyyy')); insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT) values ('104542458', '910873', '002', 432, 351, to_date('04-03-2008', 'dd-mm-yyyy')); insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT) values ('104670160', '910873', '002', 432, 351, to_date('04-07-2008', 'dd-mm-yyyy')); insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT) values ('105105026', '263156', '039', 230, 351, to_date('01-08-2009', 'dd-mm-yyyy')); insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT) values ('104392347', '910873', '002', 432, 351, to_date('04-10-2007', 'dd-mm-yyyy')); insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT) values ('104451005', '910873', '002', 432, 351, to_date('04-12-2007', 'dd-mm-yyyy')); insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT) values ('104453960', '263156', '039', 230, 351, to_date('01-12-2007', 'dd-mm-yyyy')); insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT) values ('104671563', '263156', '039', 230, 351, to_date('01-07-2008', 'dd-mm-yyyy')); insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT) values ('104331181', '263156', '039', 230, 351, to_date('01-08-2007', 'dd-mm-yyyy')); insert into BILLS (BILL_ID, TRX_NO, ITEM_CODE, AMOUNT, ITEM_ID, INVOICE_DT) values ('105580192', '263156', '039', 230, 351, to_date('01-10-2010', 'dd-mm-yyyy'));
I want to remove the lines that are extracted from my select statement. What is the best way to achieve this?SELECT Trx_No, Item_Code, Amount, Item_Id, MAX(Invoice_Dt) FROM Bills GROUP BY Trx_No, Item_Code, Amount, Item_Id
SELECT query sets.She literally takes
delete from bills where (Trx_No,Item_Code,Amount,Item_Id,Invoice_Dt) in (select Trx_No,Item_Code,Amount,Item_Id,MAX(Invoice_Dt) FROM Bills GROUP BY Trx_No,Item_Code,Amount,Item_Id )
Concerning
Etbin
-
How to delete records from a table that has a composite unique key duplicate
Hello
I get the customer data from various sources in the staging of the table where I insert in the database table where the combination of two columns is considered as a unique key. But there is a possibility of duplicates. How to find duplicates in a SQL or pl/sql
Thank you
Manoi.Kassa,
You can see the duplicates by using the following query...
sql> select * from temp_rajesh; COL1 COL2 MESSAGE ---------- ---------- ------------------ 100 200 message 100 200 message2 300 400 message3 400 500 message 4 sql> select col1, col2, count(*) 2 from temp_rajesh 3 group by col1, col2 4 having count(*) > 1; COL1 COL2 COUNT(*) ---------- ---------- ---------- 100 200 2
-If in the case of duplicate records, you should see only the duplicates (according to some timestamp etc., you can use the functinon row_number analytic..)
1 select col1, col2 from ( 2 select col1, col2, 3 row_number() over (partition by col1, col2 4 order by message) rn 5 from temp_rajesh) 6* where rn > 1 sql> / COL1 COL2 ---------- ---------- 100 200
In the above example, I use message to order, you can replace it with activity_timestamp or the insertd_date according to your logic... when there are two records... one that you choose to duplicate.
Thank you
Rajesh.Published by: Rajesh Chamarthi on November 20, 2009 12:05 AM (added for example)
-
script can be invoked only from a java stored procedure
I made a java procedure and called via a sql procedure that accepts a string input:
the string is passed to Runtime.getRuntime () .exec ("myString");
If this string is:
RM-f /test/test22.log
proc = Runtime.getRuntime () .exec ("rm-f /test/test22.log");
the test22.log file that is located in the test folder is deleted
but when I place the order. /test/batchstart.ksh to run a script, the script does not run.
proc = Runtime.getRuntime ().exec(".) (' / test/batchstart.ksh ");
received the permissions of files and also the rights of the executables.
If some bobdy can say why the script is not running which will be a great helpHello
I had the chance to do something like the following without using oraenv
ORACLE_SID = GNVDEV
ORACLE_HOME=/U21/app/Oracle/product/10.2.0/Db_1/PATH = / usr/local/bin: $ORACLE_HOME/bin: $PATH
export PATHIn some cases affecting LD_LIBRARY_PATH to include the libs oracle was also necessary.
Another option is to simply use the full paths everywhere for example use
$ORACLE_HOME/bin/sqlplus instead of just sqlplus.Hope this helps,
Ravi. -
Deleting records from a table and trying to retrieve those
Hello
is it possible to recover the table deleted after validation of the track file, if so how? Once again I have to synchronize back to the database once the table is retrieved.Reverse GoldenGate utility.
details on this forum.
Reverse GoldenGate utility
Golden Gate can be a lever to make point in time recovery for MySql? -
Understanding stored procedures
Hello
Oracle 11.2.0.0.2
I am trying to learn how stored procedures to use them later in the future web applications. I was going through some documentation and found a simple stored procedure and I just wanted to see if someone could help to clarify if I understand how this stored procedure is supposed to work.
TRIGGER XXX_TEST CREATE create a trigger with the name of XXX_TEST
BEFORE INSERT Execute the trigger before it runs the command INSERT
ON f.w5 FOR EACH ROW, do something "for each line' which is 'on' the table w5 belonged f schema
START the starting point of the orders which will take place within this block
Select count (1) IN the rt of 1934_e.doc where: new. U0 = docnum and 'AA' = a1 and a2 = 'DR' and a3! = « Z »)) ; Select all the records and put new 'in' the variable doc table belonging to f, where rt. U0 variable equals the docnum and column a1 is equal to 'AA' and column a2 is equal to 'DR' and a3 is not equal to 'Z'
IF rt > 0 THEN conditional statement, if the rt variable is greater than 0, then below that
: new.pt: = 9 | substr (PT 2); concatenation of the variable which is set to match the 9
: new. U1: = 'UNFAIR '; sets the variable: new. U1: equal to 'EVIL'
END IF; end of the conditional statement
delete from f.w5 where substr (pt, 1, 1) = 9 and U1 = "UNFAIR." delete records from table w5 belonged to f where substring value 9 starting at position 1 with a length of 1 is equal to 9 and U1 is equal to 'FALSE'
END; the point of arrival of the "BEGIN"
The part that I'm not sure of is the IF / END IF block. I read that the | means the concatenation, but I don't really know what or why it is concatenation. Another explanation is appreciated! Thank you.
Hello
You have understood about correctly.
There are many errors in this code. For example, he referred to the local variables, rt and pt, but these variables are not defined anywhere. For example, in the assignment you intrigued plus:
: new.pt: = 9 | substr (PT 2);
: NEW.pt initially made reference (rightly) of a column in the current insertion, but pt near the end line (without: NEW.) reference a local variable and I do not see where all the local variables are currently reported. Perhaps the one who wrote this means use; NEW.pt in both places.
SUBSTR (pt, 2)
means the part of string pt starting with his 2nd character, so
'9' || SUBSTR (pt, 2)
a copy of the pt, but with its first character replaced by "9".
Why the trigger would do this? Your guess is as good as mine. Apparently, the pt of the column is a kind of code, and the first character of the code is supposed to be "9" If there is no line in the table corresponding to the column of u0, doc and met certain other conditions, at the point where this line was inserted.
(The | operator expected strings before and after it.) If you use a NUMBER, such as 9, in a place where one expects a string, such as '9', Oracle will automatically convert the NUMBER to a string, but it is advisable to use the correct data in type.)
Moreover, another error in this trigger is that he tries to DELETE rows from the same table that is based on. A FOR EACH ROW trigger on tble f.w5 can't even read other f.w5 lines, let alone delete them.
-
How to call a stored procedure with a REF CURSOR output parameter
I'm looking forward to example calling a function/stored procedure with a REF CURSOR output parameter and get the result.
In other words, I have a stored function/procedure that runs a SELECT statement using the OCI library and then he could get the values of each row and each column.
I put a code snippet, it have only the main thing to call a simple stored procedure and to print the name of each column of the cursor, but I couldn t to print out values in the table that calls the stored procedure.
I understand that the next step is to call an OCIStmtFetch.
How to associate the slider with the OCIStmtFetch?
If you need more information, just tell me.
I use ANSI C with HP - UX (HP - UX C) operating system and Oracle 10 g.
Kind regards.
Antonio Garcia
/ * callOracleSP * /.
#include < stdio.h >
#include < string.h >
#include < oci.h >
#include < stdlib.h > to
char * pConnectChar = "Server";
char * pUsernameChar = "user";
char * pPasswordChar = "passwd";
char * sqlCharArray1 = "BEGIN SP_GETCITIES (:,: c); END; « ;
int retval;
UB4 parmcnt = 0;
UB4 pos2 = 0;
text * pcoln [20];
UB4 namelen [20];
char state_key [5];
OCIStmt * pOciStatement;
OCIStmt * pOciStatCursor;
OCIError * pOciError;
OCIEnv * pOciEnviron;
OCIServer * pOciServer;
OCISession * pOciSession;
OCISvcCtx * pOciServiceContext;
OCIBind * pOciBind [500];
OCIParam * pOciParam;
int main()
{
retval = OCIEnvCreate (& pOciEnviron, OCI_DEFAULT, NULL, NULL, NULL, NULL, 0, NULL);
retval = OCIEnvInit (& pOciEnviron, OCI_DEFAULT, 0, NULL);
retval = OCIHandleAlloc (pOciEnviron, (void *) & pOciError, OCI_HTYPE_ERROR, 0, NULL);
retval = OCIHandleAlloc (pOciEnviron, (void *) & pOciServiceContext, OCI_HTYPE_SVCCTX, 0, NULL);
retval = OCIHandleAlloc (pOciEnviron, (void *) & pOciStatement, OCI_HTYPE_STMT, 0, NULL);
retval = OCILogon (pOciEnviron, pOciError, & pOciServiceContext,(unsigned char *) pUsernameChar,
strlen (pUsernameChar), (unsigned char *) pPasswordChar, strlen (pPasswordChar).
(unsigned char *) pConnectChar, strlen (pConnectChar));
printf ("retval=%d\n",retval OCILogon);
retval = OCIStmtPrepare (pOciStatement, pOciError, (unsigned char *) sqlCharArray1, strlen (sqlCharArray1),)
OCI_NTV_SYNTAX, OCI_DEFAULT);
printf ("StmtPrepare retval=%d\n",retval);
retval = OCIHandleAlloc (pOciEnviron, (void *) & pOciStatCursor, OCI_HTYPE_STMT, 0, NULL);
retval = 1 OCIBindByPos(pOciStatement,&pOciBind[0], pOciError, (ub4), (void *) & state_key,)
((sb4) sizeof (state_key), SQLT_STR, (void *) 0, (ub2 *) 0, (ub2 *) 0, (ub4) 0, (ub4 *) 0, OCI_DEFAULT (ub4));
printf ("BindByPos OCI_HTYPE_STMT retval=%d\n",retval);
retval = OCIBindByPos(pOciStatement,&pOciBind[1], pOciError, (ub4) 2, (void *) & pOciStatCursor,)
((sb4) 0, SQLT_RSET, (void *) 0, (ub2 *) 0, (ub2 *) 0, (ub4) 0, (ub4 *) 0, OCI_DEFAULT (ub4));
printf ("BindByPos OCI_HTYPE_STMT retval=%d\n",retval);
strcpy (state_key, 'ca');
retval = OCIStmtExecute (pOciServiceContext, pOciStatement, pOciError, (ub4) 1, (ub4) 0,)
(OCISnapshot *) NULL, (OCISnapshot *) NULL, OCI_DEFAULT (ub4));
printf ("StmtExecute retval=%d\n",retval);
/ * How to get the values of the cursor? */
/ * Number of parameters of the cursor * /.
OCIAttrGet ((void *) pOciStatCursor, OCI_HTYPE_STMT (ub4), (void *) & parmcnt,(ub4 *) 0,)
(ub4) (OCI_ATTR_PARAM_COUNT, pOciError);
printf ("\nNumber of the slider settings = %d\n",parmcnt);
for (int pos = 1; pos < = (int) parmcnt; pos ++)
{
OCIAttrGet ((void *) pOciStatCursor, OCI_HTYPE_STMT (ub4), (void *) & pos2,(ub4 *) 0,)
(ub4) (OCI_ATTR_CURRENT_POSITION, pOciError);
retval = OCIParamGet ((void *) pOciStatCursor, OCI_HTYPE_STMT (ub4), pOciError, (void *) & pOciParam,)
POS (ub4));
OCIAttrGet pOciParam, (ub4) ((void*) OCI_DTYPE_PARAM,(void*) & pcoln [pos - 1],(ub4 *) & namelen [pos-1],)
(ub4) OCI_ATTR_NAME,(OCIError *) pOciError);
}
for (int i = 1; i < = (int) parmcnt; i ++)
printf ("%i\tNAME = % column. ("* s\n", i, namelen [i-1], pcoln [i-1]);
return 0;
}
This is the script that create the table, insert records and create the stored procedure
CREATE TABLE CITIES)
STATE_CODE VARCHAR2 (2) NULL,
CITY_CODE NUMBER (15.5) NULL,
CITY_NAME VARCHAR2 (30) NULL
)
/
INSERT INTO CITIES (STATE_CODE, CITY_CODE, CITY_NAME)
VALUES ('CA', 30, 'SAN DIEGO')
/
INSERT INTO CITIES (STATE_CODE, CITY_CODE, CITY_NAME)
VALUES ('CA', 40 'SACRAMENTO')
/
INSERT INTO CITIES (STATE_CODE, CITY_CODE, CITY_NAME)
VALUES ('FL', 10, 'MIAMI')
/
INSERT INTO CITIES (STATE_CODE, CITY_CODE, CITY_NAME)
VALUES ('FL', 20, 'ORLANDO')
/
INSERT INTO CITIES (STATE_CODE, CITY_CODE, CITY_NAME)
VALUES ('NEW YORK', 10, 'NEW YORK')
/
INSERT INTO CITIES (STATE_CODE, CITY_CODE, CITY_NAME)
VALUES ('NEW YORK', 20, 'ALBANY')
/
INSERT INTO CITIES (STATE_CODE, CITY_CODE, CITY_NAME)
VALUES ('CA', 10, 'LOS ANGELES')
/
INSERT INTO CITIES (STATE_CODE, CITY_CODE, CITY_NAME)
VALUES ('CA', 20, 'SAN FRANCISCO')
/
CREATE or REPLACE PACKAGE globalPkg AUTHID CURRENT_USER AS
/ * The following is specific global variables T/SQL. */
TYPE RCT1 IS REF CURSOR; / * new cursor low definition * /.
END globalPkg;
/
CREATE OR REPLACE PROCEDURE SP_ADDCITY)
P_STATE_CODE IN VARCHAR,
P_CITY_CODE NUMBER,
P_CITY_NAME IN VARCHAR2,
P_RETURN IN NUMBERS)
AS
StoO_error INTEGER;
StoO_selcnt INTEGER;
StoO_rowcnt INTEGER;
StoO_errmsg VARCHAR2 (255);
BEGIN
StoO_rowcnt: = 0;
StoO_error: = 0;
StoO_selcnt: = 0;
P_RETURN: = 0;
INSERT INTO CITIES (STATE_CODE, CITY_CODE, CITY_NAME)
VALUES (P_STATE_CODE, P_CITY_CODE, P_CITY_NAME);
StoO_rowcnt: = number of LINES SQL %;
EXCEPTION
WHEN TOO_MANY_ROWS THEN
StoO_rowcnt: = 2;
WHILE OTHERS THEN
StoO_rowcnt: = 0;
StoO_selcnt: = 0;
StoO_error: = SQLCODE;
StoO_errmsg: = SQLERRM;
IF StoO_error! = 0 THEN
BEGIN
P_RETURN: = 1;
RETURN;
END;
END IF;
END;
/
CREATE OR REPLACE PROCEDURE SP_GETCITIES)
STATE_KEY IN VARCHAR,
RC1 IN OUT globalPkg.RCT1)
AS
StoO_error INTEGER;
StoO_selcnt INTEGER;
StoO_rowcnt INTEGER;
StoO_errmsg VARCHAR2 (255);
BEGIN
StoO_rowcnt: = 0;
StoO_error: = 0;
StoO_selcnt: = 0;
OPEN FOR RC1
SELECT STATE_CODE, CITY_CODE, FRANCISCO
CITIES
WHERE STATE_CODE = STATE_KEY
ORDER BY CITY_CODE;
StoO_rowcnt: = number of LINES SQL %;
EXCEPTION
WHILE OTHERS THEN
StoO_rowcnt: = 0;
StoO_error: = SQLCODE;
StoO_errmsg: = SQLERRM;
END;
/Hi Antonio,.
I see this:
c_buf=(ub1 **)calloc(sizeof(ub1 *),3); ... rc=OCIDefineByPos(pOciStatCursor,&pdef,(OCIError *)pOciError,pos,c_buf[pos-1],size+1,(ub2)type,(dvoid *)c_indp[pos-1],(ub2 *)0,(ub2 *)0,OCI_DEFAULT);
That I don't understand. You allocate space for 3 pointers ub1 but I don't see where these pointers are then initialized to point to where the data is to be stored.
I do not read correctly?
Sorry for posting code long, but here is an example of code that I have. It is much more 'code' for your code, but maybe that will be enough...
NOTE: This is just the code example and not rigorous. For example, I don't check the memory, allocations etc in this code!
Kind regards
Mark
#ifdef WIN32 #define _CRT_SECURE_NO_DEPRECATE 1 #endif #include
#include #include #include void checkerr(sword status, OCIError *errhp); int main(int argc, char *argv[]) { OCIEnv *envhp = NULL; /* OCI Environment handle */ OCIError *errhp = NULL; /* OCI Error handle */ OCISvcCtx *svchp = NULL; /* OCI Service Context handle */ OCIServer *srvhp = NULL; /* OCI Server handle */ OCISession *usrhp = NULL; /* OCI User Session handle */ OCIStmt *stmtp = NULL; /* OCI Statement handle */ OCIStmt *cursr = NULL; /* OCI Statement handle */ OCIParam *prmp1 = NULL; /* OCI Parameter handle */ OCIParam *prmp2 = NULL; /* OCI Parameter handle */ OCIParam *prmp3 = NULL; /* OCI Parameter handle */ OCIDefine *defp1 = NULL; /* OCI Define handle */ OCIDefine *defp2 = NULL; /* OCI Define handle */ OCIDefine *defp3 = NULL; /* OCI Define handle */ OCIBind *bndp1 = NULL; /* OCI Bind handle */ OCIBind *bndp2 = NULL; /* OCI Bind handle */ OCIBind *bndp3 = NULL; /* OCI Bind handle */ /* used to hold column width */ ub2 col_width; /* used to set the prefetch count */ ub4 prefetch_count = 32; /* will hold output from database */ oratext *pEmpId = NULL; oratext *pFirstName = NULL; oratext *pLastName = NULL; /* the anonymous block to execute */ /* this opens a ref cursor */ oratext *sqlstmt = "begin " \ " open :1 for " \ " select to_char(employee_id), " \ " first_name, " \ " last_name " \ " from hr.employees " \ " order by last_name, " \ " first_name; " \ "end;"; /* used to hold the results of each OCI call */ sword result = 0; /* Initialize and create a default environment */ result = OCIEnvCreate(&envhp, OCI_DEFAULT, (dvoid *) 0, 0, 0, 0, (size_t) 0, (dvoid **) 0); /* allocate an error handle */ result = OCIHandleAlloc((dvoid *) envhp, (dvoid **) &errhp, OCI_HTYPE_ERROR, 0, (dvoid **) 0); /* allocate a service context handle */ result = OCIHandleAlloc((dvoid *) envhp, (dvoid **) &svchp, OCI_HTYPE_SVCCTX, 0, (dvoid **) 0); /* allocate a server handle */ result = OCIHandleAlloc((dvoid *) envhp, (dvoid **) &srvhp, OCI_HTYPE_SERVER, 0, (dvoid **) 0); /* allocate a user session handle */ result = OCIHandleAlloc((dvoid *) envhp, (dvoid **) &usrhp, OCI_HTYPE_SESSION, 0, (dvoid **) 0); /* create a server context using the "ORADEMO" database */ result = OCIServerAttach(srvhp, errhp, "ORADEMO", (ub4) strlen("ORADEMO"), OCI_DEFAULT); /* set the server attribute in the service context handle */ result = OCIAttrSet((dvoid *) svchp, OCI_HTYPE_SVCCTX, (dvoid *) srvhp, (ub4) 0, OCI_ATTR_SERVER, errhp); /* open the session with the database */ /* using external authentication */ result = OCISessionBegin(svchp, errhp, usrhp, OCI_CRED_EXT, OCI_DEFAULT); /* set the user session attribute in the service context handle */ result = OCIAttrSet((dvoid *) svchp, OCI_HTYPE_SVCCTX, (dvoid *) usrhp, (ub4) 0, OCI_ATTR_SESSION, errhp); /* allocate the statement handle */ result = OCIHandleAlloc((dvoid *) envhp, (dvoid **) &stmtp, OCI_HTYPE_STMT, 0, (dvoid **) 0); /* prepare the statement for execution */ result = OCIStmtPrepare(stmtp, errhp, sqlstmt, (ub4) strlen((char *) sqlstmt), OCI_NTV_SYNTAX, OCI_DEFAULT); /* allocate the handle for the ref cursor */ result = OCIHandleAlloc((dvoid *) envhp, (void **) &cursr, OCI_HTYPE_STMT, 0, NULL); /* bind the ref cursor parameter */ result = OCIBindByPos(stmtp, &bndp1, errhp, 1, &cursr, 0, SQLT_RSET, NULL, 0, NULL, 0, 0, OCI_DEFAULT); /* execute the statement */ result = OCIStmtExecute(svchp, stmtp, errhp, 1, 0, NULL, NULL, OCI_DEFAULT); /* get parameter descriptor for first column */ result = OCIParamGet((dvoid *) cursr, OCI_HTYPE_STMT, errhp, (dvoid **) &prmp1, (ub4) 1); /* get parameter descriptor for second column */ result = OCIParamGet((dvoid *) cursr, OCI_HTYPE_STMT, errhp, (dvoid **) &prmp2, (ub4) 2); /* get parameter descriptor for third column */ result = OCIParamGet((dvoid *) cursr, OCI_HTYPE_STMT, errhp, (dvoid **) &prmp3, (ub4) 3); /* get the first column width in characters */ result = OCIAttrGet((dvoid*) prmp1, (ub4) OCI_DTYPE_PARAM, (dvoid*) &col_width, (ub4 *) 0, (ub4) OCI_ATTR_DATA_SIZE, errhp); /* allocate memory to hold the result */ pEmpId = (oratext *) malloc(sizeof(oratext) * (col_width + 1)); /* define the first column in the results */ result = OCIDefineByPos(cursr, &defp1, errhp, 1, (dvoid *) pEmpId, (sword) col_width + 1, SQLT_STR, (dvoid *) NULL, (ub2 *) 0, (ub2 *) 0, OCI_DEFAULT); /* get the second column width in characters */ result = OCIAttrGet((dvoid*) prmp2, (ub4) OCI_DTYPE_PARAM, (dvoid*) &col_width, (ub4 *) 0, (ub4) OCI_ATTR_DATA_SIZE, errhp); /* allocate memory to hold the result */ pFirstName = (oratext *) malloc(sizeof(oratext) * (col_width + 1)); /* define the second column in the results */ result = OCIDefineByPos(cursr, &defp2, errhp, 2, (dvoid *) pFirstName, (sword) col_width + 1, SQLT_STR, (dvoid *) NULL, (ub2 *) 0, (ub2 *) 0, OCI_DEFAULT); /* get the third column width in characters */ result = OCIAttrGet((dvoid*) prmp3, (ub4) OCI_DTYPE_PARAM, (dvoid*) &col_width, (ub4 *) 0, (ub4) OCI_ATTR_DATA_SIZE, errhp); /* allocate memory to hold the result */ pLastName = (oratext *) malloc(sizeof(oratext) * (col_width + 1)); /* define the third column in the results */ result = OCIDefineByPos(cursr, &defp3, errhp, 3, (dvoid *) pLastName, (sword) col_width + 1, SQLT_STR, (dvoid *) NULL, (ub2 *) 0, (ub2 *) 0, OCI_DEFAULT); /* loop through and print the results */ while ((result = OCIStmtFetch(cursr, errhp, (ub4) 1, (ub2) OCI_FETCH_NEXT, (ub4) OCI_DEFAULT)) == OCI_SUCCESS) { printf("Employee ID: %s\n", pEmpId); printf(" First Name: %s\n", pFirstName); printf(" Last Name: %s\n\n", pLastName); } /* free allocated memory */ free(pEmpId); free(pFirstName); free(pLastName); pEmpId = NULL; pFirstName = NULL; pLastName = NULL; /* terminate the session with the database */ result = OCISessionEnd(svchp, errhp, usrhp, OCI_DEFAULT); /* detach from the server */ result = OCIServerDetach(srvhp, errhp, OCI_DEFAULT); /* deallocate the environment handle */ /* OCI will deallocate the child handles */ result = OCIHandleFree((dvoid *) envhp, OCI_HTYPE_ENV); return OCI_SUCCESS; } void checkerr(sword status, OCIError *errhp) { oratext errbuf[512]; sb4 errcode = 0; switch (status) { case OCI_SUCCESS: break; case OCI_ERROR: case OCI_SUCCESS_WITH_INFO: (void) OCIErrorGet((dvoid *) errhp, (ub4) 1, (oratext *) NULL, &errcode, errbuf, (ub4) sizeof(errbuf), OCI_HTYPE_ERROR); (void) printf("Error: %.*s\n", sizeof(errbuf), errbuf); break; case OCI_NEED_DATA: (void) printf("Error - OCI_NEED_DATA\n"); break; case OCI_NO_DATA: (void) printf("Error - OCI_NO_DATA\n"); break; case OCI_INVALID_HANDLE: (void) printf("Error - OCI_INVALID_HANDLE\n"); break; case OCI_STILL_EXECUTING: (void) printf("Error - OCI_STILL_EXECUTING\n"); break; case OCI_CONTINUE: (void) printf("Error - OCI_CONTINUE\n"); break; default: break; } } -
delete records that are related to another table
I want to delete records from a table (A), these recordings has a relationship with another table (B)
using a query to set these records is that I want to delete
with B as
(
f select '2', '3' l double
Union of all the
f select '2', '3' l double
Union of all the
f select '4', '4' l double
)
Select * from A, B
where B.f() > 3 and b. > 3
and A.f. = B.f()
and A.l = b.
Oracle Database 11 g Enterprise Edition Release 11.1.0.7.0 - 64 bit Production
Thanks in advance!Hello
Here's one way:
DELETE a WHERE f > 3 AND l > 3 AND (f, l) IN ( SELECT f, l FROM b ) ;
-
Run the stored procedure of c#
Hi, im new to the use of stored procedures and I have the following stored procedure...
CREATE OR REPLACE PROCEDURE DRL_PROCEDURE2 (var_SOURCE_OBJECTID IN varchar2, var_NEW_OBJECTID OUT varchar2)
AS
BEGIN
SELECT MAX (NEW_OBJECTID)
IN var_NEW_OBJECTID
OF DRL_CONVERSION
WHERE SOURCE_OBJECTID = var_SOURCE_OBJECTID;
END;
I want to be able to call this procedure from my windows form application and display the result of the stored procedure in a label... could someone please help me! Thanks in advance!http://www.csharpfriends.com/articles/getarticle.aspx?articleid=78
You can find out how to call the stored procedure (in the link above you will find an example of SQL Server 2005 that also work for you from your oracle stored procedure) in c#.HTH
Girish Sharma -
Impossible to delete the record from the table using the form
I have a stored procedure (function, actually) that allows an administrator to manually delete a record in a table.
When I call my form there will be no effect. The record remains in the table.
In both cases, I connect to the database to the same user.
I am able to call a test function in the database which returns a field in the record, so I think I can at least communicate with and retrieve results from the database using a stored function. As soon as I approach him "select" "delete from", no luck.
If I try to run the SQL in my form with a statement of FORMS_DDL, it seems to run smoothly when I not in the code in the debugger, but it had no effect. FORMS_SUCCESS reports TRUE if DBMS_ERROR_TEXT has the following: ORA-01403: no data found. I don't know how the DBMS_ERROR_TEXT is that FORMS_SUCCESS is not set to FALSE.
Any ideas as to why I am unable to remove using my form but can when you call the function registered directly/manually?
Using Oracle Forms & DB 10.0.2.0.1.Patrick,
After each Insert / Update / Delete statement, you have to COMMIT . Then only it will be in select statements.
Kind regards
Manu.
Maybe you are looking for
-
Here is my code: < script src = "" / 1337.js "type =" text/javascript"language ="javascript"> < / script >"It is included and my page works on all browsers, but firefox (Ubuntu). What is wrong with him? EDIT *. I fixed it. It turns out that it was a
-
Satellite L500-1XL - rejecting playing a USB device and music jump
Hi all Has anyone else had problems above? Even for other laptop models? So today it keeps rejecting the USB devices, but has accepted two just now - but rejecting the rest. I rebooted several times and no use. Reading music continues to jump, it sou
-
Tecra R840 - which partitions can I delete?
Hello I installed a Plextor M5P 512 GB ssd in my Tecra R840-16J! I'm very happy with it :-)Restore laptop to factory state using the recovery DVDs I created before! Now, I have 2 copies and a 16 GB USBFlash with an extra copy! So I can restore to fac
-
Forgotten password user for Satellite P100-313
Hi@all,I forgot the password of the user for Satellite P100-313. Can I remove the password without professional help. Please help me. Good bye
-
which is a transparent lock double 2-bit bistable IC in multisim edition of analog devices
I need an equivalent IC for CD74HC75, which is a double 2-bit transparent latch IC for a simulation project. Can't find it in the reference guide of Multisim. Any suggestions?