SQL & PL/SQL :: Different Where Clause Based On In Parameter

Aug 30, 2011

how to use different where caluse based on different in parameter. say I pass 1,2 as parameter if it is 1 then the where condition > 10 else if it is 2 then the where condition <5 the where conditions are placed in cursor for loops.

View 2 Replies


ADVERTISEMENT

PL/SQL :: How To Pass List Of Values In Where Clause Of Query Parameter

Sep 18, 2012

I need to get multiple code values and put it into a variable which later need to pass into the where clause of an sql. But i am not getting any results even i pass those values in the variable of an where clause: below is my Procedure:

declare
TYPE crMain_record is RECORD (
v_code             dummy.v_code%type,
n_no               dummy.n_no%type,

[Code].....

END;"lv_character" is going to hold the multiple code values which i need to pass into whare clause of the above SQL: the totlal number of these mulitipe codes can be more then 50..

And lv_character values are commung from a setup table
lv_character varchar2(32767):= '('||''''||'COMMIS'||''''||' , '||''''||'AGY BUILDING BENS'||''''||')';
--And lv_character values are commung from a setup table.where "lv_character" holdes multipe code values...
And lv_character values are commung from a setup table and upper(d.v_code)in lv_characterif the

View 3 Replies View Related

Performance Tuning :: Pass 4000 - 5000 Parameter In IN Clause?

Mar 2, 2011

In my below query example , i have to pass more than 4000-5000 paramter in "a1.num" in below query. what is the best way to handle this, also if I pass more than 2000 paramter , the query takes a long time to execute. How can we solve the performance issue as well how I can pass more parameter.

SELECT c1, c2,
TO_CHAR (c3, 'HH24:MI'),
c4,
c5,

[code]...

View 12 Replies View Related

SQL & PL/SQL :: Calling A If Block Based On Parameter

Jan 11, 2013

I need to check the condition based what string I am sending. Suppose I am calling with

1.'a,b,c' then it should check all the if blocks.
2.'a,b' then it should check only 'a' and 'b' if blocks.

Is it possible to do so?

DECLARE
a VARCHAR2(5):=0;
b VARCHAR2(5):=0;
c VARCHAR2(5):=0;
PROCEDURE p1(
p_str VARCHAR2)
IS
BEGIN
[code]....... I

View 7 Replies View Related

SQL & PL/SQL :: Order By Based On Input Parameter?

Jun 29, 2011

I have created the Procedure P_GET_CURRENCIES. I want to sort the cursor query based on the Input parameter P_SORT_ORDER. For example if i pass 2 for P_SORT_ORDER then my query should be sorted by 2nd column. But i'm not getting correct Output.

PROCEDURE P_GET_CURRENCIES(P_START_ROW_NUM IN INTEGER
,P_END_ROW_NUM IN INTEGER
,P_SORT_ORDER IN number
,P_CURRENCY_DATA OUT SYS_REFCURSOR
,P_RETURN_MESSAGE OUT VARCHAR2 )
AS

[code]....

View 3 Replies View Related

SQL & PL/SQL :: Filtering SELECT Statement Based On Parameter?

May 26, 2010

Below is the code as currently written which works fine for Delta records processing (based on the field called activ_dt).

/*
Custom extract
Project: XYZ Price Data Extract
Product: EOWin 4.02 - Oracle database
Use : Script to create the above XYZ Extract and spool the results to a text file
Input Parameters:

[code]....

My problem is I am trying to add a 3rd parameter which will tell the extract to pull all of the data or just the deltas. So I added &3 to the comments and I have tried putting CASE or DECODE functions into the WHERE clause with no luck. I also tried to do a CASE or DECODE with two different SELECTS, again with no luck.

An example of my failed attempt to add &3 and handle F or D

/*
Custom extract
Project: XYZ Price Data Extract
Product: EOWin 4.02 - Oracle database
Use : Script to create the above XYZ Extract and spool the results to a text file
Input Parameters:

[code]....

View 16 Replies View Related

SQL & PL/SQL :: Ordering The Result Set Based On Input Parameter

Aug 2, 2013

I need to order the result set with different data types based on the input parameter.

select * from scott.emp sc order by decode('&input_parameter',1,sc.empno,2, sc.ename);

If the input_parameter is equals to 1 then,ordering should be based on EMPNO which is Number data type.
If the input_parameter is equals to 2 then,ordering should be based on ENAME which is Character Data type.

Above query was failed for input_parameter 2,as we know that decode should return same data type.

View 6 Replies View Related

SQL & PL/SQL :: Setting Variable In Procedure Based On Parameter?

May 24, 2011

I am reading in a selection of parameters. I have created a new variable which I want to set according to the value of one of the input parameters.

I am doing this straight after declaring the variable, but before the cursors and BEGIN statement It is throwing an error when I do this - but I have to do it before the cursors.the variable I am setting is: v_fptransType you can see the IF statement towards the end of the code.

the error I am getting is:Error(28,3): PLS-00103: Encountered the symbol "IF" when expecting one of the following: begin function package pragma procedure subtype type use <an identifier> <a double-quoted delimited-identifier> form current cursor The symbol "begin" was substituted for "IF" to continue.

beginning of the

create or replace
PROCEDURE "P_GLPOST" (i_entity IN varchar2, i_transType IN varchar2, i_startDate IN VARCHAR2,
i_endDate IN VARCHAR2, i_accountPeriod IN VARCHAR2, i_includeInternals IN NUMBER, i_chargeable IN NUMBER, i_trialPost IN NUMBER,
i_postingReport IN NUMBER, TESTER IN VARCHAR2) is
--set serveroutput on size 1000000;

[code].....

View 8 Replies View Related

PL/SQL :: Change Table Name Dynamically Based On Parameter

May 10, 2013

I am new to PL/SQL, worked mostly on SQL server, I have to change the table name dynamically based on the parameter.and used a ref_cursor to display the results in a report. when I execute it throws me an error.

create or replace procedure test1 (
p_eod_date IN VARCHAR2,
p_link IN NUMBER,
c_rec IN OUT SYS_REFCURSOR)
[code]....

View 10 Replies View Related

SQL & PL/SQL :: Convert As Procedure Based On Input Date Parameter

Dec 12, 2012

i have the below query

select to_char(report_date, 'YYYY MM Mon'), count(1) no_of_times
from (
select to_date('&&YYYYMMDD', 'YYYYMMDD')+rownum report_date
, mod(rownum,14) mod_result
from all_objects

[code]...

need to convert as procedure based on input date parameter.I will pass the input date from java environment and need to see the sql query output in front end.

View 7 Replies View Related

Client Tools :: Controlling Prompt Based On Previous Parameter

Apr 9, 2013

I need to accept value for some variables using substitution variable. I have a number of variables for which I need to take the value on run time. I need to prompt a parameter based on the value provided earlier.

For example;

There is prompt to enter country. If the user enters country as India it should prompt for the state else it should not prompt for state.

How can this be handled in SQL?

View 3 Replies View Related

SQL & PL/SQL :: Column Access In Table Based On User Parameter Input

Nov 10, 2010

Need to access data in a table base on user parameter input where the data is stored like a spreadsheet with column headings JAN, FEB, MAR... and the rows are the years. Is there a way to create a generic SQL statement so that I don't have to have 12 if statements in the procedure?

View 5 Replies View Related

SQL & PL/SQL :: OrderBy Clause Before From Clause?

Apr 23, 2010

can we use something like this

"select ... order by emp from emp"

what is to be done? so that this qurey runs. no co-related subquery to be used.

View 6 Replies View Related

SQL & PL/SQL :: Using 1=1 In Where Clause?

Nov 9, 2011

what is the use of 1=1 in the where clause?

View 10 Replies View Related

Import With Where Clause?

Jul 30, 2010

I have a exp .dmp file of a database that has over 1000 tables. I would like to import all tables that don't begin with 'C'. Is this possible with IMP (without listing each table I want)?

View 1 Replies View Related

SQL & PL/SQL :: Hierarchical And With Clause

Jul 31, 2013

>select level ,empno,ename,mgr
from emp
connect by prior empno=mgr
start with mgr is null;

Output:-
>
LEVEL EMPNO ENAME MGR
----- ---------- ---------- ----------
1 7839 KING
2 7566 JONES 7839
3 7788 SCOTT 7566
4 7876 ADAMS 7788
3 7902 FORD 7566
2 7698 BLAKE 7839
3 7499 ALLEN 7698
3 7521 WARD 7698
3 7654 MARTIN 7698
3 7844 TURNER 7698
3 7900 JAMES 7698

LEVEL EMPNO ENAME MGR
----- ---------- ---------- ----------
2 7782 CLARK 7839
3 7934 MILLER 7782

Note:- I got only this that this query is alternative of self join and it is giving manager name along with mgr id for each employee but when it gives output i couldn't able to understand how to identify who is manager of whom. Tell and explain with clause in oracle , i only know it is alternative of inline view but i want to know how does it work and how to use 'WITH' in oracle query if possible.

View 4 Replies View Related

SQL & PL/SQL :: Decode In Where Clause

Aug 3, 2013

I have a scenario where in report table I need to get

IF FLAG='Y' AND LOC=118443 THEN STATE='FIN'
IF FLAG='Y' AND LOC!=118443 THEN STATE SHOULD BE ('COMP','PART')
IF FLAG='N' IT SHOULD INCLUDE ALL STATES.

I tried using decode in WHERE CLAUSE , but not successful.

Create Table Report(Id Number,Loc Number,Flag Varchar2(3),State Varchar2(20));
table REPORT created.

Insert Into Report Values(1,1,'Y','COMP');
1 rows inserted.

Insert Into Report Values(2,118443,'Y','FIN');
1 rows inserted.

Insert Into Report Values(7,118443,'Y','COMP');
1 rows inserted.
[code]...

View 14 Replies View Related

SQL & PL/SQL :: Group By Clause

Mar 31, 2011

This time, I am going to provide the DML statements.

I have a simple table with 3 fields in it.I want to group by ACCT_NUMBER and sum of BALANCE field. But I want to get the description of the first row in a group.

the statements below. Here there are two groups of records 2001 and 2002. My sql(which I am working on) should return the following :

2001 EMPL TRAINING-MIS 20
2002 OTHER PROF SERV-HR 40

The following query will group by ACCT_NUMBER and sum of the BALANCE field. But how can I get the DESCRIPTION?

SELECT ACCT_NUMBER, SUM(BALANCE)
FROM TEST
GROUP BY ACCT_NUMBER
CREATE TABLE "TEST"
("ACCT_NUMBER" VARCHAR2(20 BYTE),
"DESCRIPTION" VARCHAR2(20 BYTE),

[code]...

View 5 Replies View Related

SQL & PL/SQL :: Where Clause In Concat

Jul 24, 2010

I has a table with team names like

Table name:- Teams

Structure:- name
Ind
Aus
Pak

I want the o/p as:- Fixtures
Ind Vs Aus
Ind Vs Pak
Aus Vs Pak
.......

I tried it but failed in what condition to use in the where clause.I did up to this:-

select name||' Vs ' || name from teams where .......;

how to get the result.

View 2 Replies View Related

SQL & PL/SQL :: WITH Clause In Oracle 11g R2

Sep 20, 2012

I am getting error 'ORA-03113: end-of-file on communication channel' in Oracle 11g R2 version when I ran the below query.

WITH tab1 AS (SELECT C_NUM as col1 FROM test123_v)
SELECT COUNT (distinct col1) num_assignments FROM tab1
UNION ALL
SELECT COUNT (distinct col1) num_assignments FROM tab1

The same query is working fine in 10g.Here test123_v is view created using table test123, which has one column c_num.When I use the table instead of view in the with clause I am getting the output in 11g. The below query gives the output.

WITH tab1 AS (SELECT C_NUM as col1 FROM test123)
SELECT COUNT (distinct col1) num_assignments FROM tab1
UNION ALL
SELECT COUNT (distinct col1) num_assignments FROM tab1

View 2 Replies View Related

SQL & PL/SQL :: Decode With Between Clause

Aug 11, 2011

I have a small doubt...Without any creation of tables as I feel it's not needed...(let me know if u need them) Error says "Missing Keyword"

select distinct record_number
from meta m, procedu b, control v, fact f, calendar dc, person p
where f.key = m.key and f.group_key = b.group_key
and b.proc_key = v.proc_key
and f.calendar_key = dc.calendar_key
and f.person_key = p.person_key
and VALUE BETWEEN DECODE((Select distinct operator_type
[code]....

But this gives an error...If the decode gives a "single"...the statement is working fine...but If the decode gives a "range"...the above statement gives an error saying "missing keyword"..Does the above code when mapped to "Range"...is it not producing "and" like " value between 100 and 1000"

View 4 Replies View Related

SQL & PL/SQL :: Order By Clause?

Mar 12, 2013

I have requirement to create an XML structure through stored procedure. I need to Order some of the columns in ascending order before I format them into the xml structure. I am pretty novice to creating an output into XML format, but attached is the query I came up with (without order by). This works perfect, but now the requirement is to order by - cls_cd, and within cls_cd, again order by - cat_cd. I am not able to do this.

View 2 Replies View Related

SQL & PL/SQL :: From Clause With Conditions

Apr 2, 2013

You think i can do a from clause with conditions ??

The reason is that i need to retrieve fields from different schemas depending on a column in a common table

let s say the column CRITERIA_COL is in table Common
If COMMON.CRITERIA_COL has value 1 then the select query should fetch results from the schema : SCHEMA1.MY_TABLE
If COMMON.CRITERIA_COL has value 2 then the select query should fetch results from the schema : SCHEMA2.MY_TABLE
If COMMON.CRITERIA_COL has value 3 then the select query should fetch results from the schema : SCHEMA3.MY_TABLE

Something like this:

Select my_Col1, my_Col2 from
(case COMMON.CRITERIA
when '1' then SCHEMA1.MY_TABLE
when '2' then SCHEMA2.MY_TABLE
when '3' then SCHEMA3.MY_TABLE
)

but that is not working .By the way my query is not just that, it s a more complicated query, that s just the portion I am having trouble with .

View 1 Replies View Related

SQL & PL/SQL :: Sysdate In Where Clause

Apr 22, 2010

I am not strong in SQL but can write easy SQL for data extraction but seem to not understand how to correctly use sysdate in a where clause.

Case: I have to create an alert that will email my IT dept once a person is terminated in Oracle HR. The alert will only run once a day with all terminations specified in the alert. Setting up the alert is not the issue, but rather the SQL code I want to use.

The alert will run everyday at CoB 17:30. Now, in my query, how do i specify that the results should be only for the current day? The problem however, is that I also retrieve Person Type which should show as Ex-Employee, but this is only shown the day after the actual termination has been done, because the employee is still active on the date of termination.

View 13 Replies View Related

SQL & PL/SQL :: Variable In The From Clause

May 8, 2013

Is there a way to have a variable in the FROM clause or another way to have the table name as a variable? I'm trying to not repeat the same query three times with only the table name being different.

---the tables

create table org_a (emp_id number(5) not null, name varchar2(20));
create table org_b (emp_id number(5) not null, name varchar2(20));
create table org_c (emp_id number(5) not null, name varchar2(20));

---the records

INSERT ALL
INTO org_a (emp_id, name) VALUES (00001, 'MISTER WHITE')
INTO org_a (emp_id, name) VALUES (00002, 'MISTER ORANGE')
INTO org_b (emp_id, name) VALUES (00003, 'MISTER PINK')
INTO org_b (emp_id, name) VALUES (00004, 'MISTER BROWN')
INTO org_c (emp_id, name) VALUES (00005, 'MISTER BLUE')
INTO org_c (emp_id, name) VALUES (00006, 'MISTER BLOND')
SELECT * FROM dual;

---verify inserts

SELECT * FROM org_a
UNION ALL
SELECT * FROM org_b
UNION ALL
SELECT * FROM org_c;

---i want the table name to be dependent on a variable. eventually,
---i intend to link v_org to a form with radio buttons (values: 1, 2, 3)
---to keep this simple, i'll just assign 1 to v_org

DECLARE

v_org number(1) := 1;
v_table varchar2(5);

BEGIN
v_table :=
CASE v_org WHEN 1 THEN 'org_a'
WHEN 2 THEN 'org_b'
WHEN 3 THEN 'org_c'
END;

SELECT * FROM v_table;

END;

--this is what i receive

SQL> /
SELECT * FROM v_table;
*
ERROR at line 10:

ORA-06550: line 10, column 17:
PL/SQL: ORA-00942: table or view does not exist
ORA-06550: line 10, column 3:
PL/SQL: SQL Statement ignored

View 22 Replies View Related

SQL & PL/SQL :: Inner Join Used Using Clause?

Apr 11, 2012

Equi join (Inner join)

It is the simplest join or inner. An equijoin combines rows that have equivalent values for the specified columns.

SQL> select * from x;

NAME EMAIL EMPID
Sam email@removed 1060
Rose email@removed 1061

[code]....

don't consider above mentioned queries I got valuable outputs.

NAMEEMAIL EMPID NAME EMAIL EMPID
samemail@removed 1060 sam email@removed 1060
roseemail@removed 1061 rose email@removed 1061
sonaemail@removed 1062 sona email@removed 1062

Inner join shows matches only when they exist in both tables.so , i got records 1060,1061,1062

// Referencing columns used in a USING clause.
SQL> select x.name,x.email,x.empid from x
2 inner join y
3 using (empid);

select x.name,x.email,x.empid from x
*
ERROR at line 1:
ORA-25154: column part of USING clause cannot have qualifier

so query rewritten as

SQL> select x.name,x.email,empid from x
2 inner join y
3 using (empid);
NAME EMAIL EMPID
--------------- --------------- ----------
sam email@removed 1060
rose email@removed 1061
chris email@removed 1062

I mean see two different outputs.first output records twice displayed ... Yes i agree that is Inner join.second output records not displayed twice... common records only displayed once ,in x and y.

I think should n't use a table name or alias when referencing columns used in a USING clause... am i right ????

I want to know both are inner joins .how Oracle is determined both outputs ?

View 13 Replies View Related

SQL & PL/SQL :: In Clause Is Not Working?

Sep 18, 2013

SELECT sno,mid,mname
FROM manage_date
WHERE mname IN
('KIRAN-KUMAR',
'RAHUL-RAJ',
'KAUSHAL-SONI');

IF I use this query directly in DB it's working fine. But when this query is calling in .net using parameter as below it's not giving any records for more than one value. IN (:p_mname)

If I pass one name 'KIRAN-KUMAR' from .net It's working.

If I pass multiple names from .net query not returning any records.

View 4 Replies View Related

SQL & PL/SQL :: Dynamic WHERE Clause - Too Big

Aug 18, 2011

I have to create a WHERE clause like :

SELECT * FROM wc_claims WHERE part_nbr in l_part_nbr ;

I have three tables:
table A has - user_id, supplier
table B has - supplier, part_nbr
table C , wc_claims, has part_nbr and 78 other columns.

what i need to do is when user logs in with his user_id, he should see only that info from table C, corresponding to his supplier, and the part_nbr.

SELECT supplier from table_A WHERE user_id = 'abc' ;
supp_abc
SELECT distinct part_nbr from table_B WHERE supplier = 'supp_abc' ;
partA, partB, partC,........partZZ

SELECT * FROM wc_claims WHERE part_nbr in (partA, partB, partC,........partZZ );

I have created a function :

create or replace Function wcl_partnbr ( p_supp IN varchar2 )
RETURN CLOB
IS

[Code].....

so that I can use that in the WHERE clause, because one supplier can have thousands of parts...so it works fine, if there are 200 part numbers for one supplier, but above that.. it doesnt.

View 15 Replies View Related

SQL & PL/SQL :: Dynamic Where Clause

Jul 9, 2010

I having below table :

EXAM2@orcl> desc search_table;
Name Null? Type
----------------------------------------- -------- ----------------------------
ROL NOT NULL VARCHAR2(7)
CNM NOT NULL VARCHAR2(30)
FNM NOT NULL VARCHAR2(30)
MNM NOT NULL VARCHAR2(30)
DOB NOT NULL DATE
YEAR NOT NULL NUMBER(4)
EXAM NOT NULL VARCHAR2(1)
MAIN_SUPP NOT NULL VARCHAR2(1)

In a dotnet application user is going to input/select all/any of the above column in where clause.If user has given value for rol column then ref cursor should be :

select * from search_table where rol like <given value>
endif
and/or

If user has given value for cnm column then ref cursor should be :

select * from search_table where rol like <given value> and/or cnm like <given value>
endif

I mean whatever value is being given; it should be part of where clause.For it i am going to :

EXAM2@orcl> CREATE OR REPLACE PACKAGE rollsearch AS
2 TYPE t_cursor IS REF CURSOR;
3 Procedure rol_cursor(c_rol in varchar2,c_cnm in varchar2,c_fnm in varchar2,
4 c_mnm in varchar2,d_dob in date,n_year in number,c_exam in varchar2,c_main_supp in varchar2,
5 io_cursor IN OUT t_cursor);
6 END rollsearch;
7 /

EXAM2@orcl> CREATE OR REPLACE PACKAGE BODY rollsearch AS
2 Procedure rol_cursor(c_rol in varchar2,c_cnm in varchar2,c_fnm in varchar2,
3 c_mnm in varchar2,d_dob in date,n_year in number,c_exam in varchar2,c_main_supp in varchar2,
4 io_cursor IN OUT t_cursor)
5 IS
6 v_cursor t_cursor;
7 sql varchar2(1000);
8 BEGIN
9

What should i write further; so that i may get ref cursor as whereed clause for given value. So that i may populate my datagrid view for that web form.

View 14 Replies View Related

PL/SQL :: Use Of Commit Clause

Dec 28, 2012

I have this stored procedure and sequences:

create sequence a_seq;
create sequence b_seq maxvalue 26 cycle;
create sequence c_seq maxvalue 1000 cycle;

create or replace
procedure inserta_en_B (numregistros in integer) as
ultimo_año_nuevo date := trunc (sysdate,'year');
dias_transcurridos number(3) := sysdate - ultimo_año_nuevo;
begin
[code]........

First i insert into b 400000 rows using:

execute inserta_en_b(400000));
commit;

But then i need to insert 100000 rows more using the stored procedure and without removing the 400000 rows stored before. I think i need to use the commit clause, but i dont know where.

View 3 Replies View Related







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