Loop statement in oracle
SOurce Table
ID ADDRESS1 ADDRESS2
11 12 QA ST. 16 SELI ST.
12 455 LANE 3222 ROGER LANE
Target Table:
ID TYPE ADDRESS1 ADDRESS2
11 NORMAL XYZ st.
11 HIGH ABC st.
12 NORMAL TYU st.
12 HIGH XCV st.
Description of Problem:
I have a source table in which ADDRESS1 pertains to Address1 column in target table where type= 'NORMAL' and ADDRESS2 pertains to Address 2 column in target table where type = 'HIGH'
I want to update the target table using source table on ID so that Address column in target table is updated corresponding to the ADDRESS 1 AND ADDRESS 2 columns from source table.
I am using the following code:
MERGE
INTO TARGET tgt
USING SOURCE src
ON (src.ID = tgt.ID)
WHEN MATCHED
THEN
UPDATE
SET tgt.address1 = src.address1
where TGT.type = '=NORMAL'
How can i update the address2 column in the target table where type = 'HIGH'
in one shot.
I dont want to write two seprate queries.
I think i can use loop statement.
Please Advice as how to use loop, else any other suggestion.
Thanks
user11018028 wrote:
SOurce Table
ID ADDRESS1 ADDRESS2
11 12 QA ST. 16 SELI ST.
12 455 LANE 3222 ROGER LANE
Target Table:
ID TYPE ADDRESS1 ADDRESS2
11 NORMAL XYZ st.
11 HIGH ABC st.
12 NORMAL TYU st.
12 HIGH XCV st.
Description of Problem:
I have a source table in which ADDRESS1 pertains to Address1 column in target table where type= 'NORMAL' and ADDRESS2 pertains to Address 2 column in target table where type = 'HIGH'
I want to update the target table using source table on ID so that Address column in target table is updated corresponding to the ADDRESS 1 AND ADDRESS 2 columns from source table.
I am using the following code:
MERGE
INTO TARGET tgt
USING SOURCE src
ON (src.ID = tgt.ID)
WHEN MATCHED
THEN
UPDATE
SET tgt.address1 = src.address1
where TGT.type = '=NORMAL'
How can i update the address2 column in the target table where type = 'HIGH'
in one shot.
I dont want to write two seprate queries.
I think i can use loop statement.
Please Advice as how to use loop, else any other suggestion.
ThanksMaybe this? If you provide scripts for create tables and sample data this wouldn't be a guess :)
MERGE
INTO TARGET tgt
USING SOURCE src
ON (src.ID = tgt.ID)
WHEN MATCHED
THEN
UPDATE
SET tgt.address1 = case when TGT.type = 'NORMAL' then src.address1 else tgt.address1 end
, tgt.address2 = case when TGT.type != 'NORMAL' then src.address2 else tgt.address2 end
Similar Messages
-
Using a recordset in a loop statement
Hello all,
I am (still) trying to get an Excel spreadsheet for a dynamically created table. A crucial parameter of the problem is that I do not know the column names for my table at runtime, as it is created by a pivot query.
I was very excited to find Tom Kyte's post on "Using a recordset in a loop statement:
http://asktom.oracle.com/pls/ask/f?p=4950:8:4768329722850645393::NO::F4950_P8_DISPLAYID,F4950_P8_CRITERIA:464820324673,
This is precisely the solution I need. Unfortunately for me, when I create my stored procedure, it doesn't compile. As suggested I systematically renamed EXEC_SQL to DBMS_SQL, then I made some minor tweaks to integrate with HTMLDB:
create or replace procedure export_tsv as
connection_id DBMS_SQL.CONNTYPE
default DBMS_SQL.default_connection;
cursorID DBMS_SQL.CURSTYPE;
nIgn number;
columnValue varchar2(4000);
ncols number;
sep varchar2(1);
colName varchar2(40);
colLen number;
coltype number;
BEGIN
IF DBMS_SQL.is_connected = FALSE THEN
Message('No primary connection. Please connect.');
RETURN;
END IF;
-- set up for excel spreadsheet
htp.init;
owa_util.mime_header ('application/vnd.ms-excel',false);
htmldb_application.g_page_text_generated := true;
htp.p('Content-Disposition: attachment;
filename=myexport.txt');
owa_util.http_header_close;
-- end excel spreadsheet setup
cursorID := DBMS_SQL.OPEN_CURSOR;
DBMS_SQL.PARSE(cursorID, 'select * from exp_data', DBMS_SQL.V7);
nIgn := DBMS_SQL.EXECUTE(cursorID);
for i in 1 .. 1000 loop
begin
DBMS_SQL.describe_column( connection_id, cursorId, i,
colName, colLen, colType );
DBMS_SQL.define_column(cursorID, i, columnValue,
4000 );
exception
when DBMS_SQL.invalid_column_number then
ncols := i-1;
exit;
end;
end loop;
while (DBMS_SQL.fetch_rows(cursorID) > 0)
loop
sep := '';
for i in 1 .. ncols loop
DBMS_SQL.COLUMN_VALUE(cursorID, i, columnValue);
-- print the column value
htp.p( sep || columnValue);
sep := chr(9);
end loop;
-- print the end of line CRLF
htp.p(chr(13)|| chr(10));
END LOOP;
DBMS_SQL.CLOSE_CURSOR(cursorID);
DBMS_SQL.CLOSE_CONNECTION;
END;
When I try to run this in the HTMLDB SQL Command Processor, I see the following error:
ERROR at line 2: PLS-00302: component 'CONNTYPE' must be declared
Can someone provide me with the correct translation of Tom Kyte's approach into the HTMLDB idiom?
Thanks in advance,
susanQuestions about opening multiple worksheets on the web:
I have this link that submits the page and my process calls a PL/SQL procedure that prints out an excel spreadsheet. When I hit the link again, the spreadsheet does not update. I can make the spreadsheet update from ASP or a java servlet, but never from the PL/SQL procedure. Even if I use the procedure to print out XML in XMLSS format, so that I can change worksheet name, it still does not update on successive calls.
My code:
PROCEDURE SQL_TO_EXCEL(p_sql in varchar2)
as
l_cursor integer default dbms_sql.open_cursor;
l_status PLS_INTEGER;
l_desc dbms_sql.desc_tab;
l_col_cnt number;
l_columnValue varchar2(4000);
l_row varchar2(4000);
l_frow PLS_INTEGER;
l_lrow PLS_INTEGER;
l_cols varchar2(4000);
l_date date;
begin
--set mime type to Excel
htp.init;
owa_util.mime_header('application/vnd.ms-excel',true);
--htp.p('Pragma: no-cache');
--htp.p('Cache-Control: no-cache');
--owa_util.http_header_close;
htmldb_application.g_page_text_generated := true;
--htp.htmlOpen;
--htp.headOpen;
--htp.title('SQL to Excel Export');
--htp.headCLose;
--htp.bodyOpen;
execute immediate 'alter session set nls_date_format=''dd-mon-yyyy'''; -- hh24:mi:ss''';
DBMS_SQL Calls
dbms_sql.parse(l_cursor,rtrim(p_sql,';'),dbms_sql.native);
l_status := dbms_sql.execute(l_cursor);
dbms_sql.describe_columns(l_cursor,l_col_cnt,l_desc);
l_frow := l_desc.FIRST;
l_lrow := l_desc.LAST;
if l_col_cnt > 0 then
FOR colind IN l_frow..l_lrow LOOP
l_cols := l_cols||chr(9)||l_desc(colind).col_name;
END LOOP;
htp.p(ltrim(l_cols,chr(9)));
end if;
for i in 1 .. l_col_cnt loop
if l_desc(i).col_type = 12 then
dbms_sql.define_column(l_cursor,i,l_date);
else
dbms_sql.define_column(l_cursor,i,l_columnValue,4000);
end if;
end loop;
--l_status := dbms_sql.execute(l_cursor);
while (dbms_sql.fetch_rows(l_cursor) > 0) loop
for i in 1 .. l_col_cnt loop
if l_desc(i).col_type = 12 then
dbms_sql.column_value(l_cursor,i,l_date);
l_row := l_row||chr(9)||to_char(l_date,'DD-MON-YYYY HH24:MI:SS');
else
dbms_sql.column_value(l_cursor,i,l_columnValue);
l_row := l_row||chr(9)||l_columnValue;
end if;
end loop;
htp.p(ltrim(l_row,chr(9)));
l_row := '';
end loop;
--htp.bodyclose;
--htp.htmlclose;
dbms_sql.close_cursor(l_cursor);
exception
when others then
dbms_sql.close_cursor(l_cursor);
htp.p(SQLERRM||chr(10)||p_sql);
end SQL_TO_EXCEL;
Any ideas on how I can get the spreadsheet to update from repeated calls to the PL/SQL? -
Adding a field to an sql statement in Oracle Reports error ORA-00933
We have been requested to add a field that already exists in the table referred to by the sql statement in Oracle Reports Builder. The report was set up by a consultant about 3 yrs ago and we don't really have much skill in this area. What is happening when I try to modify the SQL statement, either adding a field or deleting a field to the SELECT statement, causes an error message preventing the statement from being saved. The only way out of the error message is to click Cancel. The error message is
ORA-00933:SQL command not properly ended
ORDER BY Program ==> NAME
Even adding or deleting a space anywhere in the SQL statement causes the error (not adding any new fields). A coworker found that if we comment out the ORDER BY, the statement will accept the new field in the SELECT section, however then we lose the order by functionality. I would like to add one additional field before the FROM. Not sure if any additional data are needed. Thank you.
SELECT p.person_uid PIDM_KEY, p.id_number ID,
p.full_name_lfmi name,
p.BIRTH_DATE, p.GENDER Sex,
Decode(a.residency,'D',p.Primary_ethnicity,'F') Ethn,
a.academic_period TERM,
CASE WHEN :p_group_by = 'PROGRAM' THEN a.program
ELSE ' '
END AS Program,
a.COLLEGE, a.degree, a.major, ' ' rule,
a.STUDENT_POPULATION,a.STUDENT_LEVEL, a.application_status Status, a.application_status_date app_sts_dte,
ad.decision_date1 Last_Dec_Date,
ad.decision1||' '||ad.decision2||' '|| ad.decision3||' '|| ad.decision4||' '|| ad.decision5 Decisions,
/* Deposit Date uses the last term entered in :p_term parameter string */
(SELECT MAX(deposit_effective_date) FROM usf_as_deposit WHERE account_uid = a.person_uid &term_clause group by account_uid) AS "DEPOSIT DATE",
ph.phone as PHONE,
CASE WHEN PS.FIRST_CONTACT IN ('NET','PAP','COM','COP') THEN PS.First_Contact
ELSE CASE WHEN ps.latest_contact IN ('NET','PAP','COM','COP') THEN PS.Latest_Contact
ELSE ' '
END
END AS FIRST_CONTACT,
DECODE(:p_address,'Y',REPLACE(adr.street1||' '||adr.street2||' '||adr.street3||' '||adr.city||','||adr.state||' '||adr.nation||' '||adr.zip,' ',' '),' ') as address, adr.nation, adr.state,
goremal_email_address email, a.residency, a.application_date, p.primary_ethnicity, c.cohort
FROM MST_ADMISSIONS_APPLICATION A,
MST_PERSON p,mst_pre_student PS, Admissions_Cohort c, usf_v_phone_pr_ma ph,
MST_admissions_decision_slot AD, usf_v_email, usf_v_address_dr_lr_ma_pr adr
WHERE a.PERSON_UID = p.person_uid
AND a.curriculum_priority = 1
AND a.person_uid = ps.person_uid
AND a.person_uid = ad.person_Uid(+)
AND a.person_uid = goremal_pidm(+)
AND a.person_uid = adr.pidm(+)
AND a.person_uid = ph.pidm(+)
AND ph.rnum(+) = 1
AND a.person_uid = c.person_uid(+)
AND a.academic_period = c.academic_period(+)
&Where_Clause
/* TAKE OUT FOLLOWING LINE AFTER DATA IS CLEANED UP */
AND NOT(p.id_number = '00000000' OR SUBSTR(p.id_number,1,1) = 'B' OR UPPER(p.full_name_lfmi) LIKE '%TESTING%')
AND a.application_status_date >= NVL(:p_as_of_date,sysdate-8000)
AND a.academic_period = ad.academic_period(+)
AND a.application_number = ad.application_number(+)
AND a.degree <> 'ND' /* AND a.college <> 'LW' -- Does not need non-degree and law students */
&Cohort_Clause
ORDER BY Program &ORDER_CLAUSEHi Denis,
I tried your suggestion. The good thing is that adding the comma allowed me to be able to add a.campus to the select statement, unfortunately, another error message happened.
ORA-00936: missing expression SELECT p . person_uid PIDM_KEY ,
p . id_number , p . full_name_lfmi name , p . BIRTH_DATE , p . GENDER Sex ,
Decode ( a . residency , 'D' , p . Primary_Ethnicity , 'F' ) Ethn , a . academic_period TERM ,
CASE WHEN : P_group_by = 'PROGRAM THEN a I started over and tried only putting in the comma and get the same message even though I didn't add campus. After that, removed the comma which led to the ORA-00933 error message. So once again, I had to close the file without saving, in order for the report to run at all. -
Hi all,
I have an Windows XP OS with SP3.
I have installed the Oracle 11g server.
On trying to connect to the ODBC connection, i get the following error message:
Unable to connect SQL State=S1000 [Oracle][ODBC][Ora]ORA-12170: TNS: Connect timeout occured
On trying the tnsping,
TNS Ping Utility for 32-bit Windows: Version 11.1.0.6.0 - Production on 09-OCT-2
011 13:11:05
Copyright (c) 1997, 2007, Oracle. All rights reserved.
Used parameter files:
E:\app\Gautam\product\11.1.0\db_1\network\admin\sqlnet.ora
Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.
5.207)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = orcl))
TNS-12535: TNS:operation timed out
On trying to connect with SQL Developer, i get the following error:
Status: Failure - Test failed: Io Exception: The Network Adapter could not establish the connection
However i am able to connect to the same using SQL Plus
Another issue that occurs is that the Oracle Enterprise Manager shows the following error after a while:
Agent Connection to Instance
Status Failed
Details ORA-12505: TNS:listener does not currently know of SID given in connect descriptor (DBD ERROR: OCIServerAttach)
The following services are all up during this point of time:
OracleDBConsoleorcl
OracleOraDb11g_home1TNSListener
OracleServiceORCL
Any help in this regard will be very useful as this is hindering the progress of my work.
Thanks in advance for the help.
- Gautam841683 wrote:
Hi,
I did try and delete my listener.ora and then create a new one..
That did not solve my issue..
What are the steps for configuring the listener again.
Thanks for the response..
- Gautamno listener.ora file is required.
just do as below
lsnrctl start -
Hi,
I am trying to change a BADI interface and since BADIs use ABAP OO, a simple loop statement fails to work.
I need to loop through an internal table and for each record in the internal table I need to read another db table which has a field in common with the internal table.
Ideally,
Loop at lt_selections
select logsys from /bic/mzcs_unit where /bic/zcs_unit = lt_selections-cs_unit
endloop.
But this piece of code fails to work in BADI because of OO concepts.
Can anyone help me out here?
THank youAs Alejandro said, if you are getting a syntax error, it is probably because <b>header lines are not allow in OO</b>.
data: wa_selections like line of lt_selections.
Loop at lt_selections into wa_wa_selections.
select logsys from /bic/mzcs_unit
where /bic/zcs_unit = wa_selections-cs_unit.
endloop.
Regards,
Rich Heilman
Message was edited by: Rich Heilman -
Difference B/w all DDL statements in Oracle 8i and 9i
Where can i get the difference between all the DDL statements between oracle 8i and 9i.If anyone has this pls ..post it..
What is your national character set? What is NLS_LENGTH_SEMANTICS set to?
Justin
Distributed Database Consulting, Inc.
http://www.ddbcinc.com/askDDBC -
Case Statement in Oracle Query.
Hello Oracle Gurus,
I need suggestion on whether I should use Case statement in Oracle queries.
I have a sql statement which inserts the data by selecting data from other table. While selecting the data I have put a logic in the select statement for one column which is something like this and there are some more similar statements in the same query.
CASE
WHEN (b.ACCOUNT = 'FIN' or b.ACCOUNT ='FIN ACC' or b.ACCOUNT like '%Global Eq%' or b.ACCOUNT like '%Flexible Bond%')
THEN
'MTM'
WHEN (substr(a.CTC,-3)='MTM')
THEN
'MTM'
WHEN (substr(a.CTC,-3)='AFS' or substr(a.CTC,-3)='HTM' OR substr(a.CTC,-3)='ACC' OR substr(a.CTC,-3)='HFI' )
THEN
'ACC'
ELSE
'OTH'
END,
I wanted to get an suggestion about how much performance issue can I have due to this in my insert statement.
Let me know if you need any other information.All comments are really appreciated.Hi,
It's depends on the joins how you have performed with source table, stats and existing of indexes. If the volume of data is high - in case of any performance issue - why can't you perform the required things of logical conditions of data and popualte in one cluster so - that you can fetch out the chunks of required information with better way and in support with indexes.
Let us know the ful query your working on
Oracle version
Explain plans - get it from dbms_xplan.
- Pavan Kumar N
- ORACLE - 9i/10g - OCP
RHCE - Enterprize Linux 5.4 -
Regarding LOOP Statement in ABAP
Hi,
I have small question regarding <b>LOOP ..... ENDLOOP</b> statement against <b>SY-SUBRC</b> Check.
I have a loop as below:
<b> LOOP AT i_vbap WHERE vbeln = i_vbak-vbeln.
Some Code
ENDLOOP.
IF sy-subrc <> 0.
APPEND i_sdata.
CLEAR i_sdata.
ENDIF.</b>
Is the above <b>Code/Syntax</b> is correct one.
Can we use <b>SY-SUBRC</b> Check against <b>LOOP ... ENDLOOP</b> statement.
Is this the right way of writing the code as per standards.
Can anybody give sujjestions regarding the same.
Thanks in advance.
Thanks & Regards,
Prasad.Hi Prasad,
Yes, you could use sy-subrc after the endloop. For example:
loop at itab1 where kunnr = itab2-kunnr.
some conditions...
endloop.
if sy-subrc = 0.
write: 'Success!'.
else.
leave program.
endif.
if you press F1 while highlighting the LOOP statement here are the meaning of sy-subrc in loop...endloop.
SY-SUBRC = 0:
At least one loop pass was processed.
SY-SUBRC = 4:
The loop was not processed because the table contains no entries or no entries satisfied the conditions.
Regards! -
My loop statement in smartforms seems not to be working...
Hello Experts,
I am currently practicing smartforms and I am trying to display the records of my internal table.
What I did was in my table under MAIN window I have put the statement:
it_spfli into wa_spfli and also in my main area of my table I have a loop statement. Now, in one of my text
i put wa_spfli-carrid, wa_spfli-countryfr, etc. But it still does not show any data.Help would be greatly appreciated.u will be getting a function module name for the smartform then
goto se37-->enter the FM name -->search for the ITAB you r using then put a break point.
come back to u r program the run.. controle will stops over there then check whether the data is populating or not.
INPUT and OUTPUT patameters are for program line and INITIALIZATION tabs.. when you want to modify some data in these you need to give the veriable or ITABs u r using inside. so that system will determine the global declarations(veriable or ITAbs).
for more info refer these links
http://www.sap-img.com/smartforms/sap-smart-forms.htm
http://www.sap-img.com/smartforms/smartform-tutorial.htm
http://www.sapgenie.com/abap/smartforms.htm -
Delete internal table rows without using loop statement
i have an internal table which consists of 100 records.
i need to keep only first 5 records.
without using the loop statement i need to delete the rest of the records. how can we achieve this result.
i.e. delete itab1 where "recordno" > 5.
regards.
ZGHi,
Delete itab [FROM idx1] [TO idx2] {Where (log_exp)]
To delete several lines at once, you have to specify at least one of the additions FROM, TO, or WHERE. You can only use the additions FROM and TO with standard tables and sorted tables.
Delete itab [FROM idx1]
If you specify FROM, all the table rows from the table index idx1 onwards are included.
Delete itab [TO idx2]
If you specify TO, all the table rows from the table index idx2 onwards are included.
PARAMETERS: p_carrid TYPE sflight-carrid,
p_connid TYPE sflight-connid.
DATA: BEGIN OF seats,
fldate TYPE sflight-fldate,
seatsocc TYPE sflight-seatsocc,
seatsmax TYPE sflight-seatsmax,
seatsfree TYPE sflight-seatsocc,
END OF seats.
DATA seats_tab LIKE STANDARD TABLE OF seats.
SELECT fldate seatsocc seatsmax
FROM sflight
INTO TABLE seats_tab
WHERE carrid = p_carrid AND
connid = p_connid.
LOOP AT seats_tab INTO seats.
seats-seatsfree = seats-seatsmax - seats-seatsocc.
MODIFY seats_tab INDEX sy-tabix FROM seats.
ENDLOOP.
ENDLOOP.
SORT seats_tab BY seatsfree DESCENDING.
DELETE seats_tab FROM 5.
Thanks & Regards,
ShreeMohan
Edited by: ShreeMohan Pugalia on Jul 21, 2009 4:28 PM -
Loop statement logic required!!!
Dear Gurus,
The following is used now. Need to change into Loop statement.
Read the internal table t_ABC INTO w_ABC WITH KEY .... "ABC is to collect all Successful Insertion
IF sy-subrc NE 0.
CLEAR w_ABC.
Read the internal table t_XYZ INTO w_ABC WITH KEY ....
IF sy-subrc EQ 0.
PERFORM locktable.
INSERT ABC FROM w_ABC.
IF sy-subrc NE 0.
w_failure = c_x.
ENDIF.
PERFORM unlocktable.
APPEND w_ABC TO t_ABC. "Here t_ABC will hv only all Successful Insertion records
CLEAR w_ABC.
ENDIF.
ENDIF.
Since there will be more than one record, I can't use READ Statement.
How to use Loop? But it should not affect performance.
My worry is that, if i use "Locking the table" and "Insert" inside Loop, then it will affect performance.
Can any one please help me out?
It's pretty urgent.
Points will be rewarded immediately.
Thanks & Regards,
NeerajHi,
Loop at t_abc INTO w_ABC .
Read table t_XYZ INTO w_ABC WITH KEY ....
IF sy-subrc EQ 0.
PERFORM locktable.
INSERT ABC FROM w_ABC.
IF sy-subrc NE 0.
w_failure = c_x.
ENDIF.
PERFORM unlocktable.
APPEND w_ABC TO t_ABC. "Here t_ABC will hv only all Successful Insertion records
CLEAR w_ABC.
ENDIF.
ENDIF. -
Writing an update statement in oracle forms 9i
Hi ,
I have a problem situation in which
I am fetching values from a cursor and a recod group into two data block items text box and combo box respectively .
Both the data is fetched from different tables .
Now based on the selection from combo box I have to update the selected value in another table by writing an update statemet .
I have created a button and on the trigger event of when button pressed I wrote a simple update statement but it's not working that way .
Kindly help me how to write manual update statements in oracle forms 9i
I can't used the update buil in of forms as I want to update in a table which is not mentioned in the property pallete of data block
please helpI just wrote a procedure
PROCEDURE update_current IS
BEGIN
update table abc set xculumn= :block_name.item_name2 where ycolumn = :block_name.item_name1 ;
commit;
and I called the procedure from a when button pressed trigger
it gave an error invalid identifier abc ( which is table name)
pls help
I am trying to do it with form_ddl(update_query)
but here I am facing another problem
I have update_query = 'update table abc set xculumn= ' || :block_name.item_name2 || 'where ycolumn = '||:block_name.item_name1
now since xculumn and y column are varchar type so I suppose while preparing the query I have to concatenate single quotes ( ' ) at the start and end
but i am facing problems in doing so
please tell me an alternative way or how to concatenate single quotes in the above update_query variable -
Where to run SQL statements in Oracle Database 11gR1 ?
Folks,
Hello. I have just installed Oracle Database 11gR1 and login to Database Control page. There are 4 tabs on the top: Database, Setup, Preference, Help and Logout.
I just create a table "table1" in "Database" tap. But I don't see anywhere to run SQL statement such as Select, Insert, Update.
Can any folk tell me where to run SQL statements in Oracle Database 11gR1 ?
Or
Can any folk provide a User Manual for Oracle DB 11gR1 ?You can run from a terminal or install an SQL client and connect from there.
http://www.articlesbase.com/databases-articles/how-to-install-oracle-11g-client-1793770.html
Best Regards
mseberg
Assuming you have an oracle OS user on Linux you can try typing sqlplus at you OS command prompt. Generally you will have a .bash_profile with setting like this:
# User specific environment and startup programs
PATH=$PATH:$HOME/bin
export PATH
# Oracle Settings
TMP=/tmp; export TMP
TMPDIR=$TMP; export TMPDIR
export ORACLE_BASE=/u01/app/oracle
export ORACLE_HOME=/u01/app/oracle/product/11.2.0
#export DISPLAY=localhost:0.0
export TZ=CST6CDT
export ORACLE_SID=ORCL
export ORACLE_TERM=xterm
#export TNS_ADMIN= Set if sqlnet.ora, tnsnames.ora, etc. are not in $ORACLE_HOME/network/admin
export NLS_LANG=AMERICAN;
LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib
export LD_LIBRARY_PATH
# Set shell search paths
PATH=/usr/sbin:$PATH; export PATH
export PATH=$PATH:$ORACLE_HOME/bin
# CLASSPATH:
CLASSPATH=$ORACLE_HOME/JRE:$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib
CLASSPATH=$CLASSPATH:$ORACLE_HOME/network/jlib
export EDITOR=vi
set -o vi
PS1='$PWD:$ORACLE_SID >'Edited by: mseberg on Jul 11, 2011 3:18 PM -
Need help converting Excel IF statement into CASE WHEN statement for Oracle
Hi,
Hope someone can help I have tried various ways of getting this to work, to no avail!
Bascially I have some figures that are minus figures, and I need to add them together to get a movement figure, but I need to treat the minus figures as minus, if that makes sense, rather than the usual... a minus and a minus makes a plus.
For example:- Budget Figure = -1% and Actual Figure = -68% so the movement needs to be -69%.
The IF statement I have been using in Excel is the following:-
=IF(FO110<0,(FP110-(IF(FO110=0,1,FO110)*-1)),FP110-IF(FO110=0,1,FO110))
Which when using the figures as above = -69%
Cell FO = The Budget Figure
Cell FP = The Actual Figure
However, when I created the CASE statement in Oracle, the figure in the query comes back as -0.67, which is oviously not what I want to happen when both actual and budget are minus figures; however when they are a minus and a plus, it works perfectly fine.
Any help on this would be most appreciated!
Kind regards,
AnnmarieHappy I did'n mess something up :)
Nevertheless, don't show it too much around because
case when budget < 0
then actual - case when budget = 0 /* will never happen */
then 1 /* will never happen */
else budget
end * (-1) /* -budget * (-1) remains only */
else actual - case when budget = 0
then 1
else budget
end
endso at least try the following (if case is more readable as decode for you). Let's hope it works as I don't have a Database at hand
case when budget < 0
then actual + budget
else actual - case when budget = 0
then 1
else budget
end
end Regards
Etbin -
Convert sql select statement to oracle
Hi All,
Can anyone help me converting this Sql select statement to oracle ....
-----------------------------------------Query--------------------------------------------------------------
select emp_master.emp_code ,
emp_master.dept_cd ,
attendance_master.daily_attn_code ,
attendance_master.linked_column ,
case when location.payroll_status <> 'N' and eDocsNetEmployeesLeave.StartDate < dateadd(mm, 1 , convert(smalldatetime, datename(yy ,location.next_pay_date) + '/'+ datename(mm ,location.next_pay_date)+ '/01'))
then
dateadd(mm, 1 , convert(smalldatetime, datename(yy ,location.next_pay_date) + '/'+ datename(mm ,location.next_pay_date)+ '/01'))
when eDocsNetEmployeesLeave.StartDate < convert(smalldatetime, datename(yy ,location.next_pay_date) + '/'+ datename(mm ,location.next_pay_date)+ '/01')
then convert(smalldatetime, datename(yy ,location.next_pay_date) + '/'+ datename(mm ,location.next_pay_date)+ '/01') else eDocsNetEmployeesLeaveDetails.StartDate
end ,
eDocsNetEmployeesLeaveDetails.NoOfDays,
case when eDocsNetEmployeesLeave.StartDate > location.next_pay_date
then convert(datetime , convert(varchar, dateadd(ss,-1, dateadd(mm, 1, convert(datetime , datename(yy,eDocsNetEmployeesLeave.StartDate)+ '/' + datename(mm,eDocsNetEmployeesLeave.StartDate)+ '/01') )),106) )
else
case when location.payroll_status <> 'N'
then dateadd(mm,1,location.next_pay_date)
else location.next_pay_date
end
end as PaymentDate ,
isnull(grade_master.leave_type,'C') ,
eDocsNetEmployeesLeave.StartDate ,
eDocsNetEmployeesLeaveDetails.LeaveType
from eDocsNetEmployeesLeave ,
eDocsNetEmployeesLeaveDetails ,
eDocsNetLeaveTypes ,
emp_master ,
grade_master ,
attendance_master ,
location
where eDocsNetEmployeesLeaveDetails.RequestID = eDocsNetEmployeesLeave.RequestID and
eDocsNetEmployeesLeave.EmployeeID = emp_master.emp_code and
eDocsNetEmployeesLeaveDetails.LeaveType = eDocsNetLeaveTypes.LeaveTypeID and
eDocsNetLeaveTypes.loc_cd = emp_master.loc_cd and
location.loc_cd = emp_master.loc_cd and
attendance_master.loc_cd = emp_master.loc_cd and
attendance_master.linked_column = eDocsNetLeaveTypes.LinkedAttendance and
grade_master.loc_cd = emp_master.loc_cd and
grade_master.grade_cd = emp_master.grade_cd and
eDocsNetEmployeesLeaveDetails.RequestID = @RequestID
order by eDocsNetEmployeesLeaveDetails.StartDate
Thanks in Advance
SmileySeems like you want to convert a SQL statement from the ??? dialect to the Oracle dialect. *(It would be useful to indicate the non-ANSI standard SQL you are starting with.)
Part of the problem is that you use several date related functions. Some are unnecessary in Oracle and some need to translated into Oracle functions as found in the Functions section (chapter 5) of the SQL Reference manual at http://www.oracle.com/pls/db102/homepage
Note that columns and expressions of type 'date' in ORacle always contain all of "yyyy mm dd hh mi ss" and you need to format and trauncate as necessary.
Also note that '09-JAN-31' is NOT an Oracle date, but rather a character representation of a date which must be converted to/from a date expression. You will often need to use the to_date() and to_char() functions with a format mask as the second parameter. This is also descreibed in the first 2 chapters of the SQL Reference manual.
Maybe you are looking for
-
My Apple blue tooth keyboard will not pair with my mac mini
My Apple wireless keyboard was paired with my Mac Mini. It is no longer paired. I have put in new Batteries. I have pressed the button on the top right hand section of the keyboard, the green led lights up briefly. The Blue Tooth set up assistant app
-
HomeHub 5 and and WiFi connection
I have resently go a HomeHub 5 and I am having trouble with the wireless dropping out 2 or 3 times a day. What basically will happen is that the PD will just stop sending/receiving data from the network (both the internal and external network). Other
-
The date and the time of printed of purchase order
Hi, Wich field can me watch the date and the time of printing document like purchase order Thanks in advance
-
How to make attachments work in Guided procedures
Hi, I have created a simple application in GP where there is an input and the same user can see the output.During the process we can see an attachment symbol. when i attach a file and send it the other screen or the other user doesnt recieve that att
-
Slow down effect won't work...
I recently upgraded to iMovie HD and when I try to use the slow down effect it renders it but it stays the same clip. Any suggestions on what is causing this?