Write an sql select statement for this problem?????????????????
Hi frenz, i m bharath a new bee to oracle,my problem is
the given table is
userid billno amount
1 101 1000
2 102 2000
3 103 3000
4 104 4000
output table should be:
userid billno amount total*
1 101 1000
2 102 2000 *3000*
3 103 3000 *6000*
4 104 4000 *10000*
I need a select query for the above output.
i.e,here i calculated total as sum(amount) for each row,i.e,3000 = 1000+2000,6000 = 1000+2000+3000,10000 = 1000+2000+3000+4000 by this way my calculation for total field
kindly send me a query.
This is trivial with analytics:
SQL> select empno, sal, sum(sal) over (order by empno)
2 from emp
3 /
EMPNO SAL SUM(SAL)OVER(ORDERBYEMPNO)
7369 800 800
7499 1600 2400
7521 1250 3650
7566 2975 6625
7654 1250 7875
7698 2850 10725
7782 2450 13175
7788 3000 16175
7839 5000 21175
7844 1500 22675
7876 1100 23775
7900 950 24725
7902 3000 27725
7934 1300 29025
14 rows selected.
SQL> You might want to get your keyboard checked - the question mark key seems to be stuck.
Cheers, APC
blog: http://radiofreetooting.blogspot.com
Similar Messages
-
How to write Select statement for this codition
I need to check whether SGTXT contains BELNR value.
SGTXT is a text field and It should be matched with BELNR
How to write select statement for this.
Select AUGBL AUGDT into t_BSAD
from BSAD
where SGTXT should have the given BELNR Value.
Plz note : Here I cannot give as SGTXT = BELNR as coz BELNR have only 10 digits.Hi,
data temp(12).
concatenate '%' belnr '%' into temp.
Select AUGBL AUGDT into t_BSAD
from BSAD
where SGTXT like temp.
If belnr is having multiple values,just create a internal table as follows.
types : begin of ty,
belnr....
temp(12),
end of ty.
data itab_ type standard table of ty.
data wa type ty.
loop at itab into wa.
concatenate '%' wa-belnr '%' into wa-temp.
modify itab from wa index sy-tabix transporting temp.
endloop.
Change your select statement accordingly.
Kindly reward poits if it helps. -
Regarding select statement for this requirement
Hi................
good evening
here is a requirement.
i want to retrieve data from the following table.but how to join these table is my dought.
tables fields
t001w--werks " plant id
t001w--name1 " pl;ant name
t001w--regio " plant address
ekko--ebeln " purchase order
ekko-erdat : creation date
ekko-ernam "name of the person
ekpo-ebelp " item
ekpo-bstyp "purchase order type
eket-erdat " delivery date
mara-matnr " material number
these are the tables and fields.now we want to retrive data from these tables
how we have to code select statement.
selection-screen is
plant id
order type
delivery date
please provide select statement for this requirement.
thanks and regards.
k.swaminath reddy.Is this what you are looking for?
SQL> CREATE OR REPLACE FUNCTION f_team
2 RETURN VARCHAR2
3 IS
4 s_return VARCHAR2(500);
5 BEGIN
6 FOR i IN ( select team from t_team order by 1) LOOP
7 s_return := s_return || i.team || ', ';
8 END LOOP;
9
10 RETURN substr(s_return, 1, length(s_return) - 2);
11 END;
12 /
Function created.
SQL> SELECT f_team FROM dual;
F_TEAM
Australia, Bangladesh, England, India, Kenya, Pakistan, South Africa, UAE, USA, West Indies, Zimbabwe
SQL> -
Select statement for this???
Hi
I have table t where there are two columns
it has the data in the following format..some of it is given below
team_ID Team
1 Australia
2 England
3 West Indies
4 India
5 Pakistan
6 South Africa
7 Zimbabwe
8 UAE
9 Bangladesh
10 Kenya
11 USA
12
13...
14..
so on
[pre]
I want a select statement that will show me the above data in the follwoing format:
Australia, Bangladesh, England, India, Kenya, Pakistan, South Africa, UAE, USA, West Indies, Zimbabwe
(note that the team names should always come in the Alphabetical format in the desired output..
please tell me the query for this..
regards,
Asim.Is this what you are looking for?
SQL> CREATE OR REPLACE FUNCTION f_team
2 RETURN VARCHAR2
3 IS
4 s_return VARCHAR2(500);
5 BEGIN
6 FOR i IN ( select team from t_team order by 1) LOOP
7 s_return := s_return || i.team || ', ';
8 END LOOP;
9
10 RETURN substr(s_return, 1, length(s_return) - 2);
11 END;
12 /
Function created.
SQL> SELECT f_team FROM dual;
F_TEAM
Australia, Bangladesh, England, India, Kenya, Pakistan, South Africa, UAE, USA, West Indies, Zimbabwe
SQL> -
How to write optimized select statements for this requirement
I. G/L Account No. Info: Get all the list of G/L Account no. , company code and the corresponding long description from SKB1 & SKAT tables based on the G/L Account no. and company code values entered in the selection screen.
II. No. of transactions posted: For each of the Company code & Posting date or fiscal year/ period combination, select all document numbers from BKPF table into an internal table. For each of the company code, GL Account no combination find out no. of distinct records in the BSEG table (or combination of BSIK, BSAK, BSID, BSAD, BSIS & BSAS tables) to get the No. of transactions posted.
III. For Last posting FY/period: for each G/L account, Company code combination, determine the MAX (Doc. No) in BSEG, and look up the corresponding document in BKPF table to get the last posting FY/Period.
Thanks,
Prakash.I) with a query (sq01/2) and logical database SDF
or standard abap RFSKVZ00
II)a) select bkpf
b) select count( * ) from bsik...
III) a)select max( belnr ) from bseg...
b) selec single monat from bkpf
A. -
How to write select query for this
Hi,
I had a html form and in the for i had drop down box and it needs to select multiple values from the drop down box. When i select multiple values then i have to write the SQL select statement query .
When i try to write the select statement and trying to run i am getting error.
select * from Table
where emo_no = '1,2,3'
this is how i write query please suggest me how to write query for selecting multiple values from the drop down box.
Thanksselect * from Table
where emo_no in ( 1,2,3)
for integer values
select * from Table
where emo_no in ('1','2','3')
for characters
If we talk about large scale applications that may have millions of records, I would suggest this.
declare @t table (v int)
insert into t (v) values (1)
insert into t (v) valves (2)
insert into t (v) values (3)
select *
from table
inner join @t t on table.emo_no = t.v
Using "in" for a where clause is not so bad for filtering on a few values, but if you are filtering a lot of rows and a lot of values (emo_no) the performance degrades quickly for some reasons beyond the scope of this.
This is just one solution, I'll through this out as well, instead of an in memory (@t) table, doing a disk based temp table (#t) and creating an index on the column "v".
create table #t (v int)
insert into #t (v) values (1)
insert into #t (v) valves (2)
insert into #t (v) values (3)
create index ix_t on #t (v)
select *
from table
inner join #t t on table.emo_no = t.v
drop table #t
Pardon any syntax errors and careful using a drop statement.
Sometimes in memory tables work better than disk temp tables, it takes some testing and trial and error depending on your datasets to determine the best solution.
Probably too much info ;-)
Byron Mann
[email protected]
[email protected]
Software Architect
hosting.com | hostmysite.com
http://www.hostmysite.com/?utm_source=bb -
APP-ALR-04106: Please correct the user-defined SQL statement for this alert
Hi All,
I have created an alert for engineering module in R12. It got tested and was working fine. when the user testing it, while trigger the alert getting the error, "APP-ALR-04106: Please correct the user-defined SQL statement for this alert".
when verified the alert, it got verified and ran also. It parsed the query successfully and when run it fetched few records.
Need help in resolving the issue.
Thanks in advance.
Regards,
sri
Edited by: user10939296 on Jan 18, 2010 1:16 AMHi Sri;
I have already gone through the Note: 948037.1. But this note is related to 11i. The solution provided in the Note is for 11i.
I am facing this issue in R12. Is this patch applicable to R12?I belive its not. But u can check Solution part 4 for your instance, at least it can give you idea. The other note in metalink related bug and all for R11 too.
I belive its better way to rise Sr while waiting other forum user response to that thread
Regard
Helios -
Parsing an OPEN SQL select statement
Hi all,
I want to parse an open SQL select statement to get the list of tables and the corresponding fields in the select statement.
Is there some ABAP-internal syntax from the SAP Database Interface that does this? or is the only option to do this is to manually break the statement?
Thanks.
GirishHi,
I doubt if there is something like that available to use. It think you will have to write a parser for yourself.
Regards -
Exporting SQL Select statement to spreadsheet
Hi all, basic question that I couldn't find the answer to while googling and searching the Oracle documentation.
What is the code for exporting the result of a SQL Select statement to a spreadsheet such as Excel or Calc? In Oracle SQL Developer I tried saving the output as an XML file but it did not come out properly and I tried using EXPORT at the end of the statement but it gave an error message and I am not sure if this is the right command or what the syntax is. Thanks.Here's an example of one way to create CSV files that most spreadsheet type applications are able to read...
As sys user:
CREATE OR REPLACE DIRECTORY TEST_DIR AS '\tmp\myfiles'
GRANT READ, WRITE ON DIRECTORY TEST_DIR TO myuser
/As myuser:
CREATE OR REPLACE PROCEDURE run_query(p_sql IN VARCHAR2
,p_dir IN VARCHAR2
,p_header_file IN VARCHAR2
,p_data_file IN VARCHAR2 := NULL) IS
v_finaltxt VARCHAR2(4000);
v_v_val VARCHAR2(4000);
v_n_val NUMBER;
v_d_val DATE;
v_ret NUMBER;
c NUMBER;
d NUMBER;
col_cnt INTEGER;
f BOOLEAN;
rec_tab DBMS_SQL.DESC_TAB;
col_num NUMBER;
v_fh UTL_FILE.FILE_TYPE;
v_samefile BOOLEAN := (NVL(p_data_file,p_header_file) = p_header_file);
BEGIN
c := DBMS_SQL.OPEN_CURSOR;
DBMS_SQL.PARSE(c, p_sql, DBMS_SQL.NATIVE);
d := DBMS_SQL.EXECUTE(c);
DBMS_SQL.DESCRIBE_COLUMNS(c, col_cnt, rec_tab);
FOR j in 1..col_cnt
LOOP
CASE rec_tab(j).col_type
WHEN 1 THEN DBMS_SQL.DEFINE_COLUMN(c,j,v_v_val,2000);
WHEN 2 THEN DBMS_SQL.DEFINE_COLUMN(c,j,v_n_val);
WHEN 12 THEN DBMS_SQL.DEFINE_COLUMN(c,j,v_d_val);
ELSE
DBMS_SQL.DEFINE_COLUMN(c,j,v_v_val,2000);
END CASE;
END LOOP;
-- This part outputs the HEADER
v_fh := UTL_FILE.FOPEN(upper(p_dir),p_header_file,'w',32767);
FOR j in 1..col_cnt
LOOP
v_finaltxt := ltrim(v_finaltxt||','||lower(rec_tab(j).col_name),',');
END LOOP;
-- DBMS_OUTPUT.PUT_LINE(v_finaltxt);
UTL_FILE.PUT_LINE(v_fh, v_finaltxt);
IF NOT v_samefile THEN
UTL_FILE.FCLOSE(v_fh);
END IF;
-- This part outputs the DATA
IF NOT v_samefile THEN
v_fh := UTL_FILE.FOPEN(upper(p_dir),p_data_file,'w',32767);
END IF;
LOOP
v_ret := DBMS_SQL.FETCH_ROWS(c);
EXIT WHEN v_ret = 0;
v_finaltxt := NULL;
FOR j in 1..col_cnt
LOOP
CASE rec_tab(j).col_type
WHEN 1 THEN DBMS_SQL.COLUMN_VALUE(c,j,v_v_val);
v_finaltxt := ltrim(v_finaltxt||',"'||v_v_val||'"',',');
WHEN 2 THEN DBMS_SQL.COLUMN_VALUE(c,j,v_n_val);
v_finaltxt := ltrim(v_finaltxt||','||v_n_val,',');
WHEN 12 THEN DBMS_SQL.COLUMN_VALUE(c,j,v_d_val);
v_finaltxt := ltrim(v_finaltxt||','||to_char(v_d_val,'DD/MM/YYYY HH24:MI:SS'),',');
ELSE
v_finaltxt := ltrim(v_finaltxt||',"'||v_v_val||'"',',');
END CASE;
END LOOP;
-- DBMS_OUTPUT.PUT_LINE(v_finaltxt);
UTL_FILE.PUT_LINE(v_fh, v_finaltxt);
END LOOP;
UTL_FILE.FCLOSE(v_fh);
DBMS_SQL.CLOSE_CURSOR(c);
END;This allows for the header row and the data to be written to seperate files if required.
e.g.
SQL> exec run_query('select * from emp','TEST_DIR','output.txt');
PL/SQL procedure successfully completed.Output.txt file contains:
empno,ename,job,mgr,hiredate,sal,comm,deptno
7369,"SMITH","CLERK",7902,17/12/1980 00:00:00,800,,20
7499,"ALLEN","SALESMAN",7698,20/02/1981 00:00:00,1600,300,30
7521,"WARD","SALESMAN",7698,22/02/1981 00:00:00,1250,500,30
7566,"JONES","MANAGER",7839,02/04/1981 00:00:00,2975,,20
7654,"MARTIN","SALESMAN",7698,28/09/1981 00:00:00,1250,1400,30
7698,"BLAKE","MANAGER",7839,01/05/1981 00:00:00,2850,,30
7782,"CLARK","MANAGER",7839,09/06/1981 00:00:00,2450,,10
7788,"SCOTT","ANALYST",7566,19/04/1987 00:00:00,3000,,20
7839,"KING","PRESIDENT",,17/11/1981 00:00:00,5000,,10
7844,"TURNER","SALESMAN",7698,08/09/1981 00:00:00,1500,0,30
7876,"ADAMS","CLERK",7788,23/05/1987 00:00:00,1100,,20
7900,"JAMES","CLERK",7698,03/12/1981 00:00:00,950,,30
7902,"FORD","ANALYST",7566,03/12/1981 00:00:00,3000,,20
7934,"MILLER","CLERK",7782,23/01/1982 00:00:00,1300,,10The procedure allows for the header and data to go to seperate files if required. Just specifying the "header" filename will put the header and data in the one file.
Adapt to output different datatypes and styles are required.
There are other methods for specifically creating Excel workbooks with multiple sheets etc. and details can be found in the SQL and PL/SQL FAQ at the top of the forum:
{message:id=9360007} -
Can we write function in select statement?
i have function and it has Out parameter,so in this case can i write select statement for my function to retrieve the value?
Or, you could use pipelined function - i guess.
Like ->
satyaki>
satyaki>select * from v$version;
BANNER
Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Prod
PL/SQL Release 10.2.0.1.0 - Production
CORE 10.2.0.1.0 Production
TNS for Linux: Version 10.2.0.1.0 - Production
NLSRTL Version 10.2.0.1.0 - Production
Elapsed: 00:00:00.00
satyaki>
satyaki>create or replace type a_obj as object
2 (
3 e_nm varchar2(30),
4 e_sal number(7,2)
5 )
6 /
Type created.
Elapsed: 00:00:00.00
satyaki>
satyaki>
satyaki>create or replace type a_rec as table of a_obj;
2 /
Type created.
Elapsed: 00:00:00.00
satyaki>
satyaki>create or replace function multi_return(e_cd in number)
2 return a_rec
3 pipelined
4 is
5 cursor c1
6 is
7 select a_obj(ename, sal) as a_det_rec
8 from emp
9 where empno = e_cd;
10
11 r1 c1%rowtype;
12 begin
13 for r1 in c1
14 loop
15 pipe row(r1.a_det_rec);
16 end loop;
17
18 return ;
19 end;
20 /
Function created.
Elapsed: 00:00:00.01
satyaki>
satyaki>
satyaki>select * from table(cast(multi_return(&e_no) as a_rec));
Enter value for e_no: 7369
old 1: select * from table(cast(multi_return(&e_no) as a_rec))
new 1: select * from table(cast(multi_return(7369) as a_rec))
no rows selected
Elapsed: 00:00:00.02
satyaki>
satyaki>
satyaki>select * from emp;
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO JOB1 DOB
7521 WARD SALESMAN 7698 22-FEB-81 226.88 500 30 SALESMAN
7654 MARTIN SALESMAN 7698 28-SEP-81 1815 1400 30 SALESMAN
7788 SCOTT ANALYST 7566 19-APR-87 598.95 20 ANALYST
7839 KING PRESIDENT 17-NOV-81 7260 10 PRESIDENT
7844 TURNER SALESMAN 7698 08-SEP-81 2178 0 30 SALESMAN
7876 ADAMS CLERK 7788 23-MAY-87 159.72 20 CLERK
7900 JAMES CLERK 7698 03-DEC-81 1379.4 30 CLERK
7902 FORD ANALYST 7566 03-DEC-81 5270.76 20 ANALYST
7934 MILLER CLERK 7782 23-JAN-82 1887.6 10 CLERK
7566 Smith Manager 7839 23-JAN-82 1848 0 10 Manager 23-JAN-89
7698 Glen Manager 7839 23-JAN-82 1848 0 10 Manager 23-JAN-89
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO JOB1 DOB
7599 BILLY ANALYST 7566 10-JUN-09 4500 30
12 rows selected.
Elapsed: 00:00:00.01
satyaki>
satyaki>select * from table(cast(multi_return(&e_no) as a_rec));
Enter value for e_no: 7698
old 1: select * from table(cast(multi_return(&e_no) as a_rec))
new 1: select * from table(cast(multi_return(7698) as a_rec))
E_NM E_SAL
Glen 1848
Elapsed: 00:00:00.00
satyaki>
satyaki>/
Enter value for e_no: 7599
old 1: select * from table(cast(multi_return(&e_no) as a_rec))
new 1: select * from table(cast(multi_return(7599) as a_rec))
E_NM E_SAL
BILLY 4500
Elapsed: 00:00:00.00
satyaki>Regards.
Satyaki De. -
Javascript and sql select statement
I am working in html db in the 10 g environment. I'm trying to create an "auto suggestion function" that predicts values as the user enters characters into a text field. I've gotten it to work by hard coding the values in the function, ie: states. btw: there are several external javascript files at work here.
What I want is to create a dynamic link to the database to gather, say, all names of providers at the time the page is built to use in the auto suggest format. I want to put this into a javascript routine and I'm having problems finding out how to mix the sql select statement into the javascript function.
For the states example, I'm using:
function StateSuggestions() {
this.states = [
"Alabama", "Alaska", "Arizona", "Arkansas",
"California", "Colorado", "Connecticut",..."Wyoming" ];
Can I substitute the hard coded data (states) with a sql select statement such
as:
select name from <dbtable> ???
How does this need to be "wrapped" or containerized?
Thank you. You have a great product in html db and your site is very useful. I appreciate everything you have done to assist us. Again, thank you.Hi,
You can use TRUNC with 2 arguments to get the first DATE in a month, year, quarter, week, hour, minute, ISO year, ...
SELECT TRUNC ( ADD_MONTHS ( SYSDATE
, 12
, 'MONTH'
) AS first_of_month
FROM dual
;The DATE returned will be in the same month, year, quearter, ... as the first argument.
\We convered the last day of the month in [your previous question|http://forums.oracle.com/forums/message.jspa?messageID=3942939#3942939].
At that time, I warded about using LAST_DAY as a cutoff point; TRUNC is a much better way.
For example, to find all appointment_dates in the current month next year:
SELECT *
FROM appointments
WHERE appointment_date >= TRUNC (ADD_MONTHS (SYSDATE, 12), 'MONTH')
AND appointment_date < TRUNC (ADD_MONTHS (SYSDATE, 13), 'MONTH')Note that
the first part of the WHERE clause calls for dates on or equal to the beginning of the 12th month in the future, but
the second part of the WHERE clause calls for dates before, not equal to , the beginning of the 13th month in the future. -
Using column number inplace of column name in SQL Select statement
Is there a way to run sql select statements with column numbers in
place of column names?
Current SQL
select AddressId,Name,City from AddressIs this possible
select 1,2,5 from AddressThanks in Advanceuser10962462 wrote:
well, ok, it's not possible with SQL, but how about PL/SQL?As mentioned, using DBMS_SQL you can only really use positional notation... and you can also use those positions to get the other information such as what the column is called, what it's datatype is etc.
CREATE OR REPLACE PROCEDURE run_query(p_sql IN VARCHAR2) IS
v_v_val VARCHAR2(4000);
v_n_val NUMBER;
v_d_val DATE;
v_ret NUMBER;
c NUMBER;
d NUMBER;
col_cnt INTEGER;
f BOOLEAN;
rec_tab DBMS_SQL.DESC_TAB;
col_num NUMBER;
v_rowcount NUMBER := 0;
BEGIN
-- create a cursor
c := DBMS_SQL.OPEN_CURSOR;
-- parse the SQL statement into the cursor
DBMS_SQL.PARSE(c, p_sql, DBMS_SQL.NATIVE);
-- execute the cursor
d := DBMS_SQL.EXECUTE(c);
-- Describe the columns returned by the SQL statement
DBMS_SQL.DESCRIBE_COLUMNS(c, col_cnt, rec_tab);
-- Bind local return variables to the various columns based on their types
FOR j in 1..col_cnt
LOOP
CASE rec_tab(j).col_type
WHEN 1 THEN DBMS_SQL.DEFINE_COLUMN(c,j,v_v_val,2000); -- Varchar2
WHEN 2 THEN DBMS_SQL.DEFINE_COLUMN(c,j,v_n_val); -- Number
WHEN 12 THEN DBMS_SQL.DEFINE_COLUMN(c,j,v_d_val); -- Date
ELSE
DBMS_SQL.DEFINE_COLUMN(c,j,v_v_val,2000); -- Any other type return as varchar2
END CASE;
END LOOP;
-- Display what columns are being returned...
DBMS_OUTPUT.PUT_LINE('-- Columns --');
FOR j in 1..col_cnt
LOOP
DBMS_OUTPUT.PUT_LINE(rec_tab(j).col_name||' - '||case rec_tab(j).col_type when 1 then 'VARCHAR2'
when 2 then 'NUMBER'
when 12 then 'DATE'
else 'Other' end);
END LOOP;
DBMS_OUTPUT.PUT_LINE('-------------');
-- This part outputs the DATA
LOOP
-- Fetch a row of data through the cursor
v_ret := DBMS_SQL.FETCH_ROWS(c);
-- Exit when no more rows
EXIT WHEN v_ret = 0;
v_rowcount := v_rowcount + 1;
DBMS_OUTPUT.PUT_LINE('Row: '||v_rowcount);
DBMS_OUTPUT.PUT_LINE('--------------');
-- Fetch the value of each column from the row
FOR j in 1..col_cnt
LOOP
-- Fetch each column into the correct data type based on the description of the column
CASE rec_tab(j).col_type
WHEN 1 THEN DBMS_SQL.COLUMN_VALUE(c,j,v_v_val);
DBMS_OUTPUT.PUT_LINE(rec_tab(j).col_name||' : '||v_v_val);
WHEN 2 THEN DBMS_SQL.COLUMN_VALUE(c,j,v_n_val);
DBMS_OUTPUT.PUT_LINE(rec_tab(j).col_name||' : '||v_n_val);
WHEN 12 THEN DBMS_SQL.COLUMN_VALUE(c,j,v_d_val);
DBMS_OUTPUT.PUT_LINE(rec_tab(j).col_name||' : '||to_char(v_d_val,'DD/MM/YYYY HH24:MI:SS'));
ELSE
DBMS_SQL.COLUMN_VALUE(c,j,v_v_val);
DBMS_OUTPUT.PUT_LINE(rec_tab(j).col_name||' : '||v_v_val);
END CASE;
END LOOP;
DBMS_OUTPUT.PUT_LINE('--------------');
END LOOP;
-- Close the cursor now we have finished with it
DBMS_SQL.CLOSE_CURSOR(c);
END;
SQL> exec run_query('select empno, ename, deptno, sal from emp where deptno = 10');
-- Columns --
EMPNO - NUMBER
ENAME - VARCHAR2
DEPTNO - NUMBER
SAL - NUMBER
Row: 1
EMPNO : 7782
ENAME : CLARK
DEPTNO : 10
SAL : 2450
Row: 2
EMPNO : 7839
ENAME : KING
DEPTNO : 10
SAL : 5000
Row: 3
EMPNO : 7934
ENAME : MILLER
DEPTNO : 10
SAL : 1300
PL/SQL procedure successfully completed.
SQL> exec run_query('select * from emp where deptno = 10');
-- Columns --
EMPNO - NUMBER
ENAME - VARCHAR2
JOB - VARCHAR2
MGR - NUMBER
HIREDATE - DATE
SAL - NUMBER
COMM - NUMBER
DEPTNO - NUMBER
Row: 1
EMPNO : 7782
ENAME : CLARK
JOB : MANAGER
MGR : 7839
HIREDATE : 09/06/1981 00:00:00
SAL : 2450
COMM :
DEPTNO : 10
Row: 2
EMPNO : 7839
ENAME : KING
JOB : PRESIDENT
MGR :
HIREDATE : 17/11/1981 00:00:00
SAL : 5000
COMM :
DEPTNO : 10
Row: 3
EMPNO : 7934
ENAME : MILLER
JOB : CLERK
MGR : 7782
HIREDATE : 23/01/1982 00:00:00
SAL : 1300
COMM :
DEPTNO : 10
PL/SQL procedure successfully completed.
SQL> exec run_query('select * from dept where deptno = 10');
-- Columns --
DEPTNO - NUMBER
DNAME - VARCHAR2
LOC - VARCHAR2
Row: 1
DEPTNO : 10
DNAME : ACCOUNTING
LOC : NEW YORK
PL/SQL procedure successfully completed.
SQL> -
Jdev9i, JSP, Execute a Sql Select statement directly?
Hi,
I need the syntax to execute a Sql SELECT statement directly against Oracle database and access rows(returned by SELECT statemnet) in a JSP page or Servlet? Any sample code available for this.
Thanks.Hi Ali,
I didn't work a lot with jsp ,but on this url some help .
http://otn.oracle.com/docs/products/oracle8i/doc_library/817_doc/java.817/a83726/basics7.htm#1014578 -
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. -
Need Select statement for fetch the details
Hi
i want to fetch particular customer wise sales orderds and that sales order No and date of sales order was created.. and that sales order related PO No and Materials ..
for this.. how can i write an executable programm.. is it needed to define seperate internal tables or single internal table is enough ?
what is the select statement for fetching all these details..
any help will be appriciated
Thanks
Bbaucustmer master table is KNA1 knb1 knbk
sales data tables r VBAK VBAP VBEP
Material data MARA, MARAC, MARD
PO RELATED ekko ekpo eket
<REMOVED BY MODERATOR>
Edited by: Alvaro Tejada Galindo on Feb 13, 2008 3:04 PM
Maybe you are looking for
-
MB5B report in column structure
Hi All, Can you suggest me a report where I can get the details as mentioned below in tabular format for a specified period? (i.e. Suppose in November month we want to get the detail for the month of April the opening and closing stock along with th
-
HOW TO DISPLAY THE TEXT ON A PARTICULAR PAGE IN SAPSCRIPTS
HI, HOW TO DISPLAY THE TEXT ON A PARTICULAR PAGE IN SAPSCRIPTS?
-
Sap business one studio 9.0 for microsoft visual studio 2010
Hi Experts, After added a new project, Sap business one 9.0 Add-on Project, that project can't be loaded in Visual Studio 2010. When try to re-load the project in the Solution Explorer, the project stays as (unavailable), and the next line says, The
-
My Verizon wireless service at my house has begun to degrade over the last 6 Month. It has begun to be very frustrating seeing how we switched over from Satellite to Verizon 4GLTE wireless device. How do I contact someone to see what the issue may
-
Contacts app not finding names in Exchange 2010
Contacts app not finding names in Exchange 2010 server This is weird, could be a bug in 10.8.2, not sure, want to see if anyone else is seeing this. Mountain Lion 10.8.2 Exchnage account created for: Mail, Contacts, Calendars. All looks good there. C