SQL & PL/SQL :: Count And Delete Statements

Sep 14, 2011

I am new to oracle programming.

I have a statement below

The statement below correctly filters the records that I require.. I now want to;

Count the number of records that meet the criteria and Delete the records that meet the criteria

select
sl.project_code,
sl.COST_code,
sl.category_code,
sl.supplier_code,

[Code]....

View 5 Replies


ADVERTISEMENT

PL/SQL :: How To Use CASE And COUNT Statements In SELECT QUERY

Oct 13, 2012

I want to count the batch records using BATCH_ID with CASE statement ,for that i am using below query but its not working ,

SELECT COUNT(*) FROM <TABLENAME> WHERE VNBATCH_ID=CASE WHEN #SDC <10 AND #PERIOD >=10 THEN
0||#SDC||#PERIOD||#BATCH_ID
WHEN #SDC <10 AND #PERIOD <10 THEN
0||#SDC||0||#PERIOD||#BATCH_ID
WHEN #SDC >=10 AND #PERIOD <10 THEN
#SDC||0||#PERIOD||#BATCH_ID
ELSE
#SDC||#PERIOD||#BATCH_ID
END

View 11 Replies View Related

SQL & PL/SQL :: Procedure Has Got Several Update And Delete Statements

Oct 23, 2013

One of the procedures that am working on is failing with ORA-0000: normal, successful completion error.

The procedure has got several update and delete statements and have logging enabled after each step. The problem with that again is, each time the log table gets updated thereby losing the history of until what point the procedure ran successfully.I have this issue only in production environment and unable to simulate it in dev environment which limits my options of troubleshooting the procedure code. I was using SQLERRM in the code.

Is there a way I can identify the bad records/ record causing this issue? Am very new to PL/SQL and do not know how to proceed with this.How do you debug this sort of issues??(where one procedure internally invokes another one which again invokes other one etc)

View 27 Replies View Related

Server Administration :: Delete Statements UseTemp Tablespace?

Jun 16, 2011

Why large delete statements, with no where clauses, could be using up temp tablespace segments? I thought temp tablespace was just for sort operations,joins, etc.

We have a weekly job that inserts rows into a staging table, deletes, with commit, the a few minutes later and repeats the process. Each delete is using some of the temp tablespace. Eventually we run out of space (ora-01652). That's another thing. I would have thought the space would be released for the next process, but it's now.

SNAP_TIME USERNAME SESSION_ADDR SESSION_NUM MB SQLHASH SQLADDR SQL_TEXT
2011-06-15; 19:10 SCHEMA_USER 0700000209286B00 49680 980 3165065004070000020A8F9F20 DELETE FROM SCHEMA.FIN_RECORDS_TO_EVAL
2011-06-15; 19:15 SCHEMA_USER 070000020F2A7670 10601 275 3165065004070000020A8F9F20 DELETE FROM SCHEMA.FIN_RECORDS_TO_EVAL
2011-06-15; 19:20 SCHEMA_USER 070000020925FE38 19368 4748 3165065004070000020A8F9F20 DELETE FROM SCHEMA.FIN_RECORDS_TO_EVAL
2011-06-15; 19:25 SCHEMA_USER 070000020925FE38 19368 15783 3165065004070000020A8F9F20 DELETE FROM SCHEMA.FIN_RECORDS_TO_EVAL

We will probably switch to truncate statements, but this situation really puzzles me. I've tried view the docs but don't see any of delete statements using temp tablespace.

View 2 Replies View Related

SQL & PL/SQL :: Bulk Delete With Total Count

Feb 24, 2009

I have a table A which has million records, and one of the column is a date. All records prior to 01-FEB-2009 should be deleted.

I cannot run the below code considering the amount of records or rows in the table A.

Begin
Delete from A where trunc(date_column) < '01-FEB-2009';
commit;
End;

where we can delete the rows prior to 01-FEB-2009 and also have a total count of how many were deleted?

View 14 Replies View Related

SQL & PL/SQL :: Delete After Count Oldest Row Query?

Mar 22, 2011

I have one table that have many records. For the maintenance purpose I like to delete old record based on Customer No.-That is Mobile NO.If each Customer have more than 300 records, I like to delete by everyday batch process.can't figure out how to apply each Customer No.(Specific Column), I could sort (order by few column - SAVE_DT or SMS_ARV_CLC) how to write this kind of query? I try rownum but no more progress.

Here is my table
CREATE TABLE TM_060_SMS_TEST
(
SMS_SEQ VARCHAR2(18 BYTE),
SMS_RCV_CLC VARCHAR2(14 BYTE),
CUST_NUM VARCHAR2(12 BYTE),

[code]...

View 12 Replies View Related

SQL & PL/SQL :: Delete After Count Oldest Row Query BULK

Mar 24, 2011

I like to increase speed to delete our table. Is it possible to use BULK COLLECT or FORALL this query? This is not single delete or select, maybe I got the error? Is it possible to use BULK method to this query?

delete from
TM_060_SFS_TEST
WHERE
rowid in (
SELECT
[code]......

View 1 Replies View Related

SQL & PL/SQL :: Procedure To Delete Records / Count Number Of Records Has Been Deleted

Feb 21, 2011

I have written the following PL/SQL procedure to delete the records and count the number of records has been deleted.

CREATE OR REPLACE PROCEDURE Del_emp IS
del_records NUMBER:=0;
BEGIN
DELETE
FROM candidate c
WHERE empid in
(select c.empid
from employee e,
candidate c
where e.empid = c.empid
and e.emp_stat = 'TERMINATED'
);
[code]....

View 6 Replies View Related

SQL & PL/SQL :: Insert Statements / Give A Commit One By One After Each Insert Statements?

Oct 11, 2012

Can we execute more than one insert statements at a time (eg 10) in database and givecommit at the end of insert statements or else give a commit one by one after each insert statements ?

View 8 Replies View Related

PL/SQL :: To Delete Child Records Manually Without Using Oracle Delete Cascade

Oct 9, 2012

I have to write a procedure that accepts schema name, table name and column value as parameters....I knew that i need to use metadata to do that deleting manually.

View 9 Replies View Related

SQL & PL/SQL :: Difference Between Count(*) And Count(1)?

Nov 16, 2009

When we execute select count(*) from table_name it returns the number of rows.

What does count(1) do? What does 1 signifies over here? Is this same as count(*) as it gives the same result on execution?

View 13 Replies View Related

SQL & PL/SQL :: Difference Between Count(1) And Count(*)

Nov 24, 2011

difference between count(1) and count(*). As i know count(*) will give number of rows irrespective of null and count(1) will not count the null.My Oracle version is 10 g.

SQL> select * from t1;

A B C
---------- -------------------- --------------------
1 2 3
2
5

SQL> select rownum,a.* from t1 a;

ROWNUM A B C
---------- ---------- -------------------- --------------------
1 1 2 3
2 2
3 5
4
[code]....

View 3 Replies View Related

Import CSV Using SQL Statements

Jun 9, 2011

I know, importing a *.CSV-table is easy using a few clicks with the GUI, but I want to know, how to import and create new tables, using the existing *. CSV-files, with SQL statements.

how to import a .CSV-file using SQL-statements?

View 7 Replies View Related

SQL & PL/SQL :: IF / THEN Statements With Different Datatypes

Sep 30, 2011

I have a column in a database that contains both numerical and char data. I would like to be able to do two different things (two different queries)

1. divide the numerical data in the column by 10 and leave the char data alone (just return it)

2. detect the numerical data in the column and treat is as a different value so I can run averages & counts on it while disregarding the char data

I'm not at all sure how to do number 2. I thought a CASE statement would work for number 1, but then I realized CASE doesn't like different datatypes:

select
case when '1234' = 'checked' then 'checked'
when '1234' = 'gen.nograde' then 'gen.nograde'
when '1234' = null then null
else '1234'/10 end as "GRADE"
from dual

Error report:
SQL Error: ORA-00932: inconsistent datatypes: expected CHAR got NUMBER
00932. 00000 - "inconsistent datatypes: expected %s got %s"

View 4 Replies View Related

SQL & PL/SQL :: Getting Insert Statements

Feb 26, 2010

I have a read access on all the 200+ tables in a schema, How can i generate 200+ .sql files with insert statements on all the tables of schema.

View 13 Replies View Related

Concatenating Two Select Statements

Oct 23, 2009

Been trying to concatenate the following two select statements (to then pass as a parameter in DML statement) without much luck.

Select lpad(ST_DAY,'2',0) || '/' || lpad(ST_MONTH,'2',0) from RET_FORMATS;

Select to_char(sysdate,'YYYY')"Year" FROM DUAL;

View 1 Replies View Related

Find Out What SQL Statements Currently Running

Feb 26, 2009

From database server, I need to monitor the details about the sql statements which are being currenlt running in client machines.

I tried with V_$SQLTEXT view where I can only see the SQL statements, hash value,address,SQL_id. but I'm not able to get the user name,name the client machine .

find out these details?.Which Data Dictionary i need to use ?.

View 2 Replies View Related

SQL Statements Behind Self Service Page?

Aug 29, 2011

I have a question regarding the SQL statements embedded behind the Self Service Pages in Oracle Applications.

Taking an example of Oracle E-business Suite, Is there a way to check what SQL statement is hard coded or embedded in a particular required Self Service Page?

View 1 Replies View Related

SQL Either Or Statements In Third-party Software

Dec 27, 2010

I'm in a bit of a pickle with some SQL syntax, and while my Oracle-fu is weak, an associate with SQL skills is also stuck. I am developing a database for my department that is backed by Oracle Enterprise 11g and the front end is ChemAxon (basically, chemistry database software). The short of it is that I have one large table with every compound from different groups. Each row has a flag (column PI) on it that indicates which group it belongs to (let us say 'Smith' and 'Jones' for example). The software can apply row-level filtering which will basically only show the rows that a particular username are allowed to see.

I have a FLAG_TABLE table, which contains two columns: USERNAME and FLAG. An example set up is this:

USERNAME FLAG
------------- ----------
smith_minion Smith
jones_minion Jones
jones_minion Smith

The software automatically applies a SQL filter that begins with:

SELECT DISTINCT CHEMAXON.STRUCTURES."ID" FROM CHEMAXON.STRUCTURES WHERE

I can set up filtering to work dandy, such that when smith_minion logs in, he can only see rows with the Smith flag (or jones_minion can see both Jones and Smith) by using the filter:

STRUCTURES.PI IS NULL or STRUCTURES.PI IN(SELECT ALL FLAG from FLAG_TABLE where USERNAME = '__IJC_USERNAME__')

('__IJC_USERNAME__' is how the third party software passes the logged in username into SQL)

But we have a new problem: there also exists a master user (chemaxon) who needs to see every row no matter what the flag. The row filtering is applied no matter who logs on, so we need to set up the SQL filter to basically say "If chemaxon, then select all rows, otherwise, select rows based on the username". This is proving a problem as the select statement must be prefaced with SELECT DISTINCT CHEMAXON.STRUCTURES."ID" FROM CHEMAXON.STRUCTURES WHERE.

I've tried using DECODE in a few capacities, but I am always thwarted. My last attempt was:

STRUCTURES.PI IS NULL or STRUCTURES.PI IN (DECODE('__IJC_USERNAME__','chemaxon',(!='something'),(SELECT ALL FLAG from FLAG_TABLE where USERNAME = __IJC_USERNAME__));

But this throws a ORA-00936 missing expression error, with a * under the != portion (I test it by replacing '__IJC_USERNAME__' with 'CHEMAXON').

View 3 Replies View Related

SQL & PL/SQL :: Using $ Substitution In Select Statements?

Oct 11, 2011

Is it possible to have $ substitutions in Select statements ?

For example

Select * from my_table where ID in ${ID_LIST} and DAY >= to_date(${SOME_DATE})
$ID_LIST = (100,200,300)
$SOME_DATE = 10-10-2011 12:12:00

For the ID_LIST is using Prepared statements with ?,?,? the way to go ? Or are there are any Define we can do in SQL plus for this substitions ?

View 2 Replies View Related

SQL & PL/SQL :: Syntax For Oracle Statements

Apr 26, 2011

The link from where I can get syntax of all the commands available in oracle?

View 6 Replies View Related

SQL & PL/SQL :: DML Statements - How Does Merge Works

Jul 23, 2013

My teacher taught the lesson of DML statemnts, he told us how does merge works , but he did not give us any query for that,provide query for Merge and if possible then explain it too , I am using Oracle 10g Sql Plus.

View 3 Replies View Related

DDL Statements Fail Or Not When DML Active?

Dec 9, 2011

DDL statements automatically end with COMMIT the user transactions in which they appear. Foe example:

-------------------------------------------
create table mytable01 (i integer);
insert into mytable01
select 1 from dual;
create table mytable02 (i integer);
-------------------------------------------

After all three statements are executed, data are committed in mytable01.

In the Oracle DB server SQL guide we read:

"DDL commands, such as TRUNCATE, will fail if there is any DML command active on the table. A transaction will block the DDL command until the DML command is terminated with a COMMIT or a ROLLBACK."

But I executed the following without any problem:

-------------------------------------------
create table mytable (i integer);
insert into mytable
select 1 from dual;
commit;
update mytable
set i = 2;
alter table mytable add (j integer);
-------------------------------------------

So where's the truth? Are DDL statements blocked when they refer to an active object accessed from a DML or not?

View 5 Replies View Related

SQL & PL/SQL :: 2 Insert Statements For 1 For Loop

Oct 30, 2013

Can we have 2 insert statements for 1 for loop? how can we have 2 insert statements into 1 for loop!

FORALL j IN stu.FIRST .. stu.LAST
insert into CHASSISM_test
(make, stu, invoiceno, gross_tot, discount)
values
(make(j), stu(j), INVOICEno(j), GrossTot(j), discount(j));

[Code]...

View 10 Replies View Related

SQL & PL/SQL :: Min Max - Create And Insert Statements?

Oct 4, 2010

I don't have development env .create and insert statements work below for sample data:

View 8 Replies View Related

Cannot View Database Or Run Select Statements

Jun 7, 2011

I have been out of work for 2+ years. Am about to start a job next week doing Oracle back end, Forms, and Reports development among other things. I was asked if I could take a look at 3 report requirements and give an estimate on how long it would take to correct errors in these reports. All I have is a user requirement document stating what the report is currently doing and what it should be doing, a partial screen print of an Oracle Form showing correct data, and a sample report page showing incorrect data.

I am finding it rather difficult to give an estimate without seeing tables, relations, code, etc. Is it me or does this seem nearly impossible?I do not have access to their system yet so cannot view the database or run select statements, run the report, etc. All I have are the documents I listed above.

View 3 Replies View Related

DB Upgrade From 11.1 To 11.2 - SQL Statements Running For Hours

Feb 16, 2011

Recently we have upgraded from 11.1 to 11.2 . But after upgrade SQL statements that are running fine in 11.1 was running for hours in 11.2. Statistics are collected 100%...

View 2 Replies View Related

When Are Statements Within Stored Procedure Compiled

Jul 23, 2010

connect the following concepts/information I've been collecting. This is not my field but I'm interested in filling some of mine conceptual/technical gaps.

From a JDBC perspective, one of the benefits of Prepared (and so Callable) statements have over the regular ones is that the statement is "compiled"(*) once and then reused (performance gain).

(*) for SQL statements: building of parse tree and exec.plan

In which way can this notion be extrapolated to invocation of Oracle Stored Procedures through CallableStatements? (After clearing my doubts, I may end concluding that the only relevant feature of CallableStatements is their capacity to deal with stored procedure invocations)

According to procedure's precompiled execution plan SQL compilation implies execution plans generation PL/SQL compilation implies P-code generation and, SQL statements (from PLSQL code) are treated no differently by Oracle than SQL from Java or C/C++. These SQLs will be parsed and execution plans for those SQLs created.
...
When the PL code executes the SQL statement, only then does the SQL engine receive the SQL, parse it, and create an execution plan for it.

Therefore, even when the stored procedure can be parsed and cached in SGA (through the OracleConnection.preparedCall("proc") invocation), the SQL statements won't be effectively compiled until they are executed, right? And going deeper, will those SQL statements be cached to be reused in future invocations of the containing stored procedure? Is this a characteristic of the regular stored procedure execution in Oracle? or is it due to the CallableStatement "origin"?

View 2 Replies View Related

Running Multiple Update Statements At Once

Feb 1, 2012

It started out pretty simple where I had to update about 40 contacts in the database and I would have 40 separate update statements I would run. The task has jumped to about 300 contacts and I don't want to run 300 update statements. I would like to run this all at once. For example:

update contact
set name = 'Name1'
where row_id = 'row_id1'

update contact
set name = 'Name2'
where row_id = 'row_id2'

update contact
set name = 'Name3'
where row_id = 'row_id3'

My DB is oracle 10, and TOAD is version 9.

View 1 Replies View Related

Auditing Unsuccessful Select Statements

Sep 3, 2013

I'm attempting to audit unsuccessful Select statements in order to trap a problem we're experiencing with our application. I have set the AUDIT_TRAIL initialization parameter to DB_EXTENDED, and bounced our database.

I've issued the AUDIT SELECT ANY TABLE WHENEVER NOT SUCCESSFUL command, and when I issue a SELECT statement as an application user, nothing appears in SYS.AUD$ even though the application has issued a select statement which returned no rows.

View 3 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved