How to write a query in sql?
List employee details empno,ename,job,DOB, retire_date. i want
Retire date=bod + 58 year.. Display DOB in 'dd-mon-yyyy' format and retire_date in 'mon-yyyy'
Edited by: 1008586 on Jun 5, 2013 8:26 PM
Edited by: 1008586 on Jun 5, 2013 8:30 PM
Welcome to the forum!
Whenever you post provide your 4 digit Oracle version.
>
List employee details empno,ename,job,DOB, retire_date.
Retire date=bod + 58 year.. Display DOB in 'dd-mon-yyyy' format and retire_date in 'mon-yyyy'
>
And your question or issue is?
Similar Messages
-
How to write exact query from sql to oracle?
Hi all,
hope doing well,
sir i am using one query in sql that is
declare @earlyleavers varchar(max), @earlyleavers1 int
select @earlyleavers1 = DATEDIFF(Minute,'1900/01/01 10:00:00.000','1900/01/01 11:00:00.000')
select @earlyleavers = CONVERT(char(8),DATEADD(n,@earlyleavers1,0),108)
print @earlyleavers
and i am getting the result like this
01:00:00
how to get the same result in oracle
please help me.
thanks in advance.952646 wrote:
sir i need result in this format 01:00 not in 1 format.The name is Billy and not "sir". :-)
Is "01:00" a string format or an elapsed time format?
The number that the above code returns is decimal hours. So a number value of 1.5 means 1h30m or 1:30 or however you need to render that.
And that is the question. Is this a rendering issue? Must the result be rendered in a specific format?
If so, then this is not a SQL or PL/SQL issue. The server returning decimal hours is acceptable. The client (e.g. C#/Java code) needs to decide how to format and render this meaningful value. Keep in mind that if the sever code returns "1.30" or "1:30" for example, these are string/text data and pretty much meaningless. And it does not make sense for server code to return meaningless text strings to the client.
If the client expects a duration and not a numeric data type, then the server code should return a value of the INTERVAL DAY TO SECOND data type.
This data type specifically exists to contain duration values between to dates or times.
In this case, the server code will expect the host (C#/Java) variable to be of data type INTERVAL DAY TO SECOND. The server code will look something as follows:
SQL> declare
2 earlyleavers interval day to second;
3 begin
4 earlyleavers := NumToDSinterval(
5 (to_date('1900/01/01 11:00:00','yyyy/mm/dd hh24:mi:ss') -
6 to_date('1900/01/01 10:00:00','yyyy/mm/dd hh24:mi:ss') ) * 24,
7 'hour'
8 );
9
10 dbms_output.put_line( to_char(earlyleavers) );
11 end;
12 /
+00 01:00:00.000000
PL/SQL procedure successfully completed.
SQL>An interval-to-string conversion function is used (with default formatting) to "print" the interval value via DBMS_OUTPUT. The default format includes days and a sign to indicate a positive or negative interval. Look at the SQL Reference manual for the format masks that can be used.
The important thing is to treat data values correctly using the most appropriate type. And intervals should either be a decimal day/hour/minute numeric type, or an actual interval type. -
How to write this query ?
how to write this query ?
list the emp name who is working for the highest avg sal department.
I can use row_number over to get correct result. If we don't use this row_number function, just plain sql, how to do it ?
the row_number version is like this
select emp.* from emp ,
select deptno, row_number() over (order by avg(sal) desc) r from emp
group by deptno
)e
where e.r = 1
and emp.deptno = e.deptnoHi,
806540 wrote:
how to write this query ?
list the emp name who is working for the highest avg sal department.
I can use row_number over to get correct result. If we don't use this row_number function, just plain sql, how to do it ?ROW_NUMBER is just plain SQL, and has been since Oracle 8.1.
ROW_NUMBER (or its close relative, RANK) is the simplest and most efficient way to solve this problem. Why not do this the right way?
the row_number version is like this
select emp.* from emp ,
select deptno, row_number() over (order by avg(sal) desc) r from emp
group by deptno
)e
where e.r = 1
and emp.deptno = e.deptno
If there happens to be a tie (that is, two or more departments have the same average sal, and it is the highest), then the query above will only arbitrarily treat one of them (no telling which one) as the highest. Change ROW_NUMBER to RANK to get all departments with a claim to having the highest average sal.
You could use the ROWNUM pseudo-column instead of ROW_NUMBER, if all you want to do is avoid ROW_NUMBER.
Without using ROW_NUMBER or RANK, there are lots of ways involving other analytic functions, such as AVG and MAX.
If you really, really don't want to use analytic functions at all, you can do this:
SELECT *
FROM scott.emp
WHERE deptno IN (
SELECT deptno
FROM scott.emp
GROUP BY deptno
HAVING AVG (sal) = (
SELECT MAX (AVG (sal))
FROM scott.emp
GROUP BY deptno
; -
How to write this query to filter combination of few values
Hi,
I have a table CHIMM which is a transaction table and contains information of the vaccines given to a child.
columns are: child_id, vacc_id, vacc_given_dt. I have to query for remaining vaccines.
HEXA is a vaccine_id which is composite vaccine of DPT1,POL1,HBV1 & HIB1 (vaccine ids).
I want to write to query if any of DPT1,POL1,HBV1 & HIB1 given then HEXA should not be displayed in the result.
OR
if HEXA is given then of course any of DPT1,POL1,HBV1 & HIB1 should not be displayed in the result.
How to write this query?
RegardsHi,
I'm still not sure what the output you want from that sample data is. Do you just want the child_ids, like this
CHILD_ID
3
4? If so, here's one way to get them:
WITH all_vacc_ids AS
SELECT c.child_id
, c.vacc_id AS child_vacc_id
, v.vacc_id
, COUNT ( CASE
WHEN c.vacc_id = 'HEXA'
THEN 1
END
) OVER ( PARTITION BY c.child_id
) AS hexa_itself
FROM vacc v
LEFT OUTER JOIN chimm c PARTITION BY (c.child_id)
ON c.vacc_id = v.vacc_id
WHERE v.vacc_desc = 'HEXA' -- See note below
SELECT child_id
FROM all_vacc_ids
WHERE child_vacc_id IS NULL
AND vacc_id != 'HEXA'
AND hexa_itself = 0
GROUP BY child_id
rha2 wrote:there are alot of vaccines, i just put 3 for example. this query gives error: invalid relational operatorAre you saying that the vacc table contains other rows, but those other rows are not needed for this problem? It would be good if you included an example in the sample data. The query above considers only the rows in vacc where vacc_desc='HEXA'. You can have other rows in the vacc table, but they won't affect the output of this query. The query above makes no assumptions about the number of rows that have vacc_desc='HEXA'; it will report all child_ids who are missing any of them, regardless of the number (assuming the child does not have the 'HEXA' vacc_id itself, like child_id=1).
You still haven't said which version of Oracle you're using. The query above will work in Oracle 10 (and higher). -
Hi all,
Can you please explain me how to write a query joining tables in SAP ?
Thanks,
Avani.Hi
Check info from sdn only
User T-code: SQVI
Enter your "query name" and press"create"
Enter title
In Data source " select Table join"
select basis mode and press continue.
Press Insert table and give the tabes one by one.
Drag the parameter and drop in another table to establish link and link all the tables.
Press check to check whether your link is correct, then press back
You will be able to see the tables and fields on left hand side.
Select the appropriate parameters for selection fields and list fields
Selection fields- For selection of data, the initial screen of report.
List fields are nothing but output.
Execute the report.
You will find the initial screen of report.
Give your parameters for output and execute again.
You will receive the desired output.
You can down load the output in spread sheet/ in the format desired.
At last save your query before coming out of transaction
Vishal... -
How to write a Query a table and the return result is the column name
Hi All
Pls advise how to write a query whereas the return result is the
column name.
I know there is describe <table_name>;
Is there any other ways?
Pls advise
Tj
Edited by: user600866 on Oct 14, 2008 12:13 AMData Dictionary table user_tab_columns has all the column names. You can query that and get what ever you want.
To get the column list of a table just query
select *
from user_tab_columns
where table_name = <your_table>Edited by: Karthick_Arp on Oct 14, 2008 12:18 AM -
How to write named query if we want to use IN syntax in our sql statement?
I cannot find a suitable category about named query, so please move to appropriate place if there is any.
When we write named query, below statement is fine.
Query q2 = em.createQuery("SELECT o FROM Table1 as o WHERE field1 = :input1"); q2.setParameter("input1", "value1");
Now, my question is, how can I write this type of query when we want to use the IN sql syntax? As below statement CANNOT return correct results. Even I tried to put a pair of single quote [ ':input2' ], it won't help also.
Query q2 = em.createQuery("SELECT o FROM Table1 as o WHERE field2 IN (:input2)"); q2.setParameter("input1", "3633, 3644");
Can anyone suggest? Thanks.roamer wrote:
Now, my question is, how can I write this type of query when we want to use the IN sql syntax? As below statement CANNOT return correct results. Even I tried to put a pair of single quote [ ':input2' ], it won't help also.
Query q2 = em.createQuery("SELECT o FROM Table1 as o WHERE field2 IN (:input2)");
q2.setParameter("input1", "3633, 3644");
Can anyone suggest?The above is in your code right? Not in some configuration file?
Then you do it the same way as with regular jdbc/sql.
1. You start with a collection of values - call it collection A.
1. Create a for loop that dynamically creates the string using 'bind' variables (whatever you want to call the 'colon' entity in the above).
2. Call the createQuery method using the string that was created
3. Create a second loop that iterates over A and populates with setParameter.
Pseudo code
Object[] A = ...
String sql = "SELECT o FROM Table1 as o WHERE field2 IN (";
for (int i=1; i <= A.length; i++)
if (i == 1)
sql += ":input" + i;
else
sql += ",:input" + i;
sql += ")";
Query q2 = em.createQuery(sql);
for (int i=1; i <= A.length; i++
q2.setParameter("input" + i, A[i-1]);
}By the way there is a jdbc forum. -
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 -
How to write a query for this output
I have a string ' if i know good acting , I am a hero '
now if 'hero' is present in the string it will return ' i am hero' else
'you are hero'
How to write a sql query to return the same .SQL> select (case
2 when '&a' like '%hero%' then 'I am hero'
3 ELSE 'u r hero'
4 end) output from dual;
Enter value for a: if i know good acting , I am a hero
old 2: when '&a' like '%hero%' then 'I am hero'
new 2: when 'if i know good acting , I am a hero ' like '%hero%' then 'I am hero'
OUTPUT
I am hero
SQL> /
Enter value for a: jkhkh
old 2: when '&a' like '%hero%' then 'I am hero'
new 2: when 'jkhkh' like '%hero%' then 'I am hero'
OUTPUT
u r hero
Hope this helps. -
How to write a query for the given scenario ?
Hi All ,
I am having two tables EMP, DEPT with the below data.
EMP TABLE :--
EID ENAME JOB SAL DEPID
111 RAM MANAGER 1500 10
222 SAM ASST MANAGER 2000 20
333 KALA CLERK 2500 10
444 BIMA MANAGER 3000 20
555 CHALA MANAGER 3500 30
666 RANI ASST MANAGER 4000 10
777 KAMAL MANAGER 2400 10
DEPT TABLE :--
DEPID DNAME
10 XX
20 YY
30 ZZ
Q1 : I want the sum of salary of each department and for the particular job . Here in each departmant manager, asst. manager, clerk posts are there .
I want to display the result like below ....
JOB 10 20 30
MANAGER 3900 3000 3500
ASST MANAGER 4000 2000 NULL
CLERK 2500 NULL NULL
please tell me how to write a sql query ?
Thanks
SaiIn general case, you cannot write this query.
This is one of the limits of relational database concepts. The number of columns must be known up-front. In the SELECT clause, you have to list and name all columns returned by the query. So you have to know number of departments. (There are some workarounds - you can return one column with concatenated values for all departments, separated by space character).
If you know that you have 3 departments then you qurey will return 4 columns:
SELECT
e.job,
SUM ( CASE WHEN d.deptid = 10 THEN e.sal ELSE NULL END) d10,
SUM ( CASE WHEN d.deptid = 20 THEN e.sal ELSE NULL END) d20,
SUM ( CASE WHEN d.deptid = 30 THEN e.sal ELSE NULL END) d30
FROM dept d, emp e
WHERE d.deptno = e.deptno
GROUP BY e.job -
Crystal Report XI: Can you write your query in SQL instead of using the GUI
Hello
In crystal report version XI, can you write your query in sqlplus and then use the crystal report designer to build your report instead of using the GUI . I would like to be able to go database and show sql query and open that query and make changes directly there, is that possible on this version, if yes is there a setting somewhere? Please let me know.
Thank you
alphaMoved to Database forum.
No you can no longer modify the SQL directly. Use a Command Object to enter the SQL directly.
Thank you
Don -
How to get exact query of sql in oracle?
Hi all,
Hope doing well,
sir i was using one query of sql that is here:
Declare @nshiftmax datetime
set @nshiftmax=convert(time,DATEADD(N,1439,0))
print @nshiftmax
so it is retreiving the result 1/1/1900 11:59 p.m
and one more query is there
Declare @nshiftmax datetime
set @nshiftmax=convert(time,DATEADD(N,0,0))
print @nshiftmax
so it is retreiving the result 1/1/1900 12:00 a.m
how to same result in oracle query.
thanks in advance.952646 wrote:
Hi all,
Hope doing well,
sir i was using one query of sql that is here:
You mean you have these statements in SQL Server?
Please remember that SQL is an access language for relational databases. It is used by all of the major rdbms products. "SQL Server" is the name of Microsoft's rdbms product. Do not let Microsoft's marketing flaks lull you into thinking SQL = SQL Server.
Declare @nshiftmax datetime
set @nshiftmax=convert(time,DATEADD(N,1439,0))
print @nshiftmax
so it is retreiving the result 1/1/1900 11:59 p.m
and one more query is there
Declare @nshiftmax datetime
set @nshiftmax=convert(time,DATEADD(N,0,0))
print @nshiftmax
so it is retreiving the result 1/1/1900 12:00 a.m
how to same result in oracle query.
thanks in advance. -
How to write a query for grouping them the columns and give the sequence order to each group/
Hi i have table that contains country columns .
India,USA,UK like these when ever the group changed into the differt country i make a group and arrange them the sequence into those Countries
like below
1)India
2)India
1)USA
2)USA
like these to write a query ..........pls help me for this queryAssuming you're using SQL Server you can ask here:
http://www.sqlteam.com/forums/forum.asp?FORUM_ID=23
Otherwise, please ask in the relevant forum for the type of technology you're using.
Basically it's either:
select *
from [table name]
order by country
If you want to do something with groups do something like:
select (max) income, country
from [table name]
group by country
Kind regards,
Margriet Bruggeman
Lois & Clark IT Services
web site: http://www.loisandclark.eu
blog: http://www.sharepointdragons.com -
How to write workflow rules/expressions/SQL
Hi all.
We are recent users of CRM onDemand, we would like to write some workflow rules but cannot seem to find any information on how to do this. The help section is limited in answers, and some of the questions here are also not specific to what we would like to do.
Does anyone have any advice on books, web sites, etc. on where to find the knowledge we need on how to write the workflow rules and use SQL and expressions in CRM on Demand?
Thanks in advance!!For your first case:
1. You cannot create a workflow in r15 for activity but in R16 you can
Create new to create a workflow
Name: Auto email send
record type: activity
trigger: when new record saved
rules: put your rules by clicking on the fx icon i.e this is where you are entering the rule saying the owner is different from the person who is creating the activity or the delegated field is filled (another way of looking at it)
then save the workflow
In the actions section
choose the action "Create Email Notification"
In the To: Section choose "Relative User on Record" and Choose "Activity Owner"
Save it. Make sure both the workflow and activity are marked active.
2. In your second scenario:
How do you expect to create an account and automatically populate the Sales rep's name - not sure
But you can create an opportunity and auto fill with the Account Owner's name by using this in the field validation (you do not need the workflow), you can use the FieldValueJoin function.
Hope this helps - btb there is no book you can go thro the help and you will find some directions -
How to write a query for this situation
Hi ,
Can any one help me to write a query.I have a table with three columns like char_id_1,char_id_2,char_id_3,these data have to insert into some other table but in the target table the data should be comma seperated like (10,8,2),here blank space indicates null.In source table the columns are numbers,but in target table it is varchar2.
source table:
CHAR_ID_1 CHAR_ID_2 CHAR_ID_3
10 8 2
7 1 5
4 11
6 1
2 8
6 12 7
Target table:
CHAR_IDS
10,8,2
7,1,5
4,11
6,1
2,8
6,12,7I started doing it to_char way, and thought of some different version, and ended up with an ugly solution which works only if you have three columns. Thought of not posting, but posting it anyway:
Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bit Production
With the Partitioning, OLAP and Data Mining options
SQL> with t as(
2 select 10 c1,8 c2,2 c3 from dual union all
3 select 7,1,5 from dual union all
4 select 4,null,11 from dual union all
5 select null,6,1 from dual union all
6 select 2,8,null from dual union all
7 select null,8,null from dual union all
8 select null,null,10 from dual union all
9 select 2,null,null from dual union all
10 select null,null,null from dual union all
11 select 6,12,7 from dual )
12 --
13 select nvl2(c1,
14 c1 || nvl2(c2,',' || c2 || nvl2(c3,',' || c3,null),nvl2(c3,',' || c3,null)),
15 nvl2(c2, c2 || nvl2(c3,','|| c3,null),nvl2(c3,c3,null))) col_concat
16 from t;
COL_CONCAT
10,8,2
7,1,5
4,11
6,1
2,8
8
10
2
6,12,7
10 rows selected.
SQL>
Maybe you are looking for
-
Error after re-installing mac OS X 10.5....
So I took my Imac to the Mac store and a tech looked at it and came to the conclusion I need to un-install Mac OS X 10.5 and re-install it with a clean slate... I did and at the end of the download an error came up saying about not being able to down
-
Hi, We are working on MM-SUS Scenario. Created PO in ECC and got transferred to SUS, we have created Purchase Order Response in SUS. From SUS end it is sucess. But at the ECC we are getting the below error in Inbound IDOC. Error Details Order units d
-
How can I use my N81 as a modem?
I have an edge or Media Net and I want to use it as a modem on my laptop can someone help me set it up thank you
-
How can i upgrade Oracle Workshop for WebLogic 10.3 -Upgrade
Hi, I am using Oracle Workshop 10.3.1 version. As it cannot support SOAP 12, I want to upgrade it to some higher version which support SOAP 1.2. without deleting the existing workshop. is it possible? Can you please provide the plugin for upgradation
-
Hello all, I am new to working with LabVIEW, and I am currently attempting to install software onto a Compact RIO NI-9024 under LabVIEW 8.6.0 on Windows 7 x64. I have installed LV, the Real-Time module, and the cRIO device drivers DVD (to the best o