Basic SQL queries in Scott/tiger schema...
One of my team member who is a fresher wants to learn SQL.
Access to Scott/tiger is available.
Can some links or queries be posted which can be tried and will be useful to learn SQL.
Hi,
Read the following links:
http://download-uk.oracle.com/docs/cd/B19306_01/appdev.102/b14261/toc.htm
http://download-uk.oracle.com/docs/cd/B19306_01/server.102/b14200/toc.htm
http://download-uk.oracle.com/docs/cd/B19306_01/appdev.102/b14251/toc.htm
Regards
Avinash
Similar Messages
-
Grant permission on SCOTT/tiger schema
grant select, insert, update, delete on EM to BOMBAC
I want to add permission that user BOMBAC can see EM table from SCOTT/tiger scheme and use it. But he can not see and use it. Any idea why?
regardsyes i try with public but it seems that i do not have enought privilegies
*Cause: An attempt was made to change the current username or password
without the appropriate privilege. This error also occurs if
attempting to install a database without the necessary operating
system privileges.
When Trusted Oracle is configure in DBMS MAC, this error may occur
if the user was granted the necessary privilege at a higher label
than the current login.
*Action: Ask the database administrator to perform the operation or grant
the required privileges.
For Trusted Oracle users getting this error although granted the
the appropriate privilege at a higher label, ask the database
administrator to regrant the privilege at the appropriate label. -
How to test basic sql queries online(for Sql Server 2012 and up versions) ?
Hi,
I need to test basic sql queries using sql server without installing Sql Server on to the system.
Do we have such readymade online help, which can solve such difficulties ?
Please sugest some of url's.
Thanks.Thanks for reply.
I am looking specific Sql Server.
Hi Maggy,
I strongly recommend you install SQL Server 2012 express edit and test your T-SQL queries. We can download it from the following site:
Microsoft® SQL Server® 2012 Express:
http://www.microsoft.com/en-hk/download/details.aspx?id=29062
Regards,
Elvis Long
TechNet Community Support -
Oracle 11g SQL signon - The scott/tiger routine...
I just installed Oracle 11g.
First, what is the ID/PW into SQL - it used to be scott/tiger. I changed it to what I wanted on install. However, when I logon and type scott then tiger its says
account locked out. I tried scott and my own "created pw". It still didn't let me in. Is there an "easy" fix?
I have to get this aspect going to get to first base. How do I get around this or FIX it????
Walter Earl Roper
University of Illinois
[email protected]By default, most of the demo accounts are created but locked so that they are not security holes if they are inadvertently included in a production install. To unlock scott
- Connect as SYS, i.e. from the command line (DOS prompt in Windows)
sqlplus / as sysdba- Unlock the account
SQL> ALTER USER scott ACCOUNT UNLOCK;Now, you should be able to log in as SCOTT. If you want to log in as HR, OE, or any of the other demo accounts, you'd repeat the procedure.
Justin -
Sql queries for this database schema
1) Patient—PatientID, Name, DOB
2) Doctor—DoctorID, Name, MedLicenseNumber, Phone
3) Medication—MedicationID, BrandName, GenericName
4) Prescription—PrescriptionID, Date, PatientID, PrescriberID, MedicationID
Specify the SQL queries to retrieve:
a) The prescription information along with patient name, DOB, medication brand name, and prescribing doctor name sorted by most recent date.
b) The most prescribed generic medication nameLooks like assignment question to me
a, seems to be a case of straight forward join among all the involved tables on common fields. Suggest you learn about joins and try it out yourself.
see below link
http://www.w3schools.com/sql/sql_join.asp
b, Have a look at GROUP BY. you need to apply group by and take medicine name which repeats maximum (ie largest count value)
see
http://www.w3schools.com/sql/sql_groupby.asp
Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs -
An interesting problem in emp table of scott/tiger schema, kindly help
I want to write SQL which can give me the result in columns
ENAME, EMPNO, DEPTNO, DEPT_WISE_PCT_OF_EMP_SAL,
CMP_WISE_PCT_OF_EMP_SAL
i write a sql by using multiple select statements like
select ename, ename, emp.deptno, sal, (sal/a.cmp_sal )*100 cmp_sal_pct, (sal/dept_sal.dept_sal)*100 dept_sal_pct
from emp, (select sum(sal) cmp_sal from emp) a,
(select deptno, sum(sal) dept_sal from emp group by deptno) dept_sal
where dept_sal.deptno = emp.deptno
ENAME ENAME DEPTNO SAL CMP_SAL_PCT DEPT_SAL_PCT
CLARK CLARK 10 2450 8.4409991386736 28
KING KING 10 5000 17.226528854436 57.142857142857
MILLER MILLER 10 1300 4.4788975021533 14.857142857143
SMITH SMITH 20 800 2.7562446167097 7.3563218390805
ADAMS ADAMS 20 1100 3.7898363479759 10.114942528736
FORD FORD 20 3000 10.335917312661 27.586206896552
SCOTT SCOTT 20 3000 10.335917312661 27.586206896552
JONES JONES 20 2975 10.249784668389 27.35632183908
ALLEN ALLEN 30 1600 5.5124892334195 17.021276595745
BLAKE BLAKE 30 2850 9.8191214470284 30.31914893617
MARTIN MARTIN 30 1250 4.306632213609 13.297872340426
JAMES JAMES 30 950 3.2730404823428 10.106382978723
TURNER TURNER 30 1500 5.1679586563307 15.957446808511
WARD WARD 30 1250 4.306632213609 13.297872340426
but i want to solve this problem using single sql
i write the required sql but i unable to get the salary on company basis(total sal of all emp)
select emp.ename, emp.deptno, emp.empno, emp.sal,
(emp.sal/sum(dept_emp.sal))*100 dept_sal_pct
from emp, emp dept_emp
where emp.deptno = dept_emp.deptno
group by emp.ename,emp.deptno, emp.empno, emp.sal
ENAME DEPTNO EMPNO SAL DEPT_SAL_PCT
CLARK 10 7782 2450 28
KING 10 7839 5000 57.142857142857
MILLER 10 7934 1300 14.857142857143
ADAMS 20 7876 1100 10.114942528736
FORD 20 7902 3000 27.586206896552
JONES 20 7566 2975 27.35632183908
SCOTT 20 7788 3000 27.586206896552
SMITH 20 7369 800 7.3563218390805
ALLEN 30 7499 1600 17.021276595745
BLAKE 30 7698 2850 30.31914893617
JAMES 30 7900 950 10.106382978723
MARTIN 30 7654 1250 13.297872340426
TURNER 30 7844 1500 15.957446808511
WARD 30 7521 1250 13.297872340426
thanks in advanceTry this (untested)
select ename, ename, emp.deptno, sal,
RATIO_TO_REPORT(sal) OVER ()*100 cmp_sal_pct,
RATIO_TO_REPORT(sal) OVER (PARTITION BY dept)*100 dept_sal_pct
from empRATIO_TO_REPORT is the key. If this doesn't work then check the docs. -
Simple scott/tiger query in horizontal format
Hi Guys, this is my first thread to this forum, as I m a java developer and does not come across sql frequently.
I have a simple requirement.
I ll need this example to let u know, what is all I need.
You must be very well aware of the famous scott/tiger schema in Oracle database where the emp table has a many-one relationship with dept table.
Is there any way, where I can get the data in the below format (assuming one dept will have maximum 4 employees and minimum 0 employees)
DeptNo Employee1 Employee2 Employee3 Employee4
Accounting CLARK KING MILLER Null
Research JONES SCOTT ADAMS FORD
Sales ALLEN WARD NULL NULL
thanks in advance,
AbzeeHi, Abzee,
Welcome to the forum!
That's called a Pivot and here's one way to do it:
WITH got_rnum AS
SELECT deptno
, ename
, ROW_NUMBER () OVER ( PARTITION BY deptno
ORDER BY ename
) AS rnum
FROM scott.emp
SELECT d.dname
, MIN (CASE WHEN r.rnum = 1 THEN r.ename END) AS employee1
, MIN (CASE WHEN r.rnum = 2 THEN r.ename END) AS employee2
, MIN (CASE WHEN r.rnum = 3 THEN r.ename END) AS employee3
, MIN (CASE WHEN r.rnum = 4 THEN r.ename END) AS employee4
FROM scott.dept d
JOIN got_rnum r ON r.deptno = d.deptno
GROUP BY d.dname
;To do a pivot, you must have columns or expressions that tell what row and column of the output correspond to each row of the input.
In this example, d.dname uniquely identifies the row of the output, but there's nothing that says that 'JONES' belongs in the employee1 column rather than the employee2 column. I used ROW_NUMBER to assign each employee a number, starting with 1 in each deptartment, for just that reason. I used ORDER BY ename, so that the employees will appear in alphabetic order. You could use any other way of sorting them (e.g., by salary or descending hiredate).
This site normally compresses multiple spaces into one space.
To post formatted text, such as your desired reuslts, type these 6 characters:
(all small letters, inside curly brackets) before and after the formatted sections. -
Connect string for scott/tiger
i've personal oracle 8i with only scott/tiger schema on my pc. i installed forms 6i. when i try to connect to my scott/tiger schema it gives me tns listener error. i'm using scott/tiger as username/password. i tried keeping Host string null and 'ORCL' but no luck....
any help is appreciated
thank you very much
---himanshuHimanshu,
When u have the default database and Oracle Forms on the same machine, from SQL prompt it will connect to the database without any connect string. But when u connect from Forms u NEED to have a TNS entry. Open explorer --> Oracle Home directory --> Network --> Admin and u will find the Tnsnames.ora Open this file and create a new TNS entry ( u will find examples ) Give ur machine IP address/or user name and SID ( which will be ORCL by default ) save this file. Then connect from Forms it will connect. Good luck
orcl.world =
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS =
(COMMUNITY = tcp.world)
(PROTOCOL = TCP)
(Host = your machine IP)
(Port = 1521)
(CONNECT_DATA = (SID = ORCL)
now orcl is ur TNS name -
hai friends!
I installed D2K recently. Iam unable to login to sql (directly or from D2K forms) using the usual username/password..scott/tiger,system/manager,demo/demo. I get the following error message :
TNS error: Unable to connect to destination
Please help me out!
thanX,
rajiwhat is your error number.
Did you try to look up this number in the oracle error book?
Usually you can also find the solution there.
My bet is that your tnsnames.ora file is not set properly. -
Problem in login with scott/tiger in SQL Plus
Hi,
I want to login with Scott/Tiger in SQL Plus, I have client on my machine, I can connect to any database by entering entry in tnsnames.ora file, but when I try to login with scott/tiger, Protocol adapter error comes, Do I need to enter any thing in tnsnames.ora file? if yes, please tell me the entries,
Thanks
Nidhi..I have modified tnsnames.ora file, Below is this file
ORCL =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
(CONNECT_DATA =
(SERVER = DEDICATED)
(SERVICE_NAME = ORCL)
Now i ger error
Error: ORA-12541: TNS: no listener
Regards,
Nidhi.. -
Sql plus not accepting user id and password as scott, tiger resp
Hi, this is mihir shah
I have just installed oracle9i
And I have a problem in opening the sql plus. It asks for user id and pass but when entered scott, tiger it always gives a tns error.
Could you tell me how to make a database & how to log on & how to make a new user id and passwordIt seem that you have problem with network connectivity to you database.
Check the listener status and the configuration of the files: tnsnames.ora & listener.ora
In all cases you must specified the error.
Bye, Aron -
Hi,,
I am having 4 sql queries with me. I want know which user or schema has excecuted this 4 sql queries in my database.
My oracle database is 10g.
Please help...-find sql_id from v$sql view.
-check required detail from v$active_session_history where sql_id='above id';
Handle: Pravin
Status Level: Newbie
Registered: Dec 28, 2010
Total Posts: 79
Total Questions: 24 (18 unresolved)
mostly question are still open,
please have a look https://forums.oracle.com/forums/ann.jspa?annID=885 -
hello all
i have a query. i want to abort a query running in a thread with a help of another thread
my programs looks like this
public class test
public static void main(String args[]) throws Exception
String driverName = "oracle.jdbc.driver.OracleDriver";
String url = "jdbc:oracle:thin:@192.168.103.46:1521:test";
Class.forName(driverName); // load the driver
Connection connection = DriverManager.getConnection(url, "scott", "tiger");
ConnThread connThread = new ConnThread();
connThread.stmt = connection.prepareCall("{call NEWOBJECT(?)}");
connThread.stmt.registerOutParameter(1,OracleTypes.CURSOR);
connThread.start();
System.out.println ("waiting");
Thread.sleep(20);
System.out.println ("waiting done");
System.out.println ("closing conn");
connThread.stmt.cancel();
System.out.println ("closing conn done");
class ConnThread extends Thread
CallableStatement stmt = null;
public void run()
try
System.out.println ("Executing query");
stmt.executeQuery();
System.out.println ("Executing query done");
catch(Exception e)
e.printStackTrace();
My prob is that i have achieved that in case of normal sql query. but i have to do the same for SQL procedures. can ne one tll me is it even possible to do so. Also i want to check this for range of databases mainly for oracle, MS SQL and MS Access.
Thanking in advance
Regards
SaurabhKiran Bathula wrote:
How to tune SQL Queries ?
Learn how the optimizer works.
Learn what it it capable of.
And then.
Just start. The only way to become a SQL tuner, is to just do it (and do it many many times). -
How to execute sql-queries through shell scripting in linux?
How to execute sql-queries through shell scripting in linux?
http://www.oracle.com/technology/pub/articles/saternos_scripting.html
Two simple examples:
#!/usr/bin/env bash
set_orafra () {
orafra=`echo 'set heading off
select name from v$recovery_file_dest;
exit' | sqlplus -s / as sysdba`
set_orafra
echo $orafra
#!/usr/bin/env bash
export ORACLE_SID=instance_name
export ORACLE_HOME=/path_to_oracle_home_directory
export LD_LIBRARY_PATH=$ORACLE_HOME/lib
export PATH=/$ORACLE_HOME/bin/$PATH
$ORACLE_HOME/bin/sqlplus -s <<EOF
connect scott/tiger@my_instance_name
INSERT INTO table VALUES (sysdate);
exit
EOFEdited by: Markus Waldorf on Sep 17, 2010 12:19 AM -
Need help in SQL Queries using GUI controls or variables
Hello, all
I have a big problem (I have already had with Visual Basic a few mounths ago) with Java while writing my SQL Queries.
I would like to know how I must do to use variable data or GUI control data in my SQL Query to select only some records.
Here, my first Query that works without any problem (no WHERE clause !!!) :
Statement requeteBedes = connectBedes.createStatement();
ResultSet resultatSeries = requeteBedes.executeQuery("SELECT * FROM Series");
initComboBoxSeries(resultatSeries);the method "initComboBoxSeries" fills a JComboBox with all the names of the series in my database.
Here comes my problem.I would like to use the value of the selected "series" in the JComboBox to search in another table of the same Database. I made another statement but it returns a Null ResultSet :
ResultSet resultatSearchAlbumsFromSeries = requeteBedes.executeQuery("SELECT * FROM bandes_dess WHERE ser_nom = '" + strComboBoxSeriesSelected + "' "); The variable strComboBoxSeriesSelected contains the value of the selected line in the combobox with all the series, filled after the first query that is here above and that works very well.
Could some one help me and tell me how I must use variables or GUI controls values in my SQL Queries or tell me if there is a place where I could find an explanation of that kind of problems (like more "advanced SQL Queries", as the ones currently used in all the Learning Java 2 books)
Thank you all for your help.
Christian.executeQuery() will never return null. At least that's what the spec says. You are probably catching an exception (probably a syntax error caused by a single quote in strComboBoxSeriesSelected) and ignoring it. Or do you mean the ResultSet contains no rows?
Anyway, to use parameterized queries, take a look at PreparedStatements. Your code should look like this using PreparedStatement:Statement requeteBedes = connectBedes.prepareStatement("SELECT * FROM bandes_dess WHERE ser_nom = ?");
requeteBedes.setString(1, strComboBoxSeriesSelected);
ResultSet resultatSeries = requeteBedes.executeQuery();Alin.
Maybe you are looking for
-
Adobe Reader 6 and windows 8.1
i recently bought a new laptop and it has windows 8.1. i have always preferred to use Adobe Reader 6 because i can delete pages, insert pages, etc. problem is it won't work with 8.1. how do i get the new adobe reader to do what i used to be able t
-
MacBook Air and wifi at Starbucks
I went to the local Starbucks cafe in Seoul as I usually do. I have connected to the internet many times in the past without any problem at Starbucks. I use the wireless connection. I just find the provider with the strongest connection and I type th
-
Hi, I am working in image processing project ,but currently i want to use tpg ip and vdma ip to write frame data in ddr3 on zedboard,please provide me vivado block design and sdk c application for that
-
DropDown in table, bad performance.
Hi all. We have a webdynpro, with a dropdownbyindex combo, on one column of a table. The combo is filled with accounts numbers and works fine when the accounts are few. But when the items are more (1800 or more), is too slow. It takes like 5 seconds
-
Hi gurus, My requirement is to increase the lenth of field in standard transaction is it possible to increase? If yes please guide me how to do? Thanks in Advance.. Thanks and Regards Siri