Using Select statement in IF condition?
hi all,
Can i use select statement in IF COndition in pl sql ?
eg like- if( select 1 from ASD) then
end if;
There is no way to do any kind of select statement inside if conditions.
Why don't test simple cases like this first?
An example to show it.
SQL> begin
2 if exists (select 1 from dual) then
3 dbms_output.put_line('ok');
4 end if;
5 end;
6 /
if exists (select 1 from dual) then
ERRORE alla riga 2:
ORA-06550: line 2, column 5:
PLS-00204: function or pseudo-column 'EXISTS' may be used inside a SQL
statement only
ORA-06550: line 2, column 2:
PL/SQL: Statement ignored
SQL> begin
2 if ( (select count(*) from dual) > 0 ) then
3 dbms_output.put_line('ok');
4 end if;
5 end;
6 /
if ( (select count(*) from dual) > 0 ) then
ERRORE alla riga 2:
ORA-06550: line 2, column 8:
PLS-00103: Encountered the symbol "SELECT" when expecting one of the following:
( - + case mod new not null others <an identifier>
<a double-quoted delimited-identifier> <a bind variable> avg
count current exists max min prior sql stddev sum variance
execute forall merge time timestamp interval date
<a string literal with character set specification>
<a number> <a single-quoted SQL string> pipe
<an alternatively-quoted string literal with character set specification>
<an alternativ
ORA-06550: line 2, column 33:
PLS-00103: Encountered the symbol ")" when expecting one of the following:
. , @ ; for <an identifier>
<a double-quoted delimited-identifier> group having intersect
minus order partition start subpartition union where connect
SQL> begin
2 if ( 0 in (select count(*) from dual) ) then
3 dbms_output.put_line('ok');
4 end if;
5 end;
6 /
if ( 0 in (select count(*) from dual) ) then
ERRORE alla riga 2:
ORA-06550: line 2, column 12:
PLS-00405: subquery not allowed in this context
ORA-06550: line 2, column 2:
PL/SQL: Statement ignoredBye Alessandro
Similar Messages
-
REG:- SELECT STATEMENT IN IF CONDITION.
HI FRIENDS,
CAN V USE SELECT STATEMENT IN IF CONDITION LIKE....
IF (SELECT COUNT(EMPID) FROM EMPLOPYEE) > 1 THEN
UPDATE STATEMENT;
END IF;
PLEASE HELP.
--RAJNISHHi,
1. Hit the Caps Lock key hard in your key board.
2. Put your code between tags for better readability.
3. When you have a where clause, why do you want to go for if clause? as in
[code]
update <your_table> set <your_col> = <your_new_val>
where (select count(empid) from employee) > 1
[/code]
is logically equivalent to your
[code]
if (select count(empid) from employee) > 1 then
update statement;
end if;
[/code]
-Arun -
Number of rows inserted is different in bulk insert using select statement
I am facing a problem in bulk insert using SELECT statement.
My sql statement is like below.
strQuery :='INSERT INTO TAB3
(SELECT t1.c1,t2.c2
FROM TAB1 t1, TAB2 t2
WHERE t1.c1 = t2.c1
AND t1.c3 between 10 and 15 AND)' ....... some other conditions.
EXECUTE IMMEDIATE strQuery ;
These SQL statements are inside a procedure. And this procedure is called from C#.
The number of rows returned by the "SELECT" query is 70.
On the very first time call of this procedure, the number rows inserted using strQuery is *70*.
But in the next time call (in the same transaction) of the procedure, the number rows inserted is only *50*.
And further if we are repeating calling this procedure, it will insert sometimes 70 or 50 etc. It is showing some inconsistency.
On my initial analysis it is found that, the default optimizer is "ALL_ROWS". When i changed the optimizer mode to "rule", this issue is not coming.
Anybody faced these kind of issues?
Can anyone tell what would be the reason of this issue..? any other work around for this...?
I am using Oracle 10g R2 version.
Edited by: user13339527 on Jun 29, 2010 3:55 AM
Edited by: user13339527 on Jun 29, 2010 3:56 AMYou have very likely concurrent transactions on the database:
>
By default, Oracle Database permits concurrently running transactions to modify, add, or delete rows in the same table, and in the same data block. Changes made by one transaction are not seen by another concurrent transaction until the transaction that made the changes commits.
>
If you want to make sure that the same query always retrieves the same rows in a given transaction you need to use transaction isolation level serializable instead of read committed which is the default in Oracle.
Please read http://download.oracle.com/docs/cd/E11882_01/appdev.112/e10471/adfns_sqlproc.htm#ADFNS00204.
You can try to run your test with:
set transaction isolation level serializable;If the problem is not solved, you need to search possible Oracle bugs on My Oracle Support with keywords
like:
wrong results 10.2Edited by: P. Forstmann on 29 juin 2010 13:46 -
How to pass parameter in Function by using select statement?
Hi,
I got a problem. I cant pass in parameter to function by using select statement. But it can pass in parameter by using 'hardcode' method. How can I solve this problem?
Eg,
select * from table (SplitFunction('HS750020,HS750021')) <<< this work.
but
select * from table (SplitFunction(select LOT_NO from TRACER_SEARCH_SCHEDULE where JOB_ID = '36')) <<< do not work.
Thanks for who try to help. Thanks.skymonster84 wrote:
I have try this before. But it not work.here is an example
create or replace type stringlist as table of varchar2(100)
create or replace function splitstring(pstring in varchar2) return stringlist
as
lstringlist stringlist;
begin
select regexp_substr(pstring,'[^,]+',1, level) bulk collect into lstringlist
from dual
connect by level <= length(pstring)-length(replace(pstring,','))+1;
return lstringlist;
end;
select * from table(select splitstring('xx,yy,zz') from dual)
create table t(str varchar2(100))
insert into t values('x,y,z')
insert into t values('a,b,c')
select * from table(select splitstring(str) from t where rownum<2)
/If you supply multiple values then it will fail.
select * from table(select splitstring(str) from t)
/ -
Hi,
I am trying to insert values using select statement. But this is not working
INSERT INTO contribution_temp_upgrade
(PRO_ID,
OBJECT_NAME,
DELIVERY_DATE,
MODULE_NAME,
INDUSTRY_CATERGORIZATION,
ADVANTAGES,
REUSE_DETAILS)
VALUES
SELECT
:P1_PROJECTS,
wwv_flow.g_f08(vRow),
wwv_flow.g_f09(vRow),
wwv_flow.g_f10(vRow),
wwv_flow.g_f11(vRow),
wwv_flow.g_f12(vRow),
wwv_flow.g_f13(vRow)
FROM DUAL;
Please let me know what i am missing..
Thanks
SudhirTry this
INSERT INTO contribution_temp_upgrade
(PRO_ID,
OBJECT_NAME,
DELIVERY_DATE,
MODULE_NAME,
INDUSTRY_CATERGORIZATION,
ADVANTAGES,
REUSE_DETAILS)
SELECT
:P1_PROJECTS,
wwv_flow.g_f08(vRow),
wwv_flow.g_f09(vRow),
wwv_flow.g_f10(vRow),
wwv_flow.g_f11(vRow),
wwv_flow.g_f12(vRow),
wwv_flow.g_f13(vRow)
FROM DUAL;Note: when you are selecting a value using select statement, you should not specify the keyword "values".
i assume you have already assigned value for your bind variable :P1_PROJECTS and rest of the functions will return some value.
Regards,
Prazy -
How can I select columns from a table EMP, using Select statement?.
Hi Friends,
How can I select columns from a table EMP?.
I want to select columns of EMP table, using select statement.
Please reply me urgently.
ShahzadSomething like this:
scott@DBA> select empno,ename,job from emp;
EMPNO ENAME JOB
7369 SMITH CLERK
7499 ALLEN SALESMAN
7521 WARD SALESMAN
7566 JONES MANAGER
7654 MARTIN SALESMAN
7698 BLAKE MANAGER
7782 CLARK MANAGER
7788 SCOTT ANALYST
7839 KING PRESIDENT
7844 TURNER SALESMAN
7876 ADAMS CLERK
7900 JAMES CLERK
7902 FORD ANALYST
7934 MILLER CLERK
14 rows selected.Check the documentation:
http://download-east.oracle.com/docs/cd/B19306_01/server.102/b14200/statements_10002.htm#sthref9697
Message was edited by:
Delfino Nunez -
How to fetch negative sign data using select statement
hi gurus,,
i hv to fetch data which is negative in nature using select statement i m using ppdit table and wrbtr field.(it contains both negative and positive data)....wat sud i add with select statement...plz help me..
thnx in advance
Message was edited by:HI,
I think you can use LT or < 0.0 in the WHERE clause to get all the -ve values. Once you get them treat them as negative.
Regards,
Sesh -
FETCHING VALUES IN MULTI RECORD BLOCK FROM ANOTHER TABLE USING SELECT STATEMENT.
Hi,
I have one multi record block in which i want to fetch values
(more then one record) from another table using select statement
IN KEY NEXT ITEM.I am getting following error.
ORA-01422: exact fetch returns more than requested number of rows
Thanks in advance.In your case I see no reason to use non-database block and to try to populate it from a trigger with a query, instead of using the default forms functionality where you can associate the block and the fields with table, create where clause using bind variables and simply use execute_query() build-in to populate the block. The power of the forms is to use their build-in functionality to interact with the database.
Also, you can base your block on a query, not on a table and you dynamically change this query using set_block_property() build-in. You can use any dynamic queries (based on different data sources) and you simply need to control the column's data type, the number of the columns and their aliases. Something like creating inline views as a block data source.
However, you can replace the explicit cursor with implicit one like
go_block('non_db_block_name');
first_record();
FOR v_tab IN (SELECT *
FROM tab
WHERE col_name = :variable)
LOOP
:non_db_block_name.field1 := v_tab.col1;
:non_db_block_name.field2 := v_tab.col2;
next_record();
END LOOP; -
Can i use select statements in LDB
Hai All,
Can i use select statements and internal table in a LDB program.
my requirement is that if i enter company code , fiscal year and reporting periods.
generally fiscal year will be jan to dec.but in my requirement the fiscal year is apr of previous year to march of currentyear.
so as i require the last years data can iuse select statement in that ldb program or is there any solution for this.
Thanks in Advance
kiranHi Kiran,
To retrive records from ldb you have to use the
GET <node> statement. This will invoke the selection screen of the node. An alternate solution is to use the function module LDB_PROCESS.
Please see the following link for help and example
http://help.sap.com/saphelp_nw04/helpdata/en/64/237f8cd43711d1950b0000e8353423/content.htm
Thanks
Vinod -
How to get the inserted row primary key with out using select statement
how to return the primary key of inserted row ,with out using select statement
Edited by: 849614 on Apr 4, 2011 6:13 AMyes thanks to all ,who helped me .its working fine
getGeneratedKeys
String hh = "INSERT INTO DIPOFFERTE (DIPOFFERTEID,AUDITUSERIDMODIFIED)VALUES(DIPOFFERTE_SEQ.nextval,?)";
String generatedColumns[] = {"DIPOFFERTEID"};
PreparedStatement preparedStatement = null;
try {
//String gen[] = {"DIPOFFERTEID"};
PreparedStatement pstmt = conn.prepareStatement(hh, generatedColumns);
pstmt.setLong(1, 1);
pstmt.executeUpdate();
ResultSet rs = pstmt.getGeneratedKeys();
rs.next();
// The generated order id
long orderId = rs.getLong(1); -
How to avoid data repetation when using select statements with innerjoin
how to avoid data repetation when using select statements with innerjoin.
thanks in advance,
satheeshyou can use a query like this...
SELECT DISTINCT
frg~prc_group1 "Product Group 1
frg~prc_group2 "Product Group 2
frg~prc_group3 "Product Group 3
frg~prc_group4 "Product Group 4
frg~prc_group5 "Product Group 5
prc~product_id "Product ID
txt~short_text "Product Description
UP TO 10 ROWS
INTO TABLE l_i_data
FROM
Joining CRMM_PR_SALESG and
COMM_PR_FRG_ROD
crmm_pr_salesg AS frg
INNER JOIN comm_pr_frg_rod AS prd
ON frgfrg_guid = prdfragment_guid
Joining COMM_PRODUCT and
COMM_PR_FRG_ROD
INNER JOIN comm_product AS prc
ON prdproduct_guid = prcproduct_guid
Joining COMM_PRSHTEXT and
COMM_PR_FRG_ROD
INNER JOIN comm_prshtext AS txt
ON prdproduct_guid = txtproduct_guid
WHERE frg~prc_group1 IN r_zprc_group1
AND frg~prc_group2 IN r_zprc_group2
AND frg~prc_group3 IN r_zprc_group3
AND frg~prc_group4 IN r_zprc_group4
AND frg~prc_group5 IN r_zprc_group5.
reward it it helps
Edited by: Apan Kumar Motilal on Jun 24, 2008 1:57 PM -
Hi,
How can I use select stat. rather than join to join to tables so that I have all the fields from both tables appearing in my output.Hi,
There are two ways to handle the problem.
1. For all entries
Types: begin of str1_tab,
lgnum type lgnum,
ivnum type LVS_IVNUM,
ivpos type LVS_IVPOS,
lgtyp type lgtyp,
lgpla type lgpla,
idatu type LVS_IDATU,
uname type LINK_UNAME,
end of str1_tab.
Data: it_tab1 type table of str1_tab,
wa_tab1 like line of it_tab1.
DATA: it_tab3 TYPE TABLE OF str1_tab,
wa_tab3 LIKE LINE OF it_tab3.
select lgnum ivnum lgtyp uname FROM link INTO CORRESPONDING FIELDS OF
TABLE it_tab1 where lgnum = pa_lgnum AND ivnum IN s_ivnum.
<b>if sy-subrc eq 0.</b>
select lgnum ivnum lgpla idatu from linp into corresponding
fields of table it_tab3 for all entries in it_tab1 <b>where lgnum = itab1-lgnum and ivnum = itab1-ivnum.</b><b>endif.</b>
LOOP AT it_tab3 INTO wa_tab3.
<b>clear wa_tab1.</b>
READ TABLE it_tab1 INTO wa_tab1 WITH
KEY lgnum = wa_tab3-lgnum
ivnum = wa_tab3-ivnum.
IF sy-subrc = 0.
move-corresponding it_tab1 to it_tab3.
<b>modify it_tab3 from wa3 transporting lgtyp uname where lgnum = wa_tab3-lgnum
and ivnum = wa_tab3-ivnum.</b>ENDIF.
clear it_tab3.
endloop.
2. Use inner join
Types: begin of str1_tab,
lgnum type lgnum,
ivnum type LVS_IVNUM,
ivpos type LVS_IVPOS,
lgtyp type lgtyp,
lgpla type lgpla,
idatu type LVS_IDATU,
uname type LINK_UNAME,
end of str1_tab.
Data: it_tab1 type table of str1_tab,
wa_tab1 like line of it_tab1.
select linklgnum linkivnum linklgtyp linkuname linplgpla linpidatu FROM link inner join linp on linklgnum = linplgnum
and linkivnum = linkivnum
into TABLE it_tab1 where lgnum = pa_lgnum AND ivnum IN s_ivnum.
Now itab1 will contain all the values -
How to insert variable value using select statement - Oracle function
Hi,
I have a function which inserts record on basis of some condition
INSERT INTO Case
Case_ID,
Case_Status,
Closure_Code,
Closure_Date
SELECT newCaseID,
caseStatus,
Closure_Code,
Closure_Date,
FROM Case
WHERE Case_ID = caseID
Now i want new casestatus value in place of select statement caseStatus value. I have a variable m_caseStatus and i want to use the value of this variable in above select statement.
how can i use this.
thanksHi,
I have a function which inserts record on basis of some condition
INSERT INTO Case
Case_ID,
Case_Status,
Closure_Code,
Closure_Date
SELECT newCaseID,
caseStatus,
Closure_Code,
Closure_Date,
FROM Case
WHERE Case_ID = caseID
Now i want new casestatus value in place of select statement caseStatus value. I have a variable m_caseStatus and i want to use the value of this variable in above select statement.
how can i use this. Do not select Case_Status from inner select, so null will be inserted then after inserting it update the case status with m_caseStatus.
Regards. -
How to get all values from an interval using select statement
Hi,
Is it possible to write a select statement that returns all values from an interval? Interval boundaries are variable.
something like this:
select (for x in 1,1024 loop x end loop) from dual
(this, of course, doesn't work)
The result in this example should be 1024 rows of numbers from 1 to 1024. These numbers are parameters, so it is not possible to create a table with predefined values.
Thanks in advance for your help,
Mia.For your simple case, with a lower boundary of 1, you can use:
SELECT rownum
FROM all_objects
WHERE rownum <= 1024For a set of number between say 50 - 100, you can use something like:
SELECT rownum + (50 - 1)
FROM all_objects
WHERE rownum <= (100 - 50 + 1)Note, that all_objects was used only because it generally has a lot of rows. Any table with at least the number of rows in your range will work.
TTFN
John -
How to use SELECT statement to extract KNA1-NAME1 and KNB1-ZSABE
In building table I_KNA1 in form f_extract_data, an additional select statement is needed to select and append datafrom (KNA1 and KNB1) to existing I_KNA1
In form f_extract_data table i_kna1 is populated with data from zd_kna101.(where ZD_KNA101 is a view of KNA1, KNB1 and KNBK. It's a joint of these three tables.) This will take care of all customers with KNBK-BANKL and KNBK-BANLN populated. But this does not include new customers created in SAP CRM (no KNBK records). Therefore a separate SELECT statement is needed to extract KNA1-NAME1 and KNB1-ZSABE for customers created in SAP CRM(the customers who do do not have BANKL and BANKN). These selected records are then need to be appended to I_KNA1. It's possible that new selection statement might extract records that are already in existing I_KNA1 table. IF this is the case, right after the append, sort I_KNA1 and remove duplicate records.
form f_extract_data.
select kunnr " Customer Number
name1 " Name
zsabe " Business Unit
bankl " Legacy Bank Key
bankn " Legacy Bank Account
from zd_kna101 " View of KNA1, KNB1, and KNBK
into table i_kna1
for all entries in i_doc_by_ref
where kunnr = i_doc_by_ref-kunnr
and zsabe in s_zsabe.
if sy-subrc <> 0.
message a116 with 'customer'. " Customer Table is empty. HALT!!!
else.
sort i_kna1 by kunnr.
endif.
will I have to use the join statement(for KNA1-NAME1 and KNB1-ZSABE using the key as KUNNR) here or give two seperate select statements for extracting data from KNA1 and KNB1 using the key as KUNNR.
THANKS FOR THE HELP.I would suggest using the join on KUNNR. Maybe something like this.
data: begin of itab occurs 0,
kunnr type kna1-kunnr,
name1 type kna1-name1,
ZSABE type knb1-ZSABE,
end of itab.
select kna1~kunnr kna1~name1 knb1~zsabe
into table itab
from kna1
inner join knb1
on kna1~kunnr = knb1~kunnr
where ........
Regards,
Rich Heilman
Maybe you are looking for
-
ICal shows wrong month in day pane and in edit pane.
I am running iCal 3.0.8 under OS X 10.5.8 on a MacPro Intel machine. In the Month view I suddenly saw the month-day-year of each event appearing in the day panel. I also saw this date in the edit panel for that event. The problem is that the MONTH in
-
Oracle Report as data source in XMLP data template?
I use XML Publisher 5.6.3 in EBS 11.5.10 Is it possible to make an xml data template with an oracle report (rdf) as one of the sources of data? (I'm not saying create a Data Def with no Data Template attached... rather point the Data Template to an r
-
I am unable to create my two dimensional objects
suppose if class MyObject int i; MyObject [][]o; how to create this kind of objects pls help me for this
-
OM11g: Dynamic notifications on different user objects.
Hello On the User object, I have 3 custom attributes. These attributes are of type "Checkbox". I'd like to notify an administrator when any one of these attributes change value. For example: Attribute1: Head Office Access Attribute2: Remote Office Ac
-
Hi Experts, My scenario is to access the HEADER element in the incoming SOAP Header and use it as a condition for Receiver determination. Can somebody give example of 1) XSLT / java code which can be used to access SOAP Header elements. 2) How use t