Tricky SQL helpDates between dates
hi,
I need to return all months that fall between a date range. So for example,
Date range = 01-JAN-1999 to 01-JUN-1999
Should return JAN,FEB,MAR,APR,MAY,JUN
Any ideas on this one folks ?
Yhanks.
N
You can use BETWEEN
where col_date between to_date('01-JAN-1999','DD-MON-YYYY') and to_date('30-JUN-1999','DD-MON-YYYY')
hi,
I need to return all months that fall between a date range. So for example,
Date range = 01-JAN-1999 to 01-JUN-1999
Should return JAN,FEB,MAR,APR,MAY,JUN
Any ideas on this one folks ?
Yhanks.
N
Similar Messages
-
I have a table which contains a list of enquiries that I
receive. I have an 'Input_Date' field as a column. I have set up a
page on my site on which to input two dates to search between for
enquiries. One input field is called Start and the other End.
What is the SQL I would need in order to display the results
on a page which I go to after hitting 'submit'? Also, how would I
define the variables, 'Request.Form' or 'Request.QueryString'?
Thanks for your help in advance!If your 'Input_Date' DataType is datetime or Int you can use
a BETWEEN
clause.
eg. WHERE Input_Date BETWEEN Start AND End
As for whether to use Request.Form or Request.Querystring,
this depends on
whether you are using POST or GET on submission of the Form.
Do a Google on 'SQL BETWEEN' and you will find loads of good
articles. It's
very easy and straightforward to use.
Pat.
"Yorkshire Newbie" <[email protected]> wrote
in message
news:e7ojm4$4e1$[email protected]..
>I have a table which contains a list of enquiries that I
receive. I have an
> 'Input_Date' field as a column. I have set up a page on
my site on which
> to
> input two dates to search between for enquiries. One
input field is called
> Start and the other End.
>
> What is the SQL I would need in order to display the
results on a page
> which I
> go to after hitting 'submit'? Also, how would I define
the variables,
> 'Request.Form' or 'Request.QueryString'?
>
> Thanks for your help in advance!
> -
SQL to select data between a date range
Hello,
I am a new user to HTMLDB and I have an application where I need to select the rows from a table that are between a specified date range. The table description is
name varchar2
class varchar2
sal number
hdate date
I want to select the rows of all names between date value 1 and date value 2. The SQL query I use in SQLPLUS does not work in HTML DB. The query I used is
select null link, name from tab_data where hdate between TO_DATE('06-JAN-04','DD-MON-YY') and TO_DATE('08-JAN-04','DD-MON-YY')
I also have 2 date picker fields in my form and I used a similar query which did not work.
select null link, name from tab_data where hdate between TO_DATE(:P2_DATE1,'DD-MON-YY') and TO_DATE(:P2_DATE2,'DD-MON-YY').
Can someone help me out?
ThanksTo All,
This is getting frustrating... I have tried every combination and permutation I can think of with zero success. The table column I am querying is of type date. The nls_date_format is 'DD-MON-YY' on a 10g database on Linux ES. I am using datepicker 'DD-MON-YY'. I have converted it using TO_DATE, TO_CHAR(TO_DATE(, trunc etc. Is it just my installation? I have upgraded to the latest patch, so that can't be the problem. I created various test scenarios (virgin tables, one row, etc). I've been writing PL/SQL for fourteen years and I think I'm pretty good, but I've sure run up against a stone wall here. Surely somebody has done a date compare out there...
select to_char(to_date('06-JAN-04','DD-MON-YY'),'MM/DD/YYYY') from dual;
06-JAN-2004
select to_char(YOUR_DATE_COLUMN,'MM/DD/YYYY') from YOUR_TABLE_WITH_DATE_COLUMN;
15-OCT-2004
15-OCT-2004
15-OCT-2004 -
I am trying to develop a query in MS Access 2010 to join two tables using three joins, one of which is a (between) date range. The tables are contained in Access. The reason
the tables are contained in access because they are imported from different ODBC warehouses and the data is formatted for uniformity. I believe this cannot be developed using MS Visual Query Designer. I think writing a query in SQL would be suiting this project.
ABCPART links to XYZPART. ABCSERIAL links to XYZSERIAL. ABCDATE links to (between) XYZDATE1 and ZYZDATE2.
[ABCTABLE]
ABCORDER
ABCPART
ABCSERIAL
ABCDATE
[ZYXTABLE]
XYZORDER
XYZPART
XYZSERIAL
XYZDATE1
XYZDATE2Thank you for the looking at the post. The actual table names are rather ambiguous. I renamed them so it would make more sense. I will explain more and give the actual names. What I do not have is the actual data in the table. That is something I don't have
on this computer. There are no "Null" fields in either of the tables.
This table has many orders (MSORDER) that need to match one order (GLORDER) in GLORDR. This is based on MSPART joined to GLPART, MSSERIAL joined to GLSERIAL, and MSOPNDATE joined if it falls between GLSTARTDATE and GLENDDATE.
[MSORDR]
MSORDER
MSPART
MSSERIAL
MSOPNDATE
11111111
4444444
55555
2/4/2015
22222222
6666666
11111
1/6/2015
33333333
6666666
11111
3/5/2015
This table has one order for every part number and every serial number.
[GLORDR]
GLORDER
GLPART
GLSERIAL
GLSTARTDATE
GLENDDATE
ABC11111
444444
55555
1/2/2015
4/4/2015
ABC22222
666666
11111
1/5/2015
4/10/2015
AAA11111
555555
22222
3/2/2015
4/10/2015
Post Query table
GLORDER
MSORDER
GLSTARTDATE
GLENDDATE
MSOPNDATE
ABC11111
11111111
1/2/2015
4/4/2015
2/4/2015
ABC22222
22222222
1/5/2015
4/10/2015
1/6/2015
ABC22222
33333333
1/5/2015
4/10/2015
3/5/2015
This is the SQL minus the between date join.
SELECT GLORDR.GLORDER, MSORDR.MSORDER, GLORDR.GLSTARTDATE, GLORDR.GLENDDATE, MSORDR.MSOPNDATE
FROM GLORDR INNER JOIN MSORDR ON (GLORDR.GLSERIAL = MSORDR.MSSERIAL) AND (GLORDR.GLPART = MSORDR.MSPART); -
Getting SQL*Net more data from client waits when running a query through web based interface
Hi, you all,
We are having this weird behavior when running query through web based interface, we get a lot of "SQL*Net more data from client" waits, the OEM indicates that the current wait event is SQL*Net more data from client
It's just a very simple query wich invokes a db link.
When I execute the same query on any PL/SQL tool like toad or sql developer it works fine, but that query inside an application executed through a web based interface, it hangs for ever.
Where can I start looking for the problem.
We are working on a 3 Node RAC 11gr2, both databases are on the same RAC.
Thanks.Hi ,
we managed to reproduce the case in test environment, below are the steps:
1)have 2 databases on different machines, will call the first one local, the other one remote.
2)in the local database create:
a - DBLink to remote database.
b - read data from remote database(we simply used select count(*) from dummy_table )
c - insert data into a table on the local database
d - terminate the connection between the 2 databases (disconnect either machine from the network)
e - commit on local database.
what we noticed was the following:
1)when the local database is disconnected from the network(the machine is not connected to any network at the moment): almost immediately throws an error, and issuing the following:
select * from dba_2pc_pending;we found some data .
2) when the remote database was disconnected(the local database is still connected to the network):
after 7-8 seconds an error is thrown, and issuing the following:
select * from dba_2pc_pending;did not return any data.
since this is pretty similar to our case ,we concluded that it's a network issue.
is this the correct behavior ?
as a temporary solution till the network issue is fixed ,we did the following:
1) changed the call of the remote procedure to calling a local procedure that calls the remote procedure.
2) added pragma autonomous_transaction to the local procedure.
3) at the end of the local procedure rollback the autonomous transaction.
it seems that since the global transaction does not use the DBLink database does not issue a 2PC commit.
this works in my cases since the DBLink is only issed to read data. -
Extract data from a BW 7.0 cube to a SQL DB using Data Services XI
Hi Gurus,
We are trying to extract data from a BW 7.0 cube to a SQL DB using Data Services XI, the issue is that we can not read text without making "joins" between SID in the fact table and the master data tables. Do you know if it is posible to read text in a natural way?
Best RegardsThanks Wondewossen,
As you know, the DataStores (Data Services) provide access to:
1.-Tables
2.-Functions
3.-IDOCs
4.-Open Hub Tables
We are trying to extract data using the first one (Tables), not using Open Hub.
Best Regardas -
SQL*Net more data to dblink event for hours or days
Hello Everyone,
in our production database when we commit a transaction we call a remote procedure over dblink.
usually the call succeeds ,but every now and then a couple of sessions hang up,
when I use the session browser of Toad I notice that these sessions are waiting with the event SQL*Net more data to dblink
below are some queries and their results:
select sid,event,wait_class,wait_time,seconds_in_wait,state from gv$session_wait where sid=225
rslt:
225 SQL*Net more data to dblink Network -1 18279 WAITED SHORT TIME
select * from gv$session_wait_history where sid=225
rslt:
INST_ID SID SEQ# EVENT# EVENT P1TEXT P1 P2TEXT P2 P3TEXT P3 WAIT_TIME WAIT_TIME_MICRO TIME_SINCE_LAST_WAIT_MICRO
2 225 1 344 SQL*Net more data to dblink driver id 1413697536 #bytes 8144 0 0 8 41
2 225 2 344 SQL*Net more data to dblink driver id 1413697536 #bytes 8143 0 0 13 39
2 225 3 344 SQL*Net more data to dblink driver id 1413697536 #bytes 8149 0 0 7 37
2 225 4 344 SQL*Net more data to dblink driver id 1413697536 #bytes 8145 0 0 8 40
2 225 5 344 SQL*Net more data to dblink driver id 1413697536 #bytes 8145 0 1 11394 37
2 225 6 344 SQL*Net more data to dblink driver id 1413697536 #bytes 8143 0 0 7 37
2 225 7 344 SQL*Net more data to dblink driver id 1413697536 #bytes 8145 0 0 7 36
2 225 8 344 SQL*Net more data to dblink driver id 1413697536 #bytes 8138 0 0 8 37
2 225 9 344 SQL*Net more data to dblink driver id 1413697536 #bytes 8149 0 0 8 38
2 225 10 344 SQL*Net more data to dblink driver id 1413697536 #bytes 8149 0 1 11476 37I'm not sure but from the above results ,is it safe to conclude that I get stuck because I am caught in infinite loop trying to write to dblink?
additional notes:
<li>some times when I look at the current statement I find that the statement is a query or insert into a local table.
<li>there were some network outages.
<li>when viewing the database log files I found:Error 3135 trapped in 2PC on transaction 7.6.306086. Cleaning up.
Error stack returned to user:
ORA-03135: connection lost contact
ORA-02063: preceding line from MPF//where MPF is the name of dblinkeven though we use the DBLink to execute the procedure only without any changes on the remote DB, and we don't use 2PC.
<li> the local DB is a RAC
select * from dba_blockers
rslt:
no rows
select * from dba_waiters
rslt:
no rows
select * from gv$lock where sid=225
rslt:
INST_ID ADDR KADDR SID TYPE ID1 ID2 LMODE REQUEST CTIME BLOCK
2 0000000199D54F60 0000000199D54FB8 225 AE 100 0 4 0 20152 2
2 000000018EA18108 000000018EA18180 225 TX 1114138 251539 6 0 19654 2
select * from gv$session where sid=225
rslt:
INST_ID SADDR SID SERIAL# AUDSID PADDR USER# USERNAME COMMAND OWNERID TADDR LOCKWAIT STATUS SERVER SCHEMA# SCHEMANAME OSUSER PROCESS MACHINE PORT TERMINAL PROGRAM TYPE SQL_ADDRESS SQL_HASH_VALUE SQL_ID SQL_CHILD_NUMBER SQL_EXEC_START SQL_EXEC_ID PREV_SQL_ADDR PREV_HASH_VALUE PREV_SQL_ID PREV_CHILD_NUMBER PREV_EXEC_START PREV_EXEC_ID PLSQL_ENTRY_OBJECT_ID PLSQL_ENTRY_SUBPROGRAM_ID PLSQL_OBJECT_ID PLSQL_SUBPROGRAM_ID MODULE MODULE_HASH ACTION ACTION_HASH CLIENT_INFO FIXED_TABLE_SEQUENCE ROW_WAIT_OBJ# ROW_WAIT_FILE# ROW_WAIT_BLOCK# ROW_WAIT_ROW# TOP_LEVEL_CALL# LOGON_TIME LAST_CALL_ET PDML_ENABLED FAILOVER_TYPE FAILOVER_METHOD FAILED_OVER RESOURCE_CONSUMER_GROUP PDML_STATUS PDDL_STATUS PQ_STATUS CURRENT_QUEUE_DURATION CLIENT_IDENTIFIER BLOCKING_SESSION_STATUS BLOCKING_INSTANCE BLOCKING_SESSION FINAL_BLOCKING_SESSION_STATUS FINAL_BLOCKING_INSTANCE FINAL_BLOCKING_SESSION SEQ# EVENT# EVENT P1TEXT P1 P1RAW P2TEXT P2 P2RAW P3TEXT P3 P3RAW WAIT_CLASS_ID WAIT_CLASS# WAIT_CLASS WAIT_TIME SECONDS_IN_WAIT STATE WAIT_TIME_MICRO TIME_REMAINING_MICRO TIME_SINCE_LAST_WAIT_MICRO SERVICE_NAME SQL_TRACE SQL_TRACE_WAITS SQL_TRACE_BINDS SQL_TRACE_PLAN_STATS SESSION_EDITION_ID CREATOR_ADDR CREATOR_SERIAL# ECID
2 00000001993E4F58 225 445 1353611 0000000198E2FA10 198 <schema> 47 2147483644 000000018EA18108 ACTIVE DEDICATED 198 <schema> oracle 1234 <cluster name> 49993 unknown JDBC Thin Client USER 00000001968A1250 3198676106 72y8ztfzagv4a 2 02/04/2013 11:18:22 ص 33554852 00000001968A18E0 3992616824 03mm4u3qznzvs 0 02/04/2013 11:18:22 ص 33554730 158207 1 158207 1 JDBC Thin Client 2546894660 0 12206 122409 8 49354 0 94 02/04/2013 10:53:20 ص 19559 NO NONE NONE NO DISABLED ENABLED ENABLED 0 NOT IN WAIT NOT IN WAIT 42844 344 SQL*Net more data to dblink driver id 1413697536 0000000054435000 #bytes 8144 0000000000001FD0 0 00 2000153315 7 Network -1 19553 WAITED SHORT TIME 8 19553325216 SYS$USERS DISABLED FALSE FALSE FIRST EXEC 100 0000000198E2FA10 2 004qLk^iPyp0bqw5wFDCiW0002fR000B^fHi ,
we managed to reproduce the case in test environment, below are the steps:
1)have 2 databases on different machines, will call the first one local, the other one remote.
2)in the local database create:
a - DBLink to remote database.
b - read data from remote database(we simply used select count(*) from dummy_table )
c - insert data into a table on the local database
d - terminate the connection between the 2 databases (disconnect either machine from the network)
e - commit on local database.
what we noticed was the following:
1)when the local database is disconnected from the network(the machine is not connected to any network at the moment): almost immediately throws an error, and issuing the following:
select * from dba_2pc_pending;we found some data .
2) when the remote database was disconnected(the local database is still connected to the network):
after 7-8 seconds an error is thrown, and issuing the following:
select * from dba_2pc_pending;did not return any data.
since this is pretty similar to our case ,we concluded that it's a network issue.
is this the correct behavior ?
as a temporary solution till the network issue is fixed ,we did the following:
1) changed the call of the remote procedure to calling a local procedure that calls the remote procedure.
2) added pragma autonomous_transaction to the local procedure.
3) at the end of the local procedure rollback the autonomous transaction.
it seems that since the global transaction does not use the DBLink database does not issue a 2PC commit.
this works in my cases since the DBLink is only issed to read data. -
Session Facade and Access to a Non SQL Based Persistent Data Store
Hi,
We are currently using jDeveloper 10.1.3.5 and Oracle Application Server 10.1.3.5. We develop all our applications as Java portlets using Oracle PDK and they are exposed through Oracle Portal.
In our environment, the persistent data is stored on a combination of an Oracle database and a non SQL based persistent data store.
The way we access the non SQL persistent data store is by posting a URL and receiving an XML document back in response. This mechanism is used both for enquiry and update of the persistent store.
We have to create a new XML schema for each entity that we need to access and there are software changes on both our environment (Java) and the non SQL based persistent data store.
In an attempt to shorten development times we are looking to start using ADF faces and EJB3.
We have downloaded the SRDemo tutorial and made it work but there are some challenges.
1. The SRDemo seem to have a very minimal implementation of a business layer. From what I can see, it is essentially some straightforward wiring between database attributes and their viewable representation. Is there a demo/tutorial containing a bit more meat in the business layer that you are aware of?
2. Given our non SQL based persistent data store, how would you go about implementing EJB3 for such scenario. Is it recommended at all? How would you go about integrating the rest of the application (business layer and representation layer) to data arriving from such source?
3. SRDemo is not intended to be exposed as a portlet. Is there a tutorial that we can use incorporating JSR168, ADF Faces and EJB3 in the same application? I also understand that there is a JSF-JSR168 bridge available. Can you provide some pointers here? Where can we find it? Would we be able to use it in jDeveloper 10.1.3.5?
RegardsMatt,
The only way to associate an "x-axis" with a signal in the Write Data VI would be to feed it waveforms, which are constrained to use time as the x-axis unit. There is really no way around this, so in my opinion, the best solution for you would be to use the "rows are channels" conversion and write the frequency and amplitude values to the file independently. Then when you read the file in DIAdem, take the two channels and build a graph out of them there.
Regards,
E. Sulzer
Applications Engineer
National Instruments
E. Sulzer
Applications Engineer
National Instruments -
I need to know how i can find difference between date
like Joining date: 01-jan-2009 Today 10-jan-2010 result will be "1 year 10 days"
I need it in Oracle forms 6i. plz help me...Hi,
In oracle forms you can use
RESULT :=
TRUNC ((:date2 - :date1 + 1) / 365)
|| ' year and '
|| MOD (:date2 - :date1 + 1, 365)
|| ' days';
in sql you can use
SELECT TRUNC ((:date2 - :date1 + 1) / 365)
|| ' year and '
|| MOD (:date2 - :date1 + 1, 365)
|| ' days'
FROM DUAL; -
Hi,
Can any body help to write the query between dates in QAF.
i have writen like this but its is not working
whereClause.append(" OT_DATE between :");
// whereClause.append(++bindCount);
whereClause.append(fromDate);
// whereClause.append(++bindCount);
whereClause.append(" AND :");
whereClause.append(toDate);
ThanxVenkat, u can either use toDate() function in ur sql or use java.sql.Date to convert ur string into date.
Secondly parameters should be passed through whereclauseparams,like
java.sql.Date javaSqlDate =
transaction.getOANLSServices().stringToDate(submitedDateString);
whereClause.append("DATE_COLUMN_NAME = :1");
setWhereClauseParams(0,javaSqlDate);
--Mukul -
Hi Gurus,
Can anyone tell me the difference between "Data replication", "Data Cloning", "Data duplication" and "Data Migration". I have gone through Google but doesn't find any appropriate answer for that where I can find the difference.
It would be highly appreciated if you give me a link for all and give me some point out.
Thanks & Regards
Nimai KarmakarHere is how I see the terms used and understood by most folks
"Data replication"
This is the keeping the same data in sync in 2 different databases. Replication is the process of keeping data in sync between 2 environments/databases and not limited to Oracle to Oracle, it could be Oracle to MySQL to be kept in sync, MySQL to Oracle, Oracle to SQL Server, SQL Server to Oracle. The purpose of keeping data in sync can vary, but that is basic description of what it is.
"Data Cloning"
Make a copy of the data/database from one database environment to another, like for example taking production database and cloning the database to a pre-production database/environment for testing. Coning term is used more when copying a database not just data, but the whole database so typically you hear the reference "Database Cloning", but data cloning is basically the making a copy of the data from one place to another. Sometimes Cloning and Duplicating are used in the same way by folks as the basic end result is the same you are making a copy of the data to someplace else.
"Data duplication"
This is typically term when duplicating the data from one environment to another for a particular purpose, a lot of folks use "Data/Database Cloning" and "Data Duplication" in the same context, meaning they use them to mean the same thing, but I see more difference in the terms so when they are different Data Duplication is done when combining 2 databases to 1 therefore you can not clone the 2 databases into one so this term would be used more in those circumstances.
"Data Migration"
Moving data from one location/database to another location database, for example moving from MySQL to Oracle you would do a data migration from MySQL to Oracle as you are moving the data from MySQL to Oracle and going to leave it in Oracle. You could also be migrating to from Oracle 10g environment to a new Oracle 11g environment, therefore "Migration" is typically used when referring to moving the data from one environment to another and the source and target are different in location, database vendor, database version.
These are very simple ways of looking at the terms from my experience on how they are used. -
Difference Between Data type and message type
Hi,
i have doubt on data type and message type.why we are mapping the message type why not data type?wht is the difference between data type and message type?Hi Narayanana,
Data type defines the structure of your xml message.Message type is the wrapper of data type.You will be using your message type while mapping and not the data type.Its the abstraction concept used in oops
kanan thiyam
Posts: 28
Questions: 7
Registered: 1/8/07
Forum points: 24
Re: What is deffernce b/w Data type and message type
Posted: Jun 13, 2007 8:05 AM in response to: suresh k Reply E-mail this post
Hi Suresh,
Data Type defines the structure of the message and it will be wrapped under Message Type.
Hope the details below will clearify your doubts.
A data type in a programming language is a set of data with values having predefined characteristics. Examples of data types are: integer, floating point unit number, character, string, and pointer.
The characteristic of columns and variables that defines what types of data values they can store.
Check out the details:
http://en.wikipedia.org/wiki/Data_type
A message type comprises a data type that describes the structure of a message. At the following points in SAP Exchange Infrastructure you can refer to the message to be exchanged at runtime by using the message type:
Details:
http://help.sap.com/saphelp_nw04/helpdata/en/2d/c0633c3a892251e10000000a114084/content.htm
kanan -
What is the difference between data file & control file
what is the difference between data file & control file
Dear Deba s
Control file
Every Oracle Database has a control file, which is a small binary file that records the physical structure of the database. The control file includes:
The database name
Names and locations of associated datafiles and redo log files
The timestamp of the database creation
The current log sequence number
Checkpoint information
For more info look into these
[Control File Basic|http://download-east.oracle.com/docs/cd/B19306_01/server.102/b14231/control.htm#i1006143]
Data File
You manage Data File in your Oracle database as part of Space Management. You can extend, create, drop, and alter tablespaces.
You especially need to avoid tablespace overflow, which is when a tablespace runs out of freespace in the allocated file or files. This happens when an object requires a new extent but there is either no freespace or insufficient freespace in the tablespace
For more info look into these links
[Data files |http://help.sap.com/saphelp_nw04/helpdata/en/98/5dd5890f32274aa884e45e736752a2/frameset.htm]
http://help.sap.com/saphelp_nw04/helpdata/en/98/5dd5890f32274aa884e45e736752a2/frameset.htm
Hope it helps you,Revert me back if you have any queries
Assign points if helpful
Regards
Bala -
Can you use SQL as a data source for a project in the same way you can in Excel?
Excel allows you to create a data source that executes a SQL stored procedure, display that data as a table in a spreadsheet and have that data automatically refresh each time you open the spreadsheet. Is it possible to do the same thing in MS Project, displaying
the data from the stored procedure as a series of tasks?
Here's what I'm trying to do - I have a stored procedure that pulls task data meeting a specific criteria from all projects in Project Server. We're currently displaying this data as an Excel report. However, the data includes start dates and durations so
it would be nice to be able to display it as a Gantt Chart. I've played around with creating a Gantt chart in Excel and have been able to do a very basic one, but it doesn’t quite fit our needs.No, You can not use sql as a data source for a project.
You have 3 options to achieve it:
1. You can create a Sharepoint list with desired column ,fill desired data in that list then you can create a MS project from Sharepoint List.
2. You can create a SSRS report in which you can display grantt chart Joe has given you that link.
3. You can write a macro in MPP which will take data from your excel. In excel you will fetch data from your stored procedure. write a schedule which will run every day to update your data or
create an excel report in which will update automatically and write macro in mpp which will fetch the data then publish it so that it would be available to team members.
kirtesh -
Dynamic sql reurns no data when multiple values are passed.
(Dynamic sql returns no data when multiple values are passed.)
Hi,
While executing the below dynamic sql in the procedure no data is returned when it has multiple input values.
When the input is EMPID := '1'; the procedure works fine and returns data.Any suggestion why the procedure doen't works when input as EMPID := '1'',''2'; is passed as parameter?
=======================================================
create or replace PROCEDURE TEST(EMPID IN VARCHAR2, rc OUT sys_refcursor)
IS
stmt VARCHAR2(9272);
V_EMPID VARCHAR2(100);
BEGIN
V_EMPID :=EMPID;
stmt := 'select * from TEST123 where Empid is NOT NULL';
IF V_EMPID <> '-1' THEN
stmt := stmt || ' and Empid in (:1)';
ELSE
stmt := stmt || ' and -1 = :1';
END IF;
OPEN rc FOR stmt USING V_EMPID;
END Z_TEST;
============================================================
Script for create table
==================================================================
CREATE TABLE TEST123 (
EMPID VARCHAR2(10 BYTE),
DEPT NUMBER(3,0)
===========================================
Insert into PDEVUSER.TEST123 (EMPID,DEPT) values ('1',20);
Insert into PDEVUSER.TEST123 (EMPID,DEPT) values ('2',10);
Insert into PDEVUSER.TEST123 (EMPID,DEPT) values ('3',30);
Insert into PDEVUSER.TEST123 (EMPID,DEPT) values ('3',30);
Insert into PDEVUSER.TEST123 (EMPID,DEPT) values ('2',10);
=============================================
Select * from TEST123 where Empid in (1,2,3)
EMPID DEPT
1 20
2 10
3 30
3 30
2 10
===================================================================
Any suggestion why the procedure doen't works when input EMPID := '1'',''2';?
Thank you,The whole scenario is a little strange. When I tried to compile your procedure it couldn't compile, but I added the missing info and was able to get it compiled.
create or replace PROCEDURE TEST (EMPID IN VARCHAR2, rc OUT sys_refcursor)
IS
stmt VARCHAR2 (9272);
V_EMPID VARCHAR2 (100);
BEGIN
V_EMPID := EMPID;
stmt := 'select * from TEST123 where Empid is NOT NULL';
IF V_EMPID = '-1' THEN
stmt := stmt || ' and Empid in (:1)';
ELSE
stmt := stmt || ' and -1 = :1';
END IF;
OPEN rc FOR stmt USING V_EMPID;
END;If you pass in 1 as a parameter, it is going to execute because the statement that it is building is:
select * from TEST123 where Empid is NOT NULL and -1 = 1Although the syntax is valid -1 will never equal 1 so you will never get any data.
If you pass in 1,2 as a parameter then it is basically building the following:
select * from TEST123 where Empid is NOT NULL and -1 = 1,2This will cause an invalid number because it is trying to check where -1 = 1,2
You could always change your code to:
PROCEDURE TEST (EMPID IN VARCHAR2, rc OUT sys_refcursor)
IS
stmt VARCHAR2 (9272);
V_EMPID VARCHAR2 (100);
BEGIN
V_EMPID := EMPID;
stmt := 'select * from TEST123 where Empid is NOT NULL';
stmt := stmt || ' and Empid in (:1)';
OPEN rc FOR stmt USING V_EMPID;
END;and forget the if v_empid = '-1' check. If you pass in a 1 it will work, if you pass in 1,2 is will work, but don't pass them in with any tick marks.
Maybe you are looking for
-
Hi, i read that in Attributes u have do declare global variables , in Function group i declare it in Top,but if i have lot of global Variables where i have to put it ? like table types below DATA: BEGIN OF t_tab OCCURS 0, root(20) TYPE c,
-
Personal Hotspot option gone altogether after doing a carrier update
I was using my personal Hotspot for a month or so on IOS 8.1. I enabled it in Cellular data and everything was fine until I did a carrier update a few days ago. After that the personal Hostspot option itself dissapeared, and it went from the cellular
-
ITunes 9.02: Song playing but no sound
Have had an odd problem on the last couple of iTunes releases. When listening either on my MBP or over AirTunes, a song will play with no problem and will end normally. The next song will queue up, and appear to be playing (the progress bar moves, et
-
Clarification on the GSS-TSIG supported zone transfer in MS-DNS.
I have one clarification on the GSS-TSIG supported zone transfer in MS-DNS. I tried the following scenario in zone transfer, Configure my DNS server(supports GSS-TSIG algorithm for Zone transfer) as primary for a zone 'test.com' Configure MS-DNS as
-
Re: Problems with pulling data from database
OK, I figured it out I believe. In the second recordset called rsEligibility, I dimmed it, then set rsEligibility_svuserid= "0". and then put in an if statement. In IIS 5 it worked, but not in IIS6. What I had to do was take out the part that set rsE