PL/SQL :: Condition In Count Operation
Jul 25, 2012
I have a car table with the following attribute sale_code,model_car etc. the format of sale_code is year/number example when a client buy a car(model_car=mercedes) her code is 2012/0125.
I want to calculate the number of cars that were sold in the year of 2011 grouped by the model_car attribute.
select count (sale_code),model_car
from car
where sale_code like '2011%'
when I tested this query i received an error.
My question is :
how to resolve the issue when we use an attribute in where and we use the same attribute in count operation ?
View 9 Replies
ADVERTISEMENT
Jun 21, 2010
To count the number of rows to the below table entries with certain conditions
my table
col1(varchar2(4000)) col2(varchar2(10))
3-1808116101 3-Standard
3-1808312141 3-Standard
3-1808312061 3-Standard
3-1807714441 2-Significant
3-1808284201 2-Significant
3-1808278361 2-Significant
3-1808284111 3-Standard
3-1807714261 3-Standard
3-1807128371 3-Standard
3-1807128351 3-Standard
3-1808301721 2-Significant
3-1808301701 3-Standard
3-1808322501 2-Significant
where conditions:
1)need to take the count of rows(col1).where col2 value is 3 or 2 .
2)value 3 or 2 is extracted and conditioned in the query
View 13 Replies
View Related
Jun 28, 2013
i have two tables one as test_master and other one limit master.
test master table structure
ct_id ct_a ct_b ct_C ct_d ct_e...... etc
1 -- -- -- -- --
1 -- -- -- -- --
2 -- -- -- -- --
limit master structure
limit_id ct_a_limit ct_b_limit ct_c_limit ct_d_limit ct_e_limt ..... etc
1 -- -- -- -- -- -- -- --
2 -- -- -- -- -- -- -- --
ct_id and limit_id is match column used for mapping.
now i want the total count of no of records in test_master in which test_master column value not exceed limit master column limit value if any one column exceeds its limit then the same row will be in my count criteria.
how to achieve the same using sql/oracle query.
View 7 Replies
View Related
Nov 1, 2012
i want to count how many check boxes are chechked and if the check box is unchecked the count will decrease as soon as checkbox is check or uncheck.the number of chech boxes are depentdent on record set that are fetched from database.
View 2 Replies
View Related
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
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
Sep 8, 2011
run down of the implications of MERGE by ROWID in such a fashion:
CODE MERGE
INTO XXWT_AP_ACCRUALS_RECEIPT_F EXT
USING (
SELECT PO_DISTRIBUTION_ID,
[code]...
Can this lead to an "Unstable Set of Rows?". Is it possible for the ROWID's to change during the execution of this statement - meaning certain ROWIDs identified in the SELECT will not actually be updated when it comes to the MERGE operation?
Basically, is it sound practice to use ROWID to merge on - in cases where you dont have a WHEN NOT MATCHED condition?
View 8 Replies
View Related
Jun 12, 2013
I am using the dblink to merge the data. I am using the following merge statement.
merge into APP_USER.USR_NEW_RIGHTS@NEW_RIGHTS t
Using (select 'test' GRANTEE,'TESTxxx'ROLE from dual ) s
on (t.GRANTEE = s.GRANTEE and t.ROLE = s.ROLE)
when not matched then
insert (ID,GRANTEE,ROLE,XRIGHT,COMPANY,OWNER,TABLENAME)
values ('','test','TESTxxx',null, null, null, null);
I know that I have to set a commit and it's working when I insert information's with a normal insert statement via database link, but it seems that merging doesn't work.
View 1 Replies
View Related
Apr 29, 2010
What are all the DML operation can be done in DUAL table.?
View 5 Replies
View Related
Jun 12, 2013
I have a source view where I have some invalid records and those should be found based on codes present in another table.
For eg. from source the records come like
****************SIINNSFDFD****FDFDF2******8
**********TABLE****************FDFSFSSFASFAS********
and if my reference table has values
SIINNSFDFD
TABLE
then these values are present as substring in the particular column in the source view. So I need to flag those records. For every record, I need to check whether all the values present in the reference table matches or not. If it matches then it should be flagged.
I can use in operator as we are not checking for the exact match and we are checking whether that value is present anywhere in that column record.
Looping results in performance issue. We can use PL/SQL for this. As the source view is put into a ETL internal file.
View 2 Replies
View Related
May 5, 2010
i have created an file in my local system (sys name : System1). i have created a directory as below
SQL>CREATE DIRECTORY test_dir AS '\System1TEMP';
I gave rights as
SQL>GRANT ALL ON DIRECTORY TEST_DIR TO PUBLIC;
DECLARE
fileHandler UTL_FILE.FILE_TYPE;
BEGIN
IF utl_file.is_open(fileHandler) THEN
utl_file.fclose_all;
END IF;
[code]......
but while executing the above procedure, Invalid File Operation error occurs.
View 10 Replies
View Related
Dec 2, 2011
I want to create one sql script with the followings-
1.Show the values before the operation is performed
2.Display the values after the operation is performed.
How it can be done in a proper sql script format.
View 10 Replies
View Related
Apr 26, 2013
Frequently getting below error in alert log file. to sort out this issue.
Database: Active standby database
OS: Windows Server
Db Version: 11.2.0.2
Error:
***********************************************************************
Fatal NI connect error 12170.
VERSION INFORMATION:
TNS for 64-bit Windows: Version 11.2.0.2.0 - Production
Oracle Bequeath NT Protocol Adapter for 64-bit Windows: Version 11.2.0.2.0 - Production
[code]...
View 1 Replies
View Related
Feb 20, 2011
I am working on an SAP application migration project using Oracle 10.2.0.2 database. We are migrating the application from Windows to Solaris.
During the process we are facing problem with very slow insert operation on a particular table.The server's capacity is very good and so no resource bottleneck.
The table contains around 2,70,000 rows and inserting at around 100 rows per 10 seconds.
The table contains following data types.
SQL> desc SAPDATDB.CAF_GP_VALDEF;
Name Null? Type
----------------------------------------- -------- ----------------------------
VAL_UUID NOT NULL NVARCHAR2(34)
VAL_GUID NOT NULL NUMBER(10)
VAL_CLOB NCLOB
View 2 Replies
View Related
May 19, 2010
How do you refresh a datablock after DML operation(s) - INSERT, UPDATE or DELETE? I know "EXECUTE_QUERY" retrieves records, but what trigger do I use to automatically refresh the datablock after these operations - my form only has 1 datablock.
View 3 Replies
View Related
Apr 20, 2011
When I try to call a database procedure written in Oracle 8.1.7.4.0 with OUT parameter and COMMIT statement from my Oracle 10g environment, I am getting error like "ORA-02064: distributed operation not supported".
I cannot omit OUT/COMMIT statement from the procedure because it is also updating another table from called procedure. I have tried some solutions from my end, but it is not working and same error generating. Like:
1) Moved the update statement with COMMIT statement to another procedure and calling that procedure from main called procedure
2) Creating a job to run the newly created procedure and submit the job from called procedureetc.
View -1 Replies
View Related
Sep 19, 2011
I had added a new disk into disk group DATA1 with rebalance power of 5, it ran as estimated for about 2 days long, I can see the estimated time down to zero but the process never end.
The command used:
SQL> alter diskgroup DATA1 add disk '<path>' rebalance power 5;
Below is the disk status:
SQL> select group_number, disk_number, total_mb, free_mb, mount_status, header_status, state
from v$asm_disk where group_number=1 order by disk_number;
GROUP_NUMBER DISK_NUMBER TOTAL_MB FREE_MB MOUNT_S HEADER_STATU STATE
------------ ----------- ---------- ---------- ------- ------------ --------
1 0 1191626 314236 CACHED MEMBER NORMAL
1 1 1191626 314230 CACHED MEMBER NORMAL
1 2 1191626 314232 CACHED MEMBER NORMAL
1 3 1191602 314229 CACHED MEMBER NORMAL
1 4 1191626 314210 CACHED MEMBER NORMAL
1 5 1191626 314218 CACHED MEMBER NORMAL
1 6 1191626 314218 CACHED MEMBER NORMAL
1 7 1191602 314223 CACHED MEMBER NORMAL
1 8 1191626 314216 CACHED MEMBER NORMAL
1 9 1191626 314202 CACHED MEMBER NORMAL
1 10 1191626 314230 CACHED MEMBER NORMAL
[code]....
I've checked and follow the status for a few days more, it still running with EST_MINUTES=0. I think it was hang and never end.During the next few weeks, I've manually restarted the rebalance process by modifying its power to 6, 8, 10
SQL> alter diskgroup DATA1 rebalance power 10;
After every restart, the diskgroup rebalance again but has the same issue, never end.Here is the content in the alert log
NOTE: starting rebalance of group 1/0x9d2529a0 (DATA1) at power 5
Starting background process ARB0
Fri Sep 16 12:01:11 2011
ARB0 started with pid=15, OS id=21066
Starting background process ARB1
Starting background process ARB2
Fri Sep 16 12:01:11 2011
[code]....
As you can see, the rebalance process started 3 days ago, hanging till now
SQL> select group_number, operation, state, power, est_minutes from v$asm_operation;
GROUP_NUMBER OPERA STAT POWER EST_MINUTES
------------ ----- ---- ---------- -----------
1 REBAL RUN 5 0
View 3 Replies
View Related
Mar 11, 2010
I have a type to table where only few columns are SCD 2. Like address, city, zip.I wrote a code using cursor. But now the requirement is to replace the cursor .how to perform type 2 using Merge in oracle 10g or any better way to perform it without using cursor. Look the code which i have attached with cursor.
CREATE OR REPLACE PROCEDURE Proc_cp_jci_contract_dim_hist
IS
l_fun_ret_value NUMBER;
v_src_id NUMBER;
rec_jci_contract_dim jci_contract_dim%ROWTYPE;
rec_jci_contract_dim_hist jci_contract_dim_hist%ROWTYPE;
err_row VARCHAR2(4000);
ind NUMBER(1) := 1;
[code]....
View 2 Replies
View Related
Dec 29, 2012
We are using the below procedure to generate the files on the DB server.
SQL>
SQL> create or replace procedure write_to_file(p_dir varchar2,
2 p_file varchar2,
3 p_mode varchar2,
4 p_clob clob) as
5 l_output utl_file.file_type;
6 l_amt number default 32767;
7 l_offset number default 1;
8 l_length number default dbms_lob.getlength(p_clob);
9 new_clob clob;
10 BEGIN
11
12 l_output := utl_file.fopen(p_dir, p_file, p_mode, 32767);
13 while (l_offset < l_length) loop
14 new_clob:= SUBSTR(p_clob,l_offset,l_amt);
15 utl_file.put_line(l_output, new_clob,true);
16 l_offset := l_offset + dbms_lob.getlength(new_clob);
17 end loop;
18 utl_file.new_line(l_output);
19 utl_file.fclose(l_output);
20 end write_to_file;
21 /
Procedure created
SQL>
This works fine we call this from PL/SQL developer tool. However, when this procedure is called from Java JDBC, it is giving error
java.sql.SQLException: ORA-29283: invalid file operation
ORA-06512: at "SYS.UTL_FILE", line 536
ORA-29283: invalid file operation
ORA-06512: at "SYS.OBP_UPGRADE_UTIL", line 2816
ORA-06512: at "SYS.OBP_UPGRADE_UTIL", line 3029
ORA-06512: at line 1
DB schema used for both are same (SYS) Verified the directory on the DB server This Procedure called from package with AUTHID CURRENT_USER option.
View 1 Replies
View Related
Feb 24, 2013
How do I perform Undo a drop table operation?
View 12 Replies
View Related
Feb 28, 2011
I am trying to use on trigger to get the code of an DDL operation, I use the code supplied on orafaq (orafaq.com/scripts/plsql/auditdll.txt) as base code and I added a collumn objcode and a call to DBMS_METADATA.GET_DDL to save the object code, however I am receiving an Oracle error ORA-00604.See code below.
This error is raised when I try to create a new view on the schema, on objects that I already have and I changed something usually the error did not happens, how to get the object code of one object when it is created, or changed.
I am using Oracle 11g
SQL> select banner
2 from sys.v_$version;
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
PL/SQL Release 11.2.0.1.0 - Production
CORE11.2.0.1.0Production
TNS for 32-bit Windows: Version 11.2.0.1.0 - Production
NLSRTL Version 11.2.0.1.0 - Production
cl scr;
DROP TRIGGER audit_ddl_changes
/
DROP TABLE dll_audit_log
[Code]....
CREATE FORCE VIEW V3 AS SELECT * FROM ALL_OBJECTS
ORA-00604: error occurred at recursive SQL level 1
ORA-31603: object "V3" of type VIEW not found in schema "XXISV_V11R01"
ORA-06512: at "SYS.DBMS_SYS_ERROR", line 105
ORA-06512: at "SYS.DBMS_METADATA", line 3912
ORA-06512: at "SYS.DBMS_METADATA", line 5678
ORA-06512: at line 1
ORA-06512: at line 2
View 1 Replies
View Related
Jan 24, 2012
I have created the 5 Level Hierarchy Tree using the Tree example
[URL]........
how-to-s/ forms- how- to- create - a- hierarchical - tree-form".
My requirement are
1. I wish to refresh the Hierarchy Tree after DML Operation.
2. I wish to Query the Record when i will select the node.
I have 5 Master Detail Record as:
Master - Detail
Detail Master -- Detail
Detail Master -- Detail
Detail Master -- Detail
Detail Master -- Detail
3. Is there any way to find out which Hierarchy Level currently selected
4. Is there any way to find out which value is for what block.
View 1 Replies
View Related
Aug 21, 2012
I am getting the below exception when i access the WebPage.This only happens sometimes, so if i try again to hit the URL, it works. Not getting why this is behaving unusual.
StandardWrapperValve[jsp]: Servlet.service() for servlet jsp threw exception
(wt.fc.fcResource/0) wt.util.WTException: The operation: "getPrincipal" failed.
Nested exception is: wt.util.WTRemoteException: Unable to invoke remote method; nested exception is:
java.lang.OutOfMemoryError
View 1 Replies
View Related
Feb 16, 2011
I am new to SQL and I am just wondering if there is a solution to a problem I am having.I am using the piece of code below.Essentially what I am doing is selecting a field from a table and ordering that field in descending order. Using the Row_Number feature I then specify which Row I want to return.
Every day the row I will want is the Count of field1 for that day divided by 100 minus 1. This returns a single value of field1 and a single value of R.
I perform this operation every day. The only fields I change every day are the dates and the value of R. I use a seperate piece of SQL code to calculate R each day.
My problem is I have to often populate historical tables with this data. I can only run the code once for each day and for each value of R. Is there anyway I can alter this code such that it can return multiple values of field1 over several dates?The only way I can think of is to repeat the code multiple times using UNION but I am hoping there is a more efficient way.
SELECT *
FROM (SELECT Field1,
ROW_NUMBER() OVER (ORDER BY field1 desc ) R
FROM table
WHERE date >= TO_DATE ('20110215', 'YYYYMMDD')
AND date < TO_DATE ('20110216', 'YYYYMMDD')
)
WHERE R = 1227
--Note: 1227 = (count(field1)/100)-1
View 5 Replies
View Related
Jul 3, 2012
My application runs a batch procedure weekly once for searching 'A_Text' from a column in Table1 in a clob column in Table2 and inserts accordingly into another Table3.
code snippet is like this -
---
CURSOR cr_sn
IS
SELECT serial_number
[Code]....
TABLE1 will have at least 1.1 Million rows but not significantly more than this.
This procedure takes 24+ hours to complete. I tried -
1. putting parallel hint ( INSERT /*+ PARALLEL*/INTO Table3)
2. partitioning TABLE2 based on last_update_date and putting a where clause in the above query last_update_date ( last_update_date between date1 and date2)
View 3 Replies
View Related
Dec 9, 2010
Attempted to execute the Procs below with
Select OTMP_TCIS_RS.Get_UserInfo('EN') from dual; but i get the following error:
ORA-14551: cannot perform a DML operation inside a query.
The intention of the code is to perform an insert into my table based on passing in values via an object into Stored Procedure Apply_Users_Update
Package Definition
create or replace
PACKAGE OTMP_TCIS_RS AS
--1 PROCEDURE Get_UserInfo
PROCEDURE Get_UserInfo(
o_OutCode OUT INT,
i_language IN VARCHAR2);
FUNCTION Get_UserInfo(
i_language IN VARCHAR2)
RETURN NUMBER;
[code]....
View 5 Replies
View Related
Jul 27, 2008
I'm trying to simulate a delete operation through using an update on a trigger my tables are
CREATE TABLE EMPLOYEE (
LNAME VARCHAR(15) NOT NULL,
SSN CHAR(9) NOT NULL,
salary FLOAT,
dno INT NOT NULL,
vst DATE,
vet DATE,
PRIMARY KEY (Ssn));
[code]....
What I want to do is whenever there is an update on vet( valid end time) in employee, delete the values from the employee table and insert the old values from employee into the emp_history table along with the new value for vet. Here's my trigger
CREATE TRIGGER trig4
AFTER UPDATE OF VET ON EMPLOYEE
FOR EACH ROW
BEGIN
INSERT INTO EMP_HIST VALUES( : old.LNAME, : old.SSN, : old.salary, : old.dno, : old.vst, :new.vet);
DELETE FROM EMPLOYEE WHERE(SSN = :NEW.ssn AND vet IS NOT NULL);
END trig4;
//ignore the space between : and o as it makes a smily
The problem is I get an error for a mutating change, what I'd like to know is if the above trigger is possible, and if so how to implement it without giving me an error. I mean it makes sense syntactically and logically(at least to me).
View 1 Replies
View Related
Jan 13, 2013
I have two related questions:
Scenario 1:
1. I have two remote Windows machines with database on each. One is Win 2003 Server (machine A) and another one is Win XP (machine B)
2. I can ping from A to B.
3. I can ping from B to A.
4. I can tnsping from A to B.
5. I CAN'T tnsping from B to A.
6. Windows Firewall on both machines are off.
What could be possible reason for point# 5?
Scenario 2:Now, the second part:
1. I had an unwanted entry in tnsnames.ora on B which I removed.
2. Then I restarted the listener on B. Actually, I wanted to restart the one on A to check if that resolves issue mentioned in point# 5 above.
3. I tried tnsping from A to B but suprisingly it is also giving "operation timed out" error now. So now tnsping not working from either sides.
I didn't make any changes in listener.ora on B, just stopped it and started again. Only change made was removing unwanted entry in tnsnames.ora on B.
Why does that affected database connectivity from A to B which was working fine previously?
NOTE: The two machines are connected through VPN using LogMeIn Hamachi. Hamachi assigns it's own IP address to each machine. Machine A is Windows Server 2003 and B is Windows XP.
View 3 Replies
View Related
Apr 13, 2009
I am receiving the following error while inserting records.
"Oracle Error:ORA-12899: value too large for column "MFG_ADMIN"."GAGE_RESULTS"."COMP
whereas I am checking the length of all values before inserting and am sure that none of them are larger than column lengths.I did some research and found this error might be due to character set.
select * from nls_database_parameters where parameter like '%CHARACTERSET';
PARAMETER VALUE
------------------------------
----------------------------------------------------------------------------------------------------
--------------------
NLS_CHARACTERSET UTF8
NLS_NCHAR_CHARACTERSET UTF8
how can this be related to my problem or if something else is causing this error.
View 3 Replies
View Related
Jul 26, 2005
I have a windows XP server with Oracle 9i on it, when i tried to connect this server from another win XP machine after creating a service. I m getting an error
TNS-12535 TNS:operation timed out
But as i know this error is related to CONNECT_TIMEOUT and it is now obsolete in 9i( am i correct ). I tried it doing from 2 machines but got the same error from everywhere so it means that the problem is with the server.my files are :
Listener.ora
# LISTENER.ORA Network Configuration File: D:oracleora92NETWORKADMINlistener.ora
# Generated by Oracle configuration tools.
LISTENER =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = Tarun)(PORT = 1521))
)
[code]....
View 9 Replies
View Related