0% found this document useful (0 votes)
20 views

Write An SQL Statement Query That Will Center The Strings in Column GL - Code in Test - Accounting Table Ex. 01-2 01-A24

This document contains 6 questions about writing SQL queries: 1. Format account codes in a table with asterisk padding 2. Parse a check number format into year, bank number, and account number variables 3. Summarize salaries by job, department 4. Return the name and salary of the third highest earner in each department 5. Classify account codes as internal or external based on character after hyphen 6. Create a table from the emp structure, add constraints, a sequence, and insert a record

Uploaded by

asd1216
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views

Write An SQL Statement Query That Will Center The Strings in Column GL - Code in Test - Accounting Table Ex. 01-2 01-A24

This document contains 6 questions about writing SQL queries: 1. Format account codes in a table with asterisk padding 2. Parse a check number format into year, bank number, and account number variables 3. Summarize salaries by job, department 4. Return the name and salary of the third highest earner in each department 5. Classify account codes as internal or external based on character after hyphen 6. Create a table from the emp structure, add constraints, a sequence, and insert a record

Uploaded by

asd1216
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

FINAL EXAMINATION SQL

1. Write an sql statement query that will center the


strings in column gl_code in test_accounting table
Ex. ***01-2***
**01-A24**
SELECT GL_CODE, LPAD(RPAD(GL_CODE,LENGTH(GL_CODE) + ( (10LENGTH(GL_CODE))/2 ) ,'*'),10,'*')
FROM TEST_ACCOUNTING

SELECT
REPLACE( LPAD(gl_code, (10-LENGTH(gl_code))/2 +
LENGTH(gl_code),'*'),gl_code)
|| RPAD(gl_code, (10-LENGTH(gl_code))/2 + LENGTH(gl_code),'*')
FROM TEST_ACCOUNTING

2. You are tasked to parse the check number format 1231231-2010


Your query should display 2010 year , 1231 bank_no,
123 acct_no
Note: year ,bank no and acct_no may change in length
use substitution variable
to prompt the user.

3. Create a query that will list the sum of salary per


department and job see sample format
JOB
DEPT 10 DEPT 20 DEPT 30

CLERK

200

300

400

4. Write an sql statement that will return the ename, sal


of third highest earner per department if there are two
employees with the same salary then just include the
employee with higher empno.
5. Write a query that will display INTERNAL if gl_code
column in test_accounting has alphabet character (az) or (A-Z) next to the hyphen symbol - otherwise
display EXTERNAL
Sample: 01-A24 GL_CODE , INTERNAL GL TYPE
01-C24 GL_CODE , INTERNAL GL TYPE
01-1A4 GL_CODE , EXTERNAL GL TYPE
6. Create a table based from emp structure without the
data, name the table emp_yourname
* Alter the table and add foreign key constraint of
deptno column to deptnocolumn of
Dept table
* Alter the table add primary key to empno
* Alter the table add check constraint to job column
that it will only this job
(SALESMAN)
* Create a sequence name it seq_YOUR_NAME

* Alter the table add constraint to comm column that it


will not accept null
* Insert a record to your table use the sequence next
value for empno column
* commit

You might also like