SQL Query returning no rows, please help!!
I have a table that contains user audits for a particular procedures alongwith the date stamp. Now, I want to list all the procedures not accessed by the users within the last 6 months. Or, all the procedures that have not been used/accessed during the last 6 months.
This is what I am trying but is not returning any rows:
SELECT DISTINCT proc_name,
TRUNC (entry_date)
FROM log_web
WHERE proc_name NOT IN (SELECT proc_name
FROM log_web
WHERE TRUNC (entry_date) > TRUNC (SYSDATE - 180))
ORDER BY 2 DESC
Please advise.
Thank you in advance.
Two possibilities leap to mind.
First, are you sure that there are any prodcedures not accessed in the last six months?
Second, is there a chance that there could be records with a null value in proc_name? If the sub-query used in a NOT IN predicate returns even one null value, the query will return no rows.
Does this return rows?
SELECT DISTINCT proc_name, TRUNC(entry_date)
FROM log_web
WHERE proc_name NOT IN (SELECT proc_name
FROM log_web
WHERE TRUNC (entry_date) > TRUNC (SYSDATE - 180) and
proc_name IS NOT NULL)
ORDER BY 2 DESCJohn
Similar Messages
-
Oracle:JDBC Call returns no results, SQL*Plus returns 1 record, Please help
Any help would be greatly appreciated.
Running 9.2.0.5.0, and using latest 9.2 JDBC 1.4_g drivers in thin mode.
Execute the following query from SQL*Plus and it returns one row, from JDBC using a PreparedStatement, I get no results. Here's the query, table def, record, etc.:
Query:
SELECT
ID_WEB_FRM,ID_WEB_SIT,CDE_LVL_1_FUNC,
CDE_LVL_2_FUNC,NUM_WEB_FUNC_PG,NUM_WEB_PG_ID
FROM
WEB_FRM
WHERE
ID_WEB_FRM = ' '
OR
(ID_WEB_SIT = 'test' AND CDE_LVL_1_FUNC = ' '
AND CDE_LVL_2_FUNC = 'u2T' AND NUM_WEB_FUNC_PG = 1
AND NUM_WEB_PG_ID = 0)
Record returned from SQL*Plus:
ID_WEB_FRM ID_WEB_SIT CDE CDE NUM_WEB_FUNC_PG NUM_WEB_PG_ID
NfRRmc5XZu test u2T 1 0
Both in the data returned and the query, there are no blanks, but they are a single space instead (hard to see in message here).
Java code:
int count = 1;
findDBNameStatement.setString(count++," ");
findDBNameStatement.setString(count++,form.getSiteID());
findDBNameStatement.setString(count++," ");
findDBNameStatement.setString(count++, form.getFunctionID());
findDBNameStatement.setInt(count++,form.getPageNumber());
findDBNameStatement.setInt(count++,form.getSectionNumber());
ResultSet resultSet = findDBNameStatement.executeQuery();
ResultSetMetaData metaData = resultSet.getMetaData();
resultSet.next() returns false
DB table:
CREATE TABLE web_frm (
ID_WEB_FRM varchar2(10) NOT NULL,
ID_WEB_SIT varchar2(20) NOT NULL,
NAM_WEB_FRM varchar2(40),
TXT_EMAIL_SUBJ varchar2(50),
CDE_LVL_1_FUNC char(3),
CDE_LVL_2_FUNC char(3) NOT NULL,
NUM_WEB_FUNC_PG int NOT NULL,
NUM_WEB_PG_ID smallint NOT NULL,
DTE_WEB_FRM_EFF date NOT NULL,
DTE_WEB_FRM_TRM date,
CDE_VLDT_RUL char(3),
DTE_LAST_EXPRT date,
TXT_CNFRMN_MSG varchar2(4000),
IND_UPDT_ALWD char(1) NOT NULL,
TXT_RECAP_HDR varchar2(4000),
TXT_RECAP_FTR varchar2(4000),
CDE_WEB_OBJ char(3),
NUM_MAX_FRM_WIDTH number(4,0),
IND_RECAP_PG char(1) NOT NULL,
IND_CNFRM_PG char(1) NOT NULL,
IND_DSPL_CNFRM_NUM char(1) NOT NULL,
CNT_SUBM_MAX int,
TXT_CHCE_ADD_MSG varchar2(255),
TXT_CHCE_MOD_MSG varchar2(255),
TXT_WEB_HDR varchar2(4000),
TXT_WEB_FTR varchar2(4000),
TXT_WAIT_LIST_MSG varchar2(255),
FORMOBJECTHEIGHT int NOT NULL,
FORMOBJECTWIDTH int NOT NULL
ALTER TABLE web_frm ADD ( CONSTRAINT PK_web_frm PRIMARY KEY (ID_WEB_FRM));
ALTER TABLE web_frm ADD ( CONSTRAINT UK_web_frm UNIQUE (ID_WEB_SIT,CDE_LVL_1_FUNC,CDE_LVL_2_FUNC,NUM_WEB_FUNC_PG,NUM_WEB_PG_ID)) ;
Thanks,
MattThat's not quite right. From the javadocs:
next
public boolean next()
throws SQLException
Moves the cursor down one row from its current position. A ResultSet cursor is initially positioned before the first row; the first call to the method next makes the first row the current row; the second call makes the second row the current row, and so on.
If an input stream is open for the current row, a call to the method next will implicitly close it. A ResultSet object's warning chain is cleared when a new row is read.
Returns:
true if the new current row is valid; false if there are no more rows
Throws:
SQLException - if a database access error occurs -
JDBC Call returns no results, SQL*Plus returns 1 record, Please help!
Any help would be greatly appreciated.
Running 9.2.0.5.0, and using latest 9.2 JDBC 1.4_g drivers in thin mode.
Execute the following query from SQL*Plus and it returns one row, from JDBC using a PreparedStatement, I get no results. Here's the query, table def, record, etc.:
Query:
SELECT
ID_WEB_FRM,ID_WEB_SIT,CDE_LVL_1_FUNC,
CDE_LVL_2_FUNC,NUM_WEB_FUNC_PG,NUM_WEB_PG_ID
FROM
WEB_FRM
WHERE
ID_WEB_FRM = ' '
OR
(ID_WEB_SIT = 'test' AND CDE_LVL_1_FUNC = ' '
AND CDE_LVL_2_FUNC = 'u2T' AND NUM_WEB_FUNC_PG = 1
AND NUM_WEB_PG_ID = 0)
Record returned from SQL*Plus:
ID_WEB_FRM ID_WEB_SIT CDE CDE NUM_WEB_FUNC_PG NUM_WEB_PG_ID
NfRRmc5XZu test u2T 1 0
Both in the data returned and the query, there are no blanks, but they are a single space instead (hard to see in message here).
Java code:
int count = 1;
findDBNameStatement.setString(count++," ");
findDBNameStatement.setString(count++,form.getSiteID());
findDBNameStatement.setString(count++," ");
findDBNameStatement.setString(count++, form.getFunctionID());
findDBNameStatement.setInt(count++,form.getPageNumber());
findDBNameStatement.setInt(count++,form.getSectionNumber());
ResultSet resultSet = findDBNameStatement.executeQuery();
ResultSetMetaData metaData = resultSet.getMetaData();
resultSet.next() returns false
DB table:
CREATE TABLE web_frm (
ID_WEB_FRM varchar2(10) NOT NULL,
ID_WEB_SIT varchar2(20) NOT NULL,
NAM_WEB_FRM varchar2(40),
TXT_EMAIL_SUBJ varchar2(50),
CDE_LVL_1_FUNC char(3),
CDE_LVL_2_FUNC char(3) NOT NULL,
NUM_WEB_FUNC_PG int NOT NULL,
NUM_WEB_PG_ID smallint NOT NULL,
DTE_WEB_FRM_EFF date NOT NULL,
DTE_WEB_FRM_TRM date,
CDE_VLDT_RUL char(3),
DTE_LAST_EXPRT date,
TXT_CNFRMN_MSG varchar2(4000),
IND_UPDT_ALWD char(1) NOT NULL,
TXT_RECAP_HDR varchar2(4000),
TXT_RECAP_FTR varchar2(4000),
CDE_WEB_OBJ char(3),
NUM_MAX_FRM_WIDTH number(4,0),
IND_RECAP_PG char(1) NOT NULL,
IND_CNFRM_PG char(1) NOT NULL,
IND_DSPL_CNFRM_NUM char(1) NOT NULL,
CNT_SUBM_MAX int,
TXT_CHCE_ADD_MSG varchar2(255),
TXT_CHCE_MOD_MSG varchar2(255),
TXT_WEB_HDR varchar2(4000),
TXT_WEB_FTR varchar2(4000),
TXT_WAIT_LIST_MSG varchar2(255),
FORMOBJECTHEIGHT int NOT NULL,
FORMOBJECTWIDTH int NOT NULL
ALTER TABLE web_frm ADD ( CONSTRAINT PK_web_frm PRIMARY KEY (ID_WEB_FRM));
ALTER TABLE web_frm ADD ( CONSTRAINT UK_web_frm UNIQUE (ID_WEB_SIT,CDE_LVL_1_FUNC,CDE_LVL_2_FUNC,NUM_WEB_FUNC_PG,NUM_WEB_PG_ID)) ;
Thanks,
MattI have verified the parameters and such, and if I run as a Statement instead of a PreparedStatement, the query works fine. After some more troubleshooting, I narrowed the problem down, but not sure of the fix.
If I eliminate teh extra parameters and simplify things to:
SELECT ID_WEB_FRM FROM WEB_FRM WHERE ID_WEB_SIT = 'test' AND CDE_LVL_2_FUNC = 'u2T' AND NUM_WEB_FUNC_PG = 1 AND NUM_WEB_PG_ID = 0
The code works. But if I add the additional WHERE clause of CDE_LVL_1_FUNC = ' ' (has single space), it returns no data (record in the DB has single space in this new column. Query that does not work:
SELECT ID_WEB_FRM FROM WEB_FRM WHERE ID_WEB_SIT = 'test' AND CDE_LVL_1_FUNC = ' ' AND CDE_LVL_2_FUNC = 'u2T' AND NUM_WEB_FUNC_PG = 1 AND NUM_WEB_PG_ID = 0
It appears the JDBC Driver is trimming the parameter when it is a space when set through a PreparedStatement.setString(2," ") -
SQL query returns few rows, but holds on with several Gbs of RAM memory used
If I perform the following query:
SELECT d.DocumentGUID, d.DocumentID
FROM ImportDataBase.dbo.Document d
LEFT OUTER JOIN ContentDataBase.dbo.Document d2 ON (d.DocumentGUID = d2.DocumentGUID)
WHERE ( d2.DocumentGUID IS NULL ) -- new document in the ImportDB
OR ( d2.DocumentGUID IS NOT NULL AND d.QueryContent <> d2.QueryContent ) -- modified document in the ImportDB
It returns around 1000 rows and takes about 3 minutes to complete
It also raises up the RAM memory used from 2GB to 9GBs.
This memory used will remain used untill I restart the server. I have no need to make use of that memory, I already copied the returned rows of that query into a note pad for example. And any other reason of SQL has to to keep that memory stored by
that query, I dont want it.
Is there a way to release that memory I really dont need my SQL server to keep, without having to restart the SQL server?
and without topping the max memory the sql server uses, since I need my SQL server to use as much as it needs in other tasks(I dont think it needs to hold on to the above query memory used)
Thank You very much.Is there a way to release that memory I really dont need my SQL server to keep, without having to restart the SQL server?
and without topping the max memory the sql server uses, since I need my SQL server to use as much
A query can be resource intensive even if it returns a single row. Generally it is a good idea to set SQL Server MAX memory.
BOL: "Optimizing Server Performance Using Memory Configuration Options
The memory manager component of Microsoft SQL Server eliminates the need for manual management of the memory available to SQL Server. When SQL Server starts, it dynamically determines how much memory to allocate based on how much memory the operating system
and other applications are currently using. As the load on the computer and SQL Server changes, so does the memory allocated. For more information, see Memory Architecture.
The following server configuration options can be used to configure memory usage and affect server performance:
•min server memory
•max server memory
•max worker threads
•index create memory
•min memory per query
The min server memory server configuration option can be used to ensure that SQL Server does not release memory below the configured minimum server memory once that threshold is reached. This configuration option can be set to a specific value based on the
size and activity of your SQL Server. If you choose to set this value, set it to some reasonable value to ensure that the operating system does not request too much memory from SQL Server, which can affect SQL Server performance.
The max server memory server configuration option can be used to specify the maximum amount of memory SQL Server can allocate when it starts and while it runs. This configuration option can be set to a specific value if you know there are multiple applications
running at the same time as SQL Server and you want to guarantee that these applications have sufficient memory to run. If these other applications, such as Web or e-mail servers, request memory only as needed, then do not set the max server memory server
configuration option, because SQL Server releases memory to them as needed. However, applications often use whatever memory is available when they start and do not request more if needed. If an application that behaves in this manner runs on the same computer
at the same time as SQL Server, set the max server memory server configuration option to a value that guarantees that the memory required by the application is not allocated by SQL Server."
LINK:
http://technet.microsoft.com/en-us/library/ms177455(v=sql.105).aspx
Memory configuration:
http://www.sqlusa.com/bestpractices/memory-configuration/
Kalman Toth Database & OLAP Architect
SQL Server 2014 Database Design
New Book / Kindle: Beginner Database Design & SQL Programming Using Microsoft SQL Server 2014 -
Sql Query Returns repeating rows
Oracle Version : 10g R2.
DDL & DML
CREATE TABLE T1
( CCODE VARCHAR2(4 BYTE),
PNUM VARCHAR2(16 BYTE),
CTYPCDE VARCHAR2(4 BYTE)
INSERT INTO T1 VALUES ('0001','003526892','0007');
INSERT INTO T1 VALUES ('0001','06767019','0006');
INSERT INTO T1 VALUES ('0001','14787-10-900','0007');
INSERT INTO T1 VALUES ('0002','003445803','0009');
INSERT INTO T1 VALUES ('0002','000000','0018');
INSERT INTO T1 VALUES ('0002','001645156','0008');
INSERT INTO T1 VALUES ('0002','001646283','0008');
INSERT INTO T1 VALUES ('0025','002587509','0008');
INSERT INTO T1 VALUES ('0025','02507462', '0008');
INSERT INTO T1 VALUES ('0025','02565229', '0008');
INSERT INTO T1 VALUES ('0025','000943965','0007');
CREATE TABLE XWLK
( CTYPCDE VARCHAR2(4 BYTE),
CODE VARCHAR2(85 BYTE)
INSERT INTO XWLK VALUES ( '0004','70');
INSERT INTO XWLK VALUES ( '0005','05');
INSERT INTO XWLK VALUES ( '0006','05');
INSERT INTO XWLK VALUES ( '0007','05');
INSERT INTO XWLK VALUES ( '0007','10');
INSERT INTO XWLK VALUES ( '0008','15');
INSERT INTO XWLK VALUES ( '0008','20');
INSERT INTO XWLK VALUES ( '0009','25');
INSERT INTO XWLK VALUES ( '0010','75');
INSERT INTO XWLK VALUES ( '0010','80');
INSERT INTO XWLK VALUES ( '0011','75');
INSERT INTO XWLK VALUES ( '0011','80');
INSERT INTO XWLK VALUES ( '0012','75');
INSERT INTO XWLK VALUES ( '0012','80');
INSERT INTO XWLK VALUES ( '0013','75');
INSERT INTO XWLK VALUES ( '0013','80');
INSERT INTO XWLK VALUES ( '0014','75');
INSERT INTO XWLK VALUES ( '0014','80');
INSERT INTO XWLK VALUES ( '0015','75');
INSERT INTO XWLK VALUES ( '0015','80');
INSERT INTO XWLK VALUES ( '0016','75');
INSERT INTO XWLK VALUES ( '0016','80');
INSERT INTO XWLK VALUES ( '0017','15');
INSERT INTO XWLK VALUES ( '0017','70');
INSERT INTO XWLK VALUES ( '0018','15');
INSERT INTO XWLK VALUES ( '0018','25');
INSERT INTO XWLK VALUES ( '0018','70');
INSERT INTO XWLK VALUES ( '0019','25');
INSERT INTO XWLK VALUES ( '0019','70');
INSERT INTO XWLK VALUES ( '0020','70');
INSERT INTO XWLK VALUES ( '0021','75');
INSERT INTO XWLK VALUES ( '0021','80');
INSERT INTO XWLK VALUES ( '0022','75');
INSERT INTO XWLK VALUES ( '0022','80');
INSERT INTO XWLK VALUES ( '0023','10');
INSERT INTO XWLK VALUES ( '0025','05');
INSERT INTO XWLK VALUES ( '0025','10');
INSERT INTO XWLK VALUES ( '0025','25');
INSERT INTO XWLK VALUES ( '0025','30');
INSERT INTO XWLK VALUES ( '0025','35');
INSERT INTO XWLK VALUES ( '0025','40');
INSERT INTO XWLK VALUES ( '0025','45');
INSERT INTO XWLK VALUES ( '0025','50');
INSERT INTO XWLK VALUES ( '0025','55');
INSERT INTO XWLK VALUES ( '0025','60');
INSERT INTO XWLK VALUES ( '0025','65');
INSERT INTO XWLK VALUES ( '0026','75');
INSERT INTO XWLK VALUES ( '0026','80');
INSERT INTO XWLK VALUES ( '0027','05');
INSERT INTO XWLK VALUES ( '0027','10');
INSERT INTO XWLK VALUES ( '0027','25');
INSERT INTO XWLK VALUES ( '0027','30');
INSERT INTO XWLK VALUES ( '0027','35');
INSERT INTO XWLK VALUES ( '0027','40');
INSERT INTO XWLK VALUES ( '0027','45');
INSERT INTO XWLK VALUES ( '0027','50');
INSERT INTO XWLK VALUES ( '0027','55');
INSERT INTO XWLK VALUES ( '0027','60');
INSERT INTO XWLK VALUES ( '0027','65');
INSERT INTO XWLK VALUES ( '0028','15');
INSERT INTO XWLK VALUES ( '0069','75');
CREATE TABLE PTB
( PNUM VARCHAR2(20 BYTE));
INSERT INTO PTB VALUES('003526892');
INSERT INTO PTB VALUES('06767019');
INSERT INTO PTB VALUES('14787-10-900');
INSERT INTO PTB VALUES('003445803');
INSERT INTO PTB VALUES('000000');
INSERT INTO PTB VALUES('001645156');
INSERT INTO PTB VALUES('001646283');
INSERT INTO PTB VALUES('002587509');
INSERT INTO PTB VALUES('02507462');
INSERT INTO PTB VALUES('02565229');
INSERT INTO PTB VALUES('000943965');
Query
SELECT
SAK.CCODE,
SAK.CTYPCDE,
CASE
WHEN SAK.CCODE = '0001' and SAK.CTYPCDE != '0088' THEN '75'
WHEN SAK.CCODE = '0002' and SAK.CTYPCDE != '0088' THEN '75'
WHEN SAK.CCODE = '0002' and SAK.CTYPCDE != '0088' THEN '80'
WHEN SAK.CCODE = '0003' and SAK.CTYPCDE != '0088' THEN '80'
ELSE XWLK.CODE
END AS PCD,
PTB.PNUM
FROM T1 SAK INNER JOIN XWLK ON SAK.CTYPCDE = XWLK.CTYPCDE
INNER JOIN PTB ON SAK.PNUM = PTB.PNUM
Order by 4
Output
CCODE CTYPCODE PCD PNUM
0002 0018 75 000000
0002 0018 75 000000
0002 0018 75 000000
0025 0007 05 000943965
0025 0007 10 000943965
0002 0008 75 001645156
0002 0008 75 001645156
0002 0008 75 001646283
0002 0008 75 001646283
0025 0008 15 002587509
0025 0008 20 002587509
0002 0009 75 003445803
0001 0007 75 003526892
0001 0007 75 003526892
0025 0008 20 02507462
0025 0008 15 02507462
0025 0008 15 02565229
0025 0008 20 02565229
0001 0006 75 06767019
0001 0007 75 14787-10-900
0001 0007 75 14787-10-900
But the Output is not the expected one if we see for the PNUM = 000000, the records are displayed
3 times it should be only ones displayed and also for PNUM = 001645156. My Query is why is it displaying
more than once, is there anyway that we can display it only once. Can some please advice me where am making
wrong. Thanks in advance.Hi Frank,
Thanks for your responce. My earlier Insert scripts the sample data had few issues, Please find below the updated one....
Oracle Version : 10g R2.
DDL & DML
CREATE TABLE T1
( CCODE VARCHAR2(4 BYTE),
PNUM VARCHAR2(16 BYTE),
CTYPCDE VARCHAR2(4 BYTE)
INSERT INTO T1 VALUES ('0512', '000-06-5393-05', '0023');
INSERT INTO T1 VALUES ('0305', '000-06-5393-05', '0006');
INSERT INTO T1 VALUES ('0611', '0000', '0006');
INSERT INTO T1 VALUES ('0806', '0000', '0008');
INSERT INTO T1 VALUES ('0606', '0000', '0006');
INSERT INTO T1 VALUES ('0099', '0000', '0007');
INSERT INTO T1 VALUES ('0025', '000000324', '0008');
CREATE TABLE XWLK
( CTYPCDE VARCHAR2(4 BYTE),
CODE VARCHAR2(85 BYTE)
INSERT INTO XWLK VALUES ( '0004','70');
INSERT INTO XWLK VALUES ( '0005','05');
INSERT INTO XWLK VALUES ( '0006','05');
INSERT INTO XWLK VALUES ( '0007','05');
INSERT INTO XWLK VALUES ( '0007','10');
INSERT INTO XWLK VALUES ( '0008','15');
INSERT INTO XWLK VALUES ( '0008','20');
INSERT INTO XWLK VALUES ( '0009','25');
INSERT INTO XWLK VALUES ( '0010','75');
INSERT INTO XWLK VALUES ( '0010','80');
INSERT INTO XWLK VALUES ( '0011','75');
INSERT INTO XWLK VALUES ( '0011','80');
INSERT INTO XWLK VALUES ( '0012','75');
INSERT INTO XWLK VALUES ( '0012','80');
INSERT INTO XWLK VALUES ( '0013','75');
INSERT INTO XWLK VALUES ( '0013','80');
INSERT INTO XWLK VALUES ( '0014','75');
INSERT INTO XWLK VALUES ( '0014','80');
INSERT INTO XWLK VALUES ( '0015','75');
INSERT INTO XWLK VALUES ( '0015','80');
INSERT INTO XWLK VALUES ( '0016','75');
INSERT INTO XWLK VALUES ( '0016','80');
INSERT INTO XWLK VALUES ( '0017','15');
INSERT INTO XWLK VALUES ( '0017','70');
INSERT INTO XWLK VALUES ( '0018','15');
INSERT INTO XWLK VALUES ( '0018','25');
INSERT INTO XWLK VALUES ( '0018','70');
INSERT INTO XWLK VALUES ( '0019','25');
INSERT INTO XWLK VALUES ( '0019','70');
INSERT INTO XWLK VALUES ( '0020','70');
INSERT INTO XWLK VALUES ( '0021','75');
INSERT INTO XWLK VALUES ( '0021','80');
INSERT INTO XWLK VALUES ( '0022','75');
INSERT INTO XWLK VALUES ( '0022','80');
INSERT INTO XWLK VALUES ( '0023','10');
INSERT INTO XWLK VALUES ( '0025','05');
INSERT INTO XWLK VALUES ( '0025','10');
INSERT INTO XWLK VALUES ( '0025','25');
INSERT INTO XWLK VALUES ( '0025','30');
INSERT INTO XWLK VALUES ( '0025','35');
INSERT INTO XWLK VALUES ( '0025','40');
INSERT INTO XWLK VALUES ( '0025','45');
INSERT INTO XWLK VALUES ( '0025','50');
INSERT INTO XWLK VALUES ( '0025','55');
INSERT INTO XWLK VALUES ( '0025','60');
INSERT INTO XWLK VALUES ( '0025','65');
INSERT INTO XWLK VALUES ( '0026','75');
INSERT INTO XWLK VALUES ( '0026','80');
INSERT INTO XWLK VALUES ( '0027','05');
INSERT INTO XWLK VALUES ( '0027','10');
INSERT INTO XWLK VALUES ( '0027','25');
INSERT INTO XWLK VALUES ( '0027','30');
INSERT INTO XWLK VALUES ( '0027','35');
INSERT INTO XWLK VALUES ( '0027','40');
INSERT INTO XWLK VALUES ( '0027','45');
INSERT INTO XWLK VALUES ( '0027','50');
INSERT INTO XWLK VALUES ( '0027','55');
INSERT INTO XWLK VALUES ( '0027','60');
INSERT INTO XWLK VALUES ( '0027','65');
INSERT INTO XWLK VALUES ( '0028','15');
INSERT INTO XWLK VALUES ( '0069','75');
CREATE TABLE PTB
( PSAK Number(10,0),
PNUM VARCHAR2(20 BYTE),
Seq_num NUMBER(5,0));
INSERT INTO PTB VALUES('9462003', '000-06-5393-05', '1');
INSERT INTO PTB VALUES('9462004', '000-06-5393-05', '2');
INSERT INTO PTB VALUES('9462008', '0000', '1');
INSERT INTO PTB VALUES('9462009', '0000', '2');
INSERT INTO PTB VALUES('9462010', '0000', '3');
INSERT INTO PTB VALUES('9462017', '000000324', '1');
Query
SELECT
PTB.PSAK,
CASE
WHEN SAK.CCODE = '0001' and SAK.CTYPCDE != '0088' THEN '75'
WHEN SAK.CCODE = '0002' and SAK.CTYPCDE != '0088' THEN '75'
WHEN SAK.CCODE = '0002' and SAK.CTYPCDE != '0088' THEN '80'
WHEN SAK.CCODE = '0003' and SAK.CTYPCDE != '0088' THEN '80'
ELSE XWLK.CODE
END AS PCD,
PTB.PNUM,
PTB.Seq_num
FROM T1 SAK INNER JOIN XWLK ON SAK.CTYPCDE = XWLK.CTYPCDE
INNER JOIN PTB ON SAK.PNUM = PTB.PNUM
Order by 4,3
Query output without distinct
PSAK PCD PNUM SEQ_NUM
9462003 05 000-06-5393-05 1
9462003 10 000-06-5393-05 1
9462008 05 0000 1
9462008 10 0000 1
9462008 20 0000 1
9462008 15 0000 1
9462008 05 0000 1
9462008 05 0000 1
9462017 20 000000324 1
9462017 15 000000324 1
9462004 10 000-06-5393-05 2
9462004 05 000-06-5393-05 2
9462009 05 0000 2
9462009 20 0000 2
9462009 05 0000 2
9462009 15 0000 2
9462009 05 0000 2
9462009 10 0000 2
9462010 05 0000 3
9462010 05 0000 3
9462010 15 0000 3
9462010 10 0000 3
9462010 05 0000 3
9462010 20 0000 3
Query output with distinct
PSAK PCD PNUM SEQ_NUM
9462003 05 000-06-5393-05 1
9462003 10 000-06-5393-05 1
9462008 05 0000 1
9462008 10 0000 1
9462008 15 0000 1
9462008 20 0000 1
9462017 15 000000324 1
9462017 20 000000324 1
9462004 05 000-06-5393-05 2
9462004 10 000-06-5393-05 2
9462009 05 0000 2
9462009 10 0000 2
9462009 15 0000 2
9462009 20 0000 2
9462010 05 0000 3
9462010 10 0000 3
9462010 15 0000 3
9462010 20 0000 3
But both the output is wrong is there any way that i can get the result set as below, from the above query i can see duplicates
if the PNUM has more SEQ_NUM then it is again doing a cross join i think and hence the result set is coming wrong. The Below
is the expected output. Can some one help me out in getting this. Thanks in advance.
PSAK PCD PNUM SEQ_NUM
9462003 05 000-06-5393-05 1
9462004 10 000-06-5393-05 2
9462008 05 0000 1
9462009 05 0000 2
9462010 15 0000 3
9462010 20 0000 3
9462017 15 000000324 1
9462017 20 000000324 1 -
Query Return Truncated Data Please Help
when i insert data into a Table having fields dbnote_no(number),
narration(varchar2 1000),etc.. the data get inserted properly but when i view it after few days the data in the narration field get truncated to 100 characters if have changed the linsize in login script to 1000 in server and also in globin script.You might want to set the buffer width.
In sqlplus, go to the options/environment menu and specify 1000 for buffer width -
XML attributes makes my query return no rows
Hello everyone,
I've an odd problem.
I'm querying some XML, but the attributes in one of the tags make my query return no rows; if I remove the attributes, then the query works as expected.
The XML is below; it's the attributes in the Report tag that cause the issues:
<result errorCode="0">
<return>
<Report
xsi:schemaLocation="Items_x0020_status_x0020_information http://******-****/ReportServer?%2FReports%2FContent%20Producer%20Reports%2FItems%20status%20information&rs%3AFormat=xml&rc%3ASchema=True"
Name="Items status information" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="Items_x0020_status_x0020_information">
<Tablix1>
<Details_Collection>
<Details ItemId="914P7" Username="test" user_role="IT"
first_name="Barry" last_name="Donovan" organisation=""
content_format="On_Screen" modified_date="26/05/2011 13:16:49"
item_status="Draft" status_date="" component_name="" demand="" />
</Details_Collection>
</Tablix1>
</Report>
</return>
</result>My query is:
select
a.item_id
,a.username
,a.user_role
,a.first_name
,a.last_name
,a.supplier_id
,a.format
,a.modified_date
,a.item_status
,a.completion_date
,a.component_code
from dual
,xmltable
('/result/return/Report/Tablix1/Details_Collection/Details'
passing p_xml
columns
item_id varchar2(1000) path '@ItemId'
,username varchar2(1000) path '@Username'
,user_role varchar2(1000) path '@user_role'
,first_name varchar2(1000) path '@first_name'
,last_name varchar2(1000) path '@last_name'
,supplier_id varchar2(1000) path '@organisation'
,format varchar2(1000) path '@content_format'
,modified_date varchar2(1000) path '@modified_date'
,item_status varchar2(1000) path '@item_status'
,completion_date varchar2(1000) path '@status_date'
,component_code varchar2(1000) path '@demand'
) a;I've tried stripping out the attributes in the tag, which does work, but some of the XML I'm expecting back may be quite large (many records), so that caused issues in itself. I'd rather deal with it and not mess with the XML itself if possible.
Any help would be hugely appreciated!
Thank you very much in advance.
Robin
Edited by: User_resU on Apr 12, 2012 2:50 PMExample:
SQL> ed
Wrote file afiedt.buf
1 with t as (select xmltype('<result errorCode="0">
2 <return>
3 <Report
4 xsi:schemaLocation="Items_x0020_status_x0020_information http://******-****/ReportServer?%2FReports%2FContent%20Producer%20Reports%2FItems%20status%20information&rs%3AFormat=xml&rc%3ASchema=True"
5 Name="Items status information" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
6 xmlns="Items_x0020_status_x0020_information">
7 <Tablix1>
8 <Details_Collection>
9 <Details ItemId="914P7" Username="test" user_role="IT"
10 first_name="Barry" last_name="Donovan" organisation=""
11 content_format="On_Screen" modified_date="26/05/2011 13:16:49"
12 item_status="Draft" status_date="" component_name="" demand="" />
13 </Details_Collection>
14 </Tablix1>
15 </Report>
16 </return>
17 </result>') as xml from dual)
18 --
19 -- end of test data
20 --
21 select
22 a.item_id
23 ,a.username
24 ,a.user_role
25 ,a.first_name
26 ,a.last_name
27 ,a.supplier_id
28 ,a.format
29 ,a.modified_date
30 ,a.item_status
31 ,a.completion_date
32 ,a.component_code
33 from t
34 ,xmltable
35 (xmlnamespaces('Items_x0020_status_x0020_information' as "x0"),
36 '//x0:Report/x0:Tablix1/x0:Details_Collection/x0:Details'
37 passing xml
38 columns
39 item_id varchar2(1000) path '@ItemId'
40 ,username varchar2(1000) path '@Username'
41 ,user_role varchar2(1000) path '@user_role'
42 ,first_name varchar2(1000) path '@first_name'
43 ,last_name varchar2(1000) path '@last_name'
44 ,supplier_id varchar2(1000) path '@organisation'
45 ,format varchar2(1000) path '@content_format'
46 ,modified_date varchar2(1000) path '@modified_date'
47 ,item_status varchar2(1000) path '@item_status'
48 ,completion_date varchar2(1000) path '@status_date'
49 ,component_code varchar2(1000) path '@demand'
50* ) a
SQL> /
ITEM_ID
USERNAME
USER_ROLE
FIRST_NAME
LAST_NAME
SUPPLIER_ID
FORMAT
MODIFIED_DATE
ITEM_STATUS
COMPLETION_DATE
COMPONENT_CODE
914P7
test
IT
Barry
Donovan
On_Screen
26/05/2011 13:16:49
Draft -
[Excel] Running a SQL Query to delete rows
Hello Experts,
Background: I am attempting to use a dba of my companies time keeping system and implement it with Power BI tools. Given the file size restrictions within Power Bi itself I need to lower my file size by removing all time logs from
inactive employees.
I have a question regarding whether or not you can use a sql query to delete rows in excel. I have roughly 200,000+ rows in my excel spreadsheet. I am attempting to delete all rows where an employee equals inactive. I have attempted to
delete these rows by sorting them and doing a bulk delete and clear contents, but it seems to crash my excel every time. My thought process is that using a query that does a timed delete might put less of a burden on deleting the massive amount of data.
I would like to use this: DELETE * FROM [Table_(...)_Actual$] WHERE [Current] = "Inactive" (Will add more once I know it is possible to use sql queries in Excel.
Any information on whether or not this is possible would be appreciated.
Regards,
LinkRunning SQL Query in Excel is possible, however, the delete query is not supported in Excel.
You are more restricted in deleting Excel data than data from a relational data source. In a relational database, "row" has no meaning or existence apart from "record"; in an Excel worksheet, this is not true. You can delete values
in fields (cells). Please see:http://support.microsoft.com/kb/257819/en-us
One workaround : Use update query to set the rows as null, then use select query.
e.g.
SQL = "update [sheet2$A1:B5] set name=null,age=null where name='andy'"
cnn.Execute SQL
SQL = "select name,age from [sheet2$A1:B5] where name is not null"
Wind Zhang
TechNet Community Support -
Creating a directory via a jsp page sql query return
Is it possible to create a directory based on the results of a sql query?
i.e.
My sql query returns application number 1234 for a building application (BC for short).
Is it possible to create a directory /BC/1234
It is then proposed to use an iframe to look into the directory so users can place and access scanned documents which are captured during the approval process.
If so how?
An example would be great.
JasonSorry hope your still around I've been away for a while. We've created a samber share to the file server where the documents are stored and mounted it within the web file directory. It works ok if there is an existing directory but if there isn't we want it to be created when the page looks for the folder. I've done this with an asp page it basically did a directory exist test first then create folder if it didn't. The problem is can't find an example of how to do the directory exist test then directory create syntax so an example of both would be great
-
SQL query returns varchar - default value type!!!
On a field in my portal form there is a default value type of 'SQL query returns varchar', where can I put this sql to get a default value from a table?
Hi again
I have this code in 'additional pl/sql code' - '...before displaying the page'. But it comes up with an error when I run the form.
declare
prop_v varchar2(20);
group_v varchar2(3);
el1_v varchar2(3);
blk varchar2(10) := 'DEFAULT';
begin
prop_v := p_session.get_value_as_varchar2(p_block_name=>'DEFAULT', p_attribute_name => 'l_property_p');
group_v := p_session.get_value_as_varchar2(p_block_name=>'DEFAULT', p_attribute_name => 'l_group_p');
select element_code
into el1_v
from eh_risk_element_detail
where property_ref = prop_v
and group_code = group_v
and line_no = 1;
p_session.set_value(p_block_name => blk, p_attribute_name => 'L_ELEMENT1_P', p_value => el1_v);
end;
Rich -
Need help in SQL Query: Update a row in a table & insert the same row into another table
I want to update a row in a table say Table A and the updated row should be inserted into another table say Table B. I need to do it in a single SQL query and i don't want to do it in PL/SQL with triggers. And i tried with MERGE statement but its working with this scenario. (Note: I'm using Oracle Database 10g Enterprise Edition Release 10.2.0.1.0).
Thanks in Advance.Using Sven's code as an example, you could save the updated row in a sql plus variable. (also untested):
SQL> var v_id number
update tableA
set colB='ABC'
where colC='XYZ'
returning id into :v_id;
insert into table A_History (ID, colA, colB, ColC)
select id, ColA, ColB, ColC
from tableA
where id = :v_id; -
I just wanted to note this on the forum..
I'm using Apex 3.0.1.00.08
My DEV environment has just been upgraded from 10g version 10.2.0.2.0 to 10.2.0.4.0.
I created the following process to select some values into some items on my Form page.
select MAX(STAT_YEAR+1)
, pcd.pct_id
, pcd.stat_type_id
, pcd.stat_period_type_id
, pcd.measurement_id
into :P11_STAT_YEAR
, :P11_PCT_ID
, :P11_STAT_TYPE_ID
, :P11_STAT_PERIOD_TYPE_ID
, :P11_MEASUREMENT_ID
from plant_commodity_data pcd
, stat_type stt
where pcd.STAT_TYPE_ID = stt.STAT_TYPE_ID
and pcd.pct_id = :P0_PCT_ID
and stt.stat_type = 'PRD'
group by pcd.pct_id
, pcd.stat_type_id
, pcd.stat_period_type_id
, pcd.measurement_id;The process should run conditionally if there was at least one row to select...
So I copied the SQL into the Process condition, removed the "into" section and set the condition type to be "Exists (SQL query retruns at least one row) ...
select MAX(STAT_YEAR+1)
, pcd.pct_id
, pcd.stat_type_id
, pcd.stat_period_type_id
, pcd.measurement_id
from plant_commodity_data pcd
, stat_type stt
where pcd.STAT_TYPE_ID = stt.STAT_TYPE_ID
and pcd.pct_id = :P0_PCT_ID
and stt.stat_type = 'PRD'
group by pcd.pct_id
, pcd.stat_type_id
, pcd.stat_period_type_id
, pcd.measurement_id;This worked perfectly until the DEV environment was upgraded from 10g version 10.2.0.2.0 to 10.2.0.4.0.
The condition would fire even if there were no rows returning.
I pasted the condition code into SQL Developer connected to the DEV (10.2.0.4.0) environment and it returned no rows.
To solve the problem, I removed the MAX.
You can test this using this code if you have access to the two versions... select MAX(1)
, sysdate
, 'Gus'
from dual
where 1 = 2
group by sysdate, 2Now I know the MAX isn't required in the condition as I'm just trying to find out if any rows exist, but it was there as I copied the code in... I was just wondering why this happened between 10.2.0.2.0 and 10.2.0.4.0?
Gus..Hi Gus,
try to execute
select count(*) from dual where exists (select MAX(1)
, sysdate
, 'Gus'
from dual
where 1 = 2
group by sysdate, 2)in SQL Developer. The above statement is generated by APEX for an "Exists (SQL query retruns at least one row)". Can't test it, because I don't have a 10.2.0.4.0 at hand.
Does SQL Developer now show the same behavior?
Patrick
My APEX Blog: http://www.inside-oracle-apex.com
The APEX Builder Plugin: http://builderplugin.oracleapex.info/
The ApexLib Framework: http://apexlib.sourceforge.net/ -
Hi
I have installed the required .Net software, but never the less I've got this message. Could you please help me out ?
Thanx in advance
Pia
TITLE: Microsoft SQL Server Management Studio
Cannot show Query Designer.
ADDITIONAL INFORMATION:
Exception has been thrown by the target of an invocation. (mscorlib)
Unable to find the requested .Net Framework Data Provider. It may not be installed. (System.Data)
BUTTONS:
OKalso check
http://connect.microsoft.com/VisualStudio/feedback/details/652192/visual-studio-2010-add-connection-fails
mostly machine.config is referring to .net 3.0 assemblies
Balmukund Lakhani
Please mark solved if I've answered your question, vote for it as helpful to help other users find a solution quicker
This posting is provided "AS IS" with no warranties, and confers no rights.
My Blog |
Team Blog | @Twitter
| Facebook
Author: SQL Server 2012 AlwaysOn -
Paperback, Kindle -
Query return no rows in Answers but retrun rows in sql
Hi all,
I have the following query which return 3 rows in SQL promple but return no row in Answer and Execute direct request what is the problem any idea?
select abc_date,abc_asset_desc,sum(abc_market_val_lcy+abc_int_accr_lcy) "Stock"
from abc
group by abc_date,abc_asset_descRegardsHi,
i really appriciate your reply
pls tell me briefly from where i can set log-level > 2 ?? and from where check the physical log of SQL ?
Followig message is arise at server log
ORA-01455 converting column overflow integer datatype at OCI call OCIStmtFetch,Bulk fetched failed
Message was edited by:
53637 -
SQL Query to Join by Comma - Help an assistance
Hi,
Thanks for your help in advance.
Requirement is as follows.
Table1
=======
Col1 Col2
============
1 John
2 Jocky
3 Silk
Table2
========
Col1 Col2
=========
1 John, Marry, Joseph
2 Silk, David
3 Jocky, Prem
I need an sql query where the join condition has to satisfy as follows
Table1.col2=Table2.Col2 (If any of the col2 in table1 matches with Table2.Col2 i need to return the record).
How to do this.
Please guide me on this.nazzu wrote:
Thanks a lot for your response ...
But if a table1 and table2 had different numbers of rows then ?
I may be behaving like a fool ... but my requrirement is such a fashion.
Please help ...
Thanks again for your help.
Edited by: nazzu on Mar 14, 2013 8:22 AMHi,
try to be clear in your requirement. You mentioned in your initial question:
I need an sql query where the join condition has to satisfy as followsWhat happen if you have different number of rows in table1 and table2?
Rows from table2 will be returned for any match in table1 if you are using a normal join. However if you have 2 rows in table1 that are matching table2 then that row in table2 will return twice.
Let me just show you an example:
WITH table1(col1, col2) AS
SELECT 1, 'John' FROM DUAL UNION ALL
SELECT 2, 'Jocky' FROM DUAL UNION ALL
SELECT 3, 'Silk' FROM DUAL UNION ALL
SELECT 4, 'Marry' FROM DUAL
, table2(col1, col2) AS
SELECT 1, 'John, Marry, Joseph' FROM DUAL UNION ALL
SELECT 2, 'Silk, David' FROM DUAL UNION ALL
SELECT 3, 'Jocky, Prem' FROM DUAL
SELECT t2.col1, t2.col2, t1.col2
FROM table2 t2
JOIN table1 t1
ON(INSTR(', '||t2.col2||',', ', '||t1.col2||',')>0);
COL1 COL2 COL2_1
1 John, Marry, Joseph John
1 John, Marry, Joseph Marry
2 Silk, David Silk
3 Jocky, Prem Jocky As you can see the first row from table2 is returned twice because it matches 2 records on table1.
In case you want to display only rows from table2 which has a match in table1 you can either do a distinct:
SELECT DISTINCT t2.col1, t2.col2
FROM table2 t2
JOIN table1 t1
ON(INSTR(', '||t2.col2||',', ', '||t1.col2||',')>0);
COL1 COL2
1 John, Marry, Joseph
2 Silk, David
3 Jocky, Prem or use EXISTS operator:
SELECT t2.col1, t2.col2
FROM table2 t2
WHERE EXISTS (SELECT 1
FROM table1 t1
WHERE INSTR(', '||t2.col2||',', ', '||t1.col2||',')>0
COL1 COL2
1 John, Marry, Joseph
2 Silk, David
3 Jocky, Prem Regards.
Al
Maybe you are looking for
-
ITunes quit unexpectedly while using the CoreAudio plug-in. How can I fix this?
It will not start at all. Logging in as guest and trying to start iTunes gives the same error. Any suggestions? Process: iTunes [1712] Path: /Applications/iTunes.app/Contents/MacOS/iTunes Identifier: com.apple.iTunes Version:
-
I am British, live in Spain, and want to use my UK credit card for my iTunes account and use English, but can't find a way to do this. Can anyone help?
-
Problem Adding Managed Servers in Weblogic - OSB Domain
In the project there were 4 OSB nodes as a part of a cluster, 2 other wanted to be add. These 2 were added as a part of the same cluster and were started with no problem. However, it was found that the OSB proxy services were not properly deployed in
-
How to stop a person from creating an order for a particular region?
Hi All, Suppose there are three regions viz : 1.Asia 2.Middle East 3.Europe Now what I want that when a agent /end user is creating an order for a particular person for a specific region, he gets an error message that "Orders cannot be created for th
-
I noticed 2 problems using TFL with arabic text: 1- While writing arabic text and pressing the direction keys to move the cursor - it moves in the opposite direction. 2- The double quotation mark : " appears as single quotation mark: ' when press (se