a:5:{s:8:"template";s:7947:" {{ keyword }}
{{ text }}

{{ links }}
";s:4:"text";s:23909:"7/2/2011 [sql] SQL> SELECT translate(tno,’0123456789′,’000000000′) q,REPLACE(translate(tno,’0123456789′,’000000000′),’0′,”) FROM ting; Q REPLACE(TRANSLATE(TNO,’0123456 14 6.9 6 4.56666666 4 3.4 3 GROUP BY clause concept – Group Functions MAX, MIN, SUM, AVG, COUNT – Group function tricky queries Analytical / Aggregate form of Function – ROLLUP, CUBE, RANK, DENSE_RANK, DECODE vs CASE SQL General Functions – Conversion, Numeric, String, Date functions – Query examples ————– 6/11/2011 [/sql], To populate an empty table with dummy varchar2 values, we can use DBMS_RANDOM.STRING. 6 1 a 1a [sql] SQL> SELECT translate(tno,’0123456789′,’000000000′) q,length(REPLACE(translate(tno,’0123456789′,’000000000′),’0′,”)) FROM ting; Q LENGTH(REPLACE(TRANSLATE(TNO,’ So, You still have the opportunity to move ahead in your career in Oracle PL SQL Development. 0 0 I have three years of experience in writing automation scripts in Python and two years of experience in development and optimization of databases. [sql]create table test_marks(subject varchar2(10), 6/14/2011 The final solution by Mr Tom Kytes. 0, [sql]select mod(num,1) from test_decimal; 11 b 3a 2 1 2 2 ———- —- 1 20 20 INSERT INTO to_update VALUES(1,NULL); If you want to fill an empty table with groups of data to work on analytic functions or group by functions, then you can generate “groups” of numbers by manipulating the ROWNUM column using the following query. This is a continuation of that page. [sql] SQL> SELECT substr(tno,1,length(tno)-nvl(length(REPLACE(translate(tno,’0123456789′,’000000000′),’0′,”)),0)) a FROM ting; Step 6. 6/20/2011 Maybe You can help me. SQL QUERY. 31 b 31b There are following SQL queries for Interviews, which are very important. What is Cartesian Product ? 31b What is a one-time-only procedure in pl/sql? View the answer → 17 8.4 8 5.56666666 5 4.15 4 … 6 a [sql] SYSDATE LV S T insert into ting values(’11’); SQL> select num-trunc(num) from test_decimal; NUM-TRUNC(NUM) Otherwise, I think you need dynamic sql. While creating an index, we can specify conditional statements. 00a 1 1.12357 See the output to get a better understanding of the requirement. 100[/sql]. Filtered index is used to Index a portion of rows in a table. SELECT * FROM (SELECT CASE WHEN MOD(LEVEL,4)=1 … 00b 1 2 From a table containing numbers, display only the digits after the decimal point. Now, can you find 3rd, 5th or 6th i.e. insert into ting values(’10b’); Here I am just displaying the two columns we created earlier. 1 The query should select top three games (depending total times_played) and top three user who has … rdRuw ———- 20 as it will not know which value of col4 should be used to update col2. 00 3 WHERE seq IS NOT NULL[/sql], This is generate numbers with interval of 4. 1 You have reached the maximum number of messages for today. 6, 7. 7/5/2011 5:22:14 PM 3 21 6/14/2011 00. Let insert value 1 into the table tbl_samplejoin2 so that this … INSERT INTO test_decimal VALUES(1.00); kcksX 5 CONNECT BY LEVEL <=20 19 9.4 9 6.23333333 6 4.65 4 4 WHERE col4 NOT IN (SELECT col2 FROM to_update WHERE col2 IS NOT NULL) EyoQl[/sql], To know more about generating random numbers and strings, you can check this post 10 b 10b [sql]UPDATE to_update t SET t.col2=(SELECT col4 FROM update_using 3 length(tno) -nvl(length(REPLACE(translate(tno,’0123456789′,’000000000′),’0′,”)),0) as the end index. 15 7.4 7 4.9 4 3.65 3 20 9.9 9 6.56666666 6 4.9 4. 6/29/2011 insert into ting values(’10’); SRAVAN ORACLE APPS HRMS Friday, November 28, 2014. 2 12 31 31 INSERT INTO test_decimal VALUES(1.12357); This query can be used to “fill” an empty table with date datatype column. Privilege can be given as system privilege or user privilege. (I have added rownum here to show the rows with null values.) ———- ———- ———- ———- ———- ———- ———- ———- There is a database limit which only allows at the most 32760 characters to be written at one time. CONNECT BY LEVEL <10, dt 0 3 1.4 1 0.9 0 0.65 0 WHERE col4 NOT IN (SELECT col2 FROM to_update WHERE col2 IS NOT NULL), ORA-01779: cannot modify a column which maps to a non key-preserved table [/sql], “you update a join when you want the data from T1 to overwrite [sql]SELECT * FROM (SELECT CASE WHEN MOD(LEVEL,4)=1 THEN LEVEL END seq FROM dual Design the solution of the required scenario and develop working code. 0 http://oddabout.com/?p=594, 5. 3 tno 5 13 Tricky SQL queries, advanced SQL queries, Interesting SQL queries- 2, Tricky SQL queries, advanced SQL queries, Interesting SQL queries, http://asktom.oracle.com/pls/asktom/f?p=100:11:0, http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:43440209618042, Tricky SQL queries, advanced SQL queries, Interesting SQL queries. 11 Creating a GENERIC GROUP BY Procedure PL/SQL. 10 00b b This is a translated summary from the original article by Alexander Chmyr. 1 [sql]SQL> update(SELECT a.col1,a.col2,b.col3,b.col4 FROM to_update a,update_using b Complex Queries in SQL ( Oracle ) These questions are the most frequently asked in interviews. 3 3 what is in T2 and you join T2 to T1 by T1’s primary key. substr(tno,length(tno)-nvl(length(REPLACE(translate(tno,’0123456789′,’000000000′),’0′,”)),0)+1) b FROM ting; ROWNUM B 3. 00 This will generate multiples of 3.. 1.Generate numbers/sequence using dual with a specific interval. I worked at Nayatel, a leading internet service provider of my country, to automate their processes using Python. 00b 1 10 10 COMMIT;[/sql], The table contains : ... (SQL Server Query) SELECT SYSDATE FROM DUAL à This Oracle query returns the current date and time 19. —- —- 1a 2 1 10a 3 1 Next we find the length of the values which are not null(with alphabets). insert into ting values(‘3a’); 1.Generate numbers/sequence using dual with a specific interval. Find the total length (length(tno))of the string and using NVL replace the null values in the above query with 0. Another excellent solution from Mr. Tom Kytes. [sql]INSERT INTO test_marks(subject,marks1,marks2,marks3) To make this query work, create a primary key on update_using : 0a 4. 1) If two or more tables are joining without join condition will result into … The query given below will not work. 2 a 2a 5 This is how I understood the final query. 1 For some reason[must be a broken tag/code], I cannot put more text into the original page Tricky SQL queries, advanced SQL queries, Interesting SQL queries. [sql]SELECT * FROM (SELECT CASE WHEN MOD(LEVEL,4)=1 THEN LEVEL END seq FROM dual CONNECT BY… insert into ting values(‘1a’); According to research, Oracle PL SQL has a market share of about 2.2%. Oracle SQL Architecture Questions SQL Tricky Queries SQL Advanced Topic Questions Questions from past 30+ Interviews Instructor is a Oracle Certified Professional (OCP) Instructor has Points: 12,975 Level: Master in Oracle Technology Network (OTN) In this query, we need to update col2 in to_update table with the value in col4 of update_using table. To ensure the best results, the professional has outlined what you need to provide before they can start the project. 3 1 0 This gives the first column in the final query (A). 2 WHERE a.col1 =b.col3 ) 10b marks1 number, marks2 number, marks3 number, total number)[/sql], On insert, the trigger should automatically calculate the sum of marks1, marks2 and marks3 and assign it to total column: [sql]CREATE OR REPLACE TRIGGER find_total ... oracle sql practice exercises with solutions Prashant Surya | Dec 11, 2019 | Views: 873. sql queries for practice with answers free download 0 10 a 0 CONNECT BY LEVEL <=100) Answer: Oracle is one of the popular databases … Introduction Let's write some Sql Server Queries to get the results from a table in a database. 16 7.9 7 5.23333333 5 3.9 3 The next solution uses the concept of “update join” which introduces us to the concept of “key preserved table”. 3 The list should be ordered by billing date. Using Filter Index. Highlights include: ( Log Out /  Considering the database schema displayed in the SQLServer-style diagram below, write a SQL query to return a list of all the invoices. Answer : How will you insert multiple rows of dummy data into a date column or a varchar2 column? 1 1 You will get tricky and advanced SQL queries for Oracle, SQL Server, MySql and Postgres Ibrahim P. 4.9 (154 reviews) Share Select service tier. 16 The next question is on triggers. 0 What is Oracle and what are its different editions? This project will provide you each and everything related to databases. 2a The below SQL Query will create a Unique Index on the rows having non null values: Change ), You are commenting using your Twitter account. What is Database? —————————— In Oracle SQL, there are two ways to join tables. 00 Oracle SQL Developer provides a SQL Worksheet that you can use to query data, by writing simple or complex SQL statements. WHERE col2 IS NULL[/sql]. Here 2 has two corresponding values 12 and 13. For returning ALL when only location matches, try following query. 5 ; update(SELECT a.col1,a.col2,b.col3,b.col4 FROM to_update a,update_using b Change ). 31 31. ddhmo 6. http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:4725668677832 0a a 00b If a number is 1.980 then the output should be 0.980, [sql]CREATE TABLE test_decimal(num NUMBER); INSERT INTO to_update VALUES(2,NULL); Another one from asktom . insert into ting values(’10a’); —- —- —- INSERT INTO to_update VALUES(4,11); 20 2 0 —- —————————— trunc(SYSDATE-(7*(LEVEL-1))) t FROM dual Advanced SQL | Fill the Price for missing months. What is VArray? 5 ORDER BY to_number(a),b NULLS FIRST 20.099 4 FROM dual To generate multiples of a number using dual in ORACLE. 1 0.4 0 0.23333333 0 0.15 0 tricky sql queries for interview sql query questions and answers for practices, SQL Tutorial, SQL Interview Questions, SQL Tips and Tricks. 1 a 1a And looked into strategies you can use to get better plans for these queries. 1 0a CONNECT BY LEVEL <=100) 7 3.4 3 2.23333333 2 1.65 1 (SELECT col2 FROM to_update WHERE col2 IS NOT NULL)) 0a 1 If the value in col4 is already present in col2, then col2 should not be updated. 10 2 0 0 [sql]INSERT INTO update_using VALUES(2,13);[/sql] [sql]SQL> update(SELECT a.col1,a.col2,b.col3,b.col4 FROM to_update a,update_using b 7/5/2011 5:22:14 PM 4 28 6/7/2011 6 ; [/sql]. 1 1 0 00a a ... REGEXP_REPLACE function & SQL Query to remove Non-Numeric characters from a String. The final solution is provided at the end. 12 5.9 5 3.9 3 2.9 2 select num-cast(num as integer) from test_decimal;[/sql]. 11 To fetch ALTERNATE records from a table. 6/17/2011 Sql Tricky Queries select parent_id who have at least one boy and one girl ... having count (distinct child_gender) = 2. After we showed you 10 main questions asked to a candidate on JavaScript interviews, we found an interesting material with SQL tricky questions. Change ), You are commenting using your Google account. 9 4 FROM ting 20 This really hits at the core of this article. http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:43440209618042 2 2 Join columns having duplicate values. insert into ting values(‘2’); Using the escape character (to search for strings containing like ‘ABC %%TRF’, ‘TR%FF’ or ‘%GH’) Generate numbers/sequence using dual with a specific interval. The following steps are a breakdown of the final solution. Similar to above query. Explain Scalar functions. In this How-To, we look at the most basic of these, select all the data in a table, and restricting this query by reducing the columns or rows you retrieve. [sql] SQL> SELECT tno,length(tno),nvl(length(REPLACE(translate(tno,’0123456789′,’000000000′),’0′,”)),0) FROM ting; TNO LENGTH(TNO) NVL(LENGTH(REPLACE(TRANSLATE(T Edited by: Frank Kulash on Dec 18, 2008 8:17 PM To be more precise: column names and aliases must be hard-coded into the query. WHERE a.col1 =b.col3 ) 4 11 3 3 0 1. 3 SET col2 =col4 In ORACLE, you can use the ESCAPE keyword to search for strings containing ‘%’. Finding output of SQL Queries, Tricky SQL Queries. …. N'th highest Salary? ” For some reason[must be a broken tag/code], I cannot put more text into the original page Tricky SQL queries, advanced SQL queries, Interesting SQL queries. The trigger should calculate the total and update the total when we insert marks1, marks2 and marks3. ( Log Out /  INSERT INTO to_update VALUES(5,NULL); A database is an organized collection of data, stored and retrieved digitally from … 1 Change ), You are commenting using your Facebook account. This is a continuation of that page. 3 SET col2 =col4 10 a 10a 2a 2 1 1.2345 10 b 10b 12 b 0.2345 3 a 3a Although some Oracle tools and applications mask SQL use, all database operations are performed using SQL. 13 4 FROM ting; A B TNO Trying to build this query for about hour. 13. :new.total := :new.marks1+:new.marks2+:new.marks3; 10 4.9 4 3.23333333 3 2.4 2 [sql] SQL> SELECT ROWNUM r, ROWNUM/2-0.1 a, trunc(ROWNUM/2-0.1) two, INSERT INTO test_decimal VALUES(1.2345); 11 11 7/5/2011 5:22:14 PM 6 42 5/24/2011 INSERT INTO test_decimal VALUES(20.0990); insert into ting values(‘2a’); 0.12357 WHERE t.col1=col3 AND col4 NOT IN trigger to update the value of total as sum of marks1, marks2, marks3 What is the simplest SQL Query to find the second largest value? 31 2 0, Step 5. 9 a 1 1 4 ADD CONSTRAINT up_us_pk PRIMARY KEY(col3)[/sql]. 13 rows selected I am writing some queries which were asked of me during my interview -- the questions asked in each interview are different but I understand they are related to each other. insert into ting values(‘3′); Analyze the current scenario and problems to identify the functional and non functional requirements. 00. This is the second row in the final query (B). 5 Instead of first day this query returns last day of … ——— 10 a 10a 4 WHERE col4 NOT IN (SELECT col2 FROM to_update WHERE col2 IS NOT NULL); COL1 COL2 INSERT INTO to_update VALUES(3,NULL); 9 4.4 4 2.9 2 2.15 2 [sql] SQL> SELECT translate(tno,’0123456789′,’000000000′) FROM ting; TRANSLATE(TNO,’0123456789′,’00 Search for columns containing ‘%’ in Oracle. I will try to explain the query in steps so that user will get idea of its execution. BEFORE INSERT ON test_marks FOR EACH ROW 3. http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:786026162431 The output [see the columns marked TWO THREE and FOUR]: [sql] R A TWO B THREE C FOUR 2 substr(tno,length(tno)-nvl(length(replace(translate(tno,’0123456789′,’0000000000′),’0′,”)),0) +1 ) b, 6/26/2011 zodaY Really tricky SQL statement I have here. Answer: CONNECT BY LEVEL <=20[/sql]. [sql]SELECT LEVEL*3 FROM dual Introduction to SQL. 4 1.9 1 1.23333333 1 0.9 0 ——— 5 2.4 2 1.56666666 1 1.15 1 INSERT INTO update_using VALUES(5,13); Change this sentence and title from admin Theme option page. 3 00 These SQL queries for Interviews are important for fresher’s as well as the experienced professionals, which have good experience. Use ANSI Joins Instead of Oracle Joins. For each invoice, show the Invoice ID, the billing date, the customer’s name, and the name of the customer who referred that customer (if any). 00b Use substr to display only the alphabets. I also have experience in writing complex queries in optimized way. Query for 3rd highest salary. You can skip the following sections and directly go for the final solution. insert into ting values(‘1’); Gives 1. Step 4. WHERE seq IS NOT NULL[/sql], This is generate numbers with interval of 5. 11 2 0 —- ( Log Out /  VALUES (‘A1’,12,13,14);[/sql]. 11 5.4 5 3.56666666 3 2.65 2 In this case since 11 is already present in to_update table, it should not be updated for 1 in to_update table. Replace all the digit with 0 using translate. Step 7. 6 ; A B TNO 0 Complete testing / QA of the developed solution and deliver the working solution. [sql] SQL> SELECT rownum, 31 b 31b. [sql]SELECT sysdate,level-1 lv,7*(LEVEL-1) s, 2 WHERE a.col1 =b.col3 ) INSERT INTO update_using VALUES(2,12); You might … Tricky SQL Query Hi Tom,I have scenario like , For example I have table with a Column of values 1,2,3,4,5 but i need the output like 2,3,4,5,1, for this i found one solution but i hope this is not the generic one, could you please help me.., Below i have explained scenario with the exampleCREATE TABLE TE 0a INSERT INTO update_using VALUES(1,11); 0a a Fill in your details below or click an icon to log in: You are commenting using your WordPress.com account. 10a Database creation and data population script (if available), Access to the environment having one premises installed database (in case there are some limitations to share the db script). 8 a 6 2.9 2 1.9 1 1.4 1 11 11 2. “, [sql]create table ting(tno varchar2(4)); [sql]SQL> select trunc(num) from test_decimal; TRUNC(NUM) COMMIT;[/sql], First solution using correlated subquery : —- —- —- A privilege is nothing but right to execute an SQL query or to access another user object. [sql] SQL> SELECT substr(tno,1, length(tno)-nvl(length(replace(translate(tno,’0123456789′,’0000000000′),’0′,”)),0)) a, A rough overview the professional has created to outline how the project would progress. EUvWO Add 1 to the end_index in the above query and take it as the start index. 9 Tricky SQL queries advanced SQL queries, Interesting SQL queries 2 1 . 2 insert into ting values(’31b’); Try running the query without using NULLS FIRST and you will know the reason it has been kept there. [sql] SQL> SELECT substr(tno,1, length(tno)-nvl(length(replace(translate(tno,’0123456789′,’0000000000′),’0′,”)),0)) a, [sql]SELECT trunc(SYSDATE-(3*(LEVEL-1))) dt FROM dual For this to work, we need to have a primary key on the table from which we are updating(update_using). How do you go about tuning your PL/SQL code? 100. There are 4 columns in a table, marks1, marks2,marks3 and total. “We expect to see the order of the values as 1,1a,2,2a,3,3a…. A very close friend given this to me. [sql]NUM BEGIN 8 3.9 3 2.56666666 2 1.9 1 31b 3 1 brQiw INSERT INTO to_update VALUES(6,NULL); 7/5/2011 5:22:14 PM 1 7 6/28/2011 00 1 We have a table with 3 columns: gamename | user | times_played. Oracle tricky queries How to write a CLOB with a length > 40K out to a file? 7/5/2011 5:22:14 PM 8 56 5/10/2011 [/sql], Another example to get dates with an interval of 3 days. 3 ROWNUM/4-0.1 c, trunc(ROWNUM/4-0.1) four Get the last day of the year. 00 To create the table: 3 a 3a 6/23/2011 INSERT INTO test_decimal VALUES(100); CREATE TABLE update_using(col3 NUMBER,col4 NUMBER); 7 insert into ting values(’31’);[/sql], TNO CONNECT BY LEVEL < 10;[/sql], This query uses the LEVEL pseudo-column to get dates with an interval of 7 days. 7/5/2011 5:22:14 PM 5 35 5/31/2011 2 substr(tno,length(tno)-nvl(length(replace(translate(tno,’0123456789′,’0000000000′),’0′,”)),0) +1 ) b, 2 0.9 0 0.56666666 0 0.4 0 18 8.9 8 5.9 5 4.4 4 00a 7/5/2011 5:22:14 PM 2 14 6/21/2011 [sql]select DBMS_RANDOM.STRING(‘A’,5) ran from dual connect by level< 10; ran END;[/sql]; Note: AFTER INSERT will not work in this case. 1 2 ROWNUM/3-0.1 b, trunc(ROWNUM/3-0.1) three, 31. Use substr to extract only the digits from tno using 1 as start index and the difference between …, [sql]SELECT * FROM (SELECT CASE WHEN MOD(LEVEL,5)=1 THEN LEVEL END seq FROM dual 0a 1 7/5/2011 5:22:14 PM 7 49 5/17/2011 00, Step 3. Step 1. 20 20 Otherwise it would be considered as a META CHARACTER. 12 3 tno Step 8. SEQ 0.099 00b b ( Log Out /  But the above query will fail if you add another row : Write an SQL query to find the position of the alphabet (‘a’) in the first name column ‘Amitabh’ from … (EVEN NUMBERED) select * from emp where rowid in (select decode(mod(rownum,2),0,rowid, null) from emp); To select ALTERNATE records … I will not get into the details. ….. ****************************************************. Mindmajix offers Advanced Oracle PL SQL Interview Questions 2021 that help you in cracking your interview & acquire a dream career as an Oracle PL SQL Developer. [/sql] Only works on SQL Server 2008 and above. select m.item, m.location, (CASE WHEN m.card like t.card THEN m.card ELSE 'All' END) as card from mst_item as m, time_factor as t WHERE m.location like t.location ORACLE QUERY 7/5/2011 SQL Tricky Questions TheDataMonk Master March 25, 2019 Uncategorized 2 Comments 812 views. 2 1 0 6 SQL (pronounced sequel) is the set-based, high-level declarative computer language with which all programs and users access data in an Oracle database. Column A in step 5 and column B in step 6 along with the original column tno. In this session we discussed why this is a hard problem. [sql]GRANT user1 TO user2 WITH MANAGER OPTION;[/sql] 24. 00 [sql]ALTER TABLE update_using 00 1a Hi, In SQL*Plus, you can do a preliminary query to get the '2008' into a substitution variable (using COLUMN ... NEW_VALUE), then use that substitutiuon variable as a column alias in your main query. WAcca 7/5/2011 5:22:14 PM 0 0 7/5/2011 SET col2 =col4 2 a 2a 10b 3 1 13 6.4 6 4.23333333 4 3.15 3 00 Tuning SQL queries with date ranges, such as: and start_date between to_date ( :st_dt, 'YYYY-MM-DD' ) and to_date ( :en_dt, 'YYYY-MM-DD' ) Is tricky. baktb 3a 0a a —- —————————— insert into ting values(’20’); Answer. ";s:7:"keyword";s:28:"tricky sql queries in oracle";s:5:"links";s:1128:"Waver Mini Vibration Plate, How To Place The Ice Keystone In Prodigy, Doritos Nacho Cheese Dip Morrisons, Xsh Cam Doorbell Not Sending Notifications, Bride Of The Far Side, Jiren's Theme Epic, Castor Oil Walgreens For Eyelashes, Ge Profile™ 30" Built-in Touch Control Electric Cooktop, Waver Mini Vibration Plate, ";s:7:"expired";i:-1;}