How to convert this SQL PL/SQL query
Basically, I need to create an anonymous block that will display the name of each student, family name and the number of students who scored less than test 1 that the student.So basically you need to find the number of students scoring less than this particular student and we do it for all students of the table.
So, for this particular query, I designed my code in SQL
Select g1.gr_fname, g1.gr_lname, count (*)
grade g1, g2 grade
where g1.gr_t1 > g2.gr_t1 and
G1.std_code = g2.std_code
G1.gr_fname group, g1.gr_lname;
But I am unable to get the logic of how to run it in PL/SQL, something missing a minor detail to run the same in PL/SQL
could someone help me please with the logic.
Thank you
You can write it in pl/sql like this
begin
for i in (
select g1.gr_fname, g1.gr_lname, count(*) cnt
from grade g1,
grade g2
where g1.gr_t1 > g2.gr_t1
and g1.std_code = g2.std_code
group by g1.gr_fname, g1.gr_lname;
)
loop
-- I have just wirtern the output into the buffer. You can do what ever you want here.
dbms_output.put_line(i.gr_fname||'/'||i.gr_lname||'/'||i.cnt);
end loop;
end;
Tags: Database
Similar Questions
-
Question to convert oracle sql query
Hi friends,
I have a sql query, as follows,
I want to convert this to oracle. I tried to convert this in someways. But I get errors only. Please someone help me solve this problem.Select Name From SysObjects Where XType = 'U' And Name = @Name
Thank you
RAMViews of the Oracle dictionary more come in DBA_, ALL_ USER_ flavors. You probably don't have privileges to view DBA_OBJECTS, in which case try object or USER_OBJECTS.
Of after what I read, you may need something like
SELECT * FROM all_objects WHERE owner <> 'SYS' AND object_type = 'TABLE'
BTW, a sure way to liquidate Oracle professionals is to use "SQL" to designate another DBMS product, not Structured Query Language. As you may have noticed, we have SQL here as well.
-
How to find the sql query generated by BI Publisher
I'm looking for the physical sql query generated by BEEP when I send parameters as part of the data model.
Of course, this can be noted in newspapers...
Can anyone tell me the location of newspapers?
Thanks in advanceHave a look here http://gerardnico.com/wiki/dat/bip/log
I explain a bit how you can get the newspaper.See you soon
Nico -
How to build a SQL query to print ranges of week of a month
Hi gurus!
I have a requirement to create a query to display the times of week of a month.
The entries will be Year and month.
The result should be something like this:
If the year = 2009 and month = June
The SQL query should return the following:
June 1, 2009-June 6, 2009
June 7, 2009 to June 13, 2009
June 14, 2009-June 20, 2009
June 21, 2009-June 27, 2009
June 27, 2009 to June 30, 2009
I'm confused how to proceed. Please help me. Any help would be appreciated grately.
Thank you
AhmedHello
This might help (the exit is not exactly the same):
Connected to Oracle Database 10g Express Edition Release 10.2.0.1.0 Connected as hr SQL> SQL> SELECT TRUNC(to_date('01-Jun-2009'), 2 'D') + 7 * (LEVEL - 1) AS START_DATE, 3 TRUNC(to_date('01-Jun-2009'), 4 'D') + 7 * (LEVEL - 1) + 6 AS END_DATE 5 FROM dual 6 CONNECT BY LEVEL <= 4; START_DATE END_DATE ----------- ----------- 31/05/2009 06/06/2009 07/06/2009 13/06/2009 14/06/2009 20/06/2009 21/06/2009 27/06/2009 SQL>
Kind regards
-
How to convert a SQL with variable
Can Hello, please how I convert the underside with a dominant
I need to be able to generate a plan to explain it, I think I should use cast.
SELECT TO_NUMBER (OIL. REBALANCE_ORDER_ID UNIQUE_ID),
OIL. ORDER_QTY,
OIL. ORDER_TYPE,
OIL. ORDER_SIDE,
OIL. POSITION_TYPE,
OIL. AVAILABLE_QTY AVAILABLE_QUANTITY,
OIL. GROSS_AMOUNT ORDER_AMT,
OIL.NET_AMOUNT NET_AMOUNT,
OIL. FEE_AMT FEE_AMOUNT,
OIL. ACCRUED_INTEREST_AMT ACCRUED_INTEREST
TABLE (: B6) OIL>
I need to be able to generate a plan to explain it, I think I should use cast.SELECT TO_NUMBER (OIL. REBALANCE_ORDER_ID UNIQUE_ID),
OIL. ORDER_QTY,
OIL. ORDER_TYPE,
OIL. ORDER_SIDE,
OIL. POSITION_TYPE,
OIL. AVAILABLE_QTY AVAILABLE_QUANTITY,
OIL. GROSS_AMOUNT ORDER_AMT,
OIL.NET_AMOUNT NET_AMOUNT,
OIL. FEE_AMT FEE_AMOUNT,
OIL. ACCRUED_INTEREST_AMT ACCRUED_INTEREST
TABLE (: B6) OIL
>
You're right - mount the bind as the appropriate type. I have a SQL type named emp_table_type so that it worksexplain plan for select * from table(cast (:e1 as emp_table_type))
The models involved are
CREATE OR REPLACE TYPE SCOTT.emp_scalar_type as object (EMPNO NUMBER(4) , ENAME VARCHAR2(10), JOB VARCHAR2(9), MGR NUMBER(4), HIREDATE DATE, SAL NUMBER(7, 2), COMM NUMBER(7, 2), DEPTNO NUMBER(2) ) / CREATE OR REPLACE TYPE SCOTT.emp_table_type as table of emp_scalar_type /
-
Please help me with this SQL query
I'm practicing of SQL queries and met one involving the extraction of data from 3 different tables.
The three paintings are as below
< pre >
Country
Location_id country
LOC1 Spain
loc2 England
LOC3 Spain
loc4 USA
loc5 Italy
loc6 USA
loc7 USA
< / pre >
< pre >
User
user_id location_id
loc1 U1
loc1 U2
loc2 U3
loc2 U4
loc1 U5
U6 loc3
< / pre >
< pre >
Publish
user_id post_id
P1 u1
P2 u1
U2 P3
P4 u3
P5 u1
P6 u2
< / pre >
I am trying to write a SQL query - for each country of the users, showing the average number of positions
I understand the logic behind all this that we must first consolidate all locations, and then the users in one country and then find the way to their positions.
But, I'm having a difficulty to this format SQL. Could someone help me please with this request.
Thank you.Select
Country.Country,
Count (*) Totalpostspercountry,
Count (distinct post.user_id) Totaldistincuserspercountry,
count (*) / count (distinct post.user_id) Avgpostsperuserbycountry
Of
countries, have, post
where country.location_id = muser.location_id
and muser.user_id = post.user_id
Country.country groupThe output is like this for your sample data - hope that's what you're looking for :)
COUNTRY, TOTALPOSTSPERCOUNTRY, TOTALDISTINCUSERSPERCOUNTRY, AVGPOSTSPERUSERBYCOUNTRY
In England, 1, 1, 1.
Spain, 5, 2, 2.5. -
How to convert this code random AS2 AS3 pos?
Hello! I do a sort of screen saver and have random logo on the screen. In ActionScript 2, it's easy, simply paste a code for the object, and it works. Things to do it is total different in ActionScript 3 and I can not understand how to solve this problem. Would be nice if someone could take a look at my very simple example and point me in the right direction. Maybe there are some example out there done in AS3?
I can't understand how post fla so I renamed it to jpg. Just change the extension to the fla again format...
Best regards / Jimmy
Hello
I was not able to see the FichierVous have attached.
However, I enclose you a zip that will give you the idea of how we can position any logo randomly on the stage.
Check and let me know if that helps...
P.S.: Zip and attach files whenever necessary
-
How to convert this BSO formulas formulas ASO?
I need help to convert this BSO formulas formulas ASO:
BSO formulas:
12 * ("head count"-> "stopped" / ((@PRIOR("Head Count"-> "Total Active & Leave") + "number of head"-> "Total assets & leave ') / 2));
'Number of head' is a member of the dimension account
'Complete' and ' Total assets & leave "are members of the dimension of the State
Existing Active
New rental
Assets
CARPET
STD
OTH
Leave
Holidays & total assets
Volunteer
Involuntary
Death
Retirement
End of temporary assignment
Terminated
LTD
Total status
Promotion within level
Promotion to the next level
Promotion
No Total status
All Status
Status (Dimension)
ASO, the formulas will be?
Thank youTry
CASE WHEN IS([Period].CurrentMember, [Jan]) THEN 12 * (([Head Count], [Terminated] ) / ((( [Head Count], [Total Active & Leave], [Dec], [Year].CurrentMember.lag(1) ) + ([Head Count], [Total Active & Leave])) / 2)) ELSE 12 * (([Head Count], [Terminated] ) / ((( [Head Count], [Total Active & Leave], [Time].CurrentMember.lag(1) ) + ([Head Count], [Total Active & Leave])) / 2)) END
Note that this implies that your dimension of the year is in descending order
Year
-2007
-2008
-2009If the year is in ascending order
Year
-2009
-2008
-2007Then, you need to change
[Year].CurrentMember.lag(1)
TO
[Year].CurrentMember.lead(1)
-
How do I get this sql query?
Hi all
I'm using oracle 11g.
I have a table as below:
[code] create table id_test)
Identification number, name varchar2 (20)
) ;
[/ code]
And records like below:
[code]
ID NAME
1 sr
1 ds
2 sr
DS 2
3 sr
[/ code]
where I want to select only the id that have only the name as "sr."
But as I have 100 names cannot put a not in condition to check other names.
The expected result would be like:
[code]
ID NAME
3 sr
[/ code]
Concerning
Dale
Do you want to max (id) name = "SR"... Try the below
SELECT id,
name
GO (select id,
name,
ROW_NUMBER() over (ORDER BY id desc) rn
of id_test
WHERE name = 'sr')
WHERE rn = 1
OR
SELECT MAX id (id),
name
Of id_test
WHERE name = 'sr '.
GROUP BY name.
OR if you want to get the id which is only in SR, then try it out below
SELECT id,
name
Id_test A1
WHERE name = 'sr '.
AND NOT EXISTS (SELECT 1 from id_test a2
WHERE a1.id = a2.id
AND name! = « sr ») ;
Post edited by: 000000
-
Need help to convert a sql query to a stored procedure
I have a task to convert a script sql in a stored precedure. The sql with different pr_id test_type are below. And the stored procedure must accept a pr_id and a test_type as an argument. Test type will be 3 for ATI and 2 for TI. It must return a single value, the greatest distance calculated to fill the value of tap. It is possible that they will pass a prid, test_type combination that will have all the records in the dsltdr table.
{
SELECT pw,
Round ((DECODE (t.rfltype1, 5, t.rfldist1,)))
DECODE (t.rfltype2, 5, t.rfldist2,)
DECODE (t.rfltype3, 5, t.rfldist3,)
DECODE (t.rfltype4, 5, t.rfldist4,)
DECODE (t.rfltype5, 5, t.rfldist5,)
DECODE (t.rfltype6, 5, t.rfldist6,)
DECODE (t.rfltype7, 5, t.rfldist7,)
DECODE (t.rfltype8, 5, t.rfldist8,)
NULL)))
(- launch_start) * distk * vop, 2) dist
OF dsltdr t
WHERE pr_id = 464529581
AND test_type = 3
ORDER BY pw CSA;
}
SELECT pw,
Round ((DECODE (t.rfltype1, 5, t.rfldist1,)))
DECODE (t.rfltype2, 5, t.rfldist2,)
DECODE (t.rfltype3, 5, t.rfldist3,)
DECODE (t.rfltype4, 5, t.rfldist4,)
DECODE (t.rfltype5, 5, t.rfldist5,)
DECODE (t.rfltype6, 5, t.rfldist6,)
DECODE (t.rfltype7, 5, t.rfldist7,)
DECODE (t.rfltype8, 5, t.rfldist8,)
NULL)))
(- launch_start) * distk * vop, 2) dist
OF dsltdr t
WHERE pr_id = 464528353
AND test_type = 3
ORDER BY pw CSA;
SELECT pw,
Round ((DECODE (t.rfltype1, 5, t.rfldist1,)))
DECODE (t.rfltype2, 5, t.rfldist2,)
DECODE (t.rfltype3, 5, t.rfldist3,)
DECODE (t.rfltype4, 5, t.rfldist4,)
DECODE (t.rfltype5, 5, t.rfldist5,)
DECODE (t.rfltype6, 5, t.rfldist6,)
DECODE (t.rfltype7, 5, t.rfldist7,)
DECODE (t.rfltype8, 5, t.rfldist8,)
NULL)))
(- launch_start) * distk * vop, 2) dist
OF dsltdr t
WHERE pr_id = 464527142
AND test_type = 2
ORDER BY pw CSA;
SELECT pw,
Round ((DECODE (t.rfltype1, 5, t.rfldist1,)))
DECODE (t.rfltype2, 5, t.rfldist2,)
DECODE (t.rfltype3, 5, t.rfldist3,)
DECODE (t.rfltype4, 5, t.rfldist4,)
DECODE (t.rfltype5, 5, t.rfldist5,)
DECODE (t.rfltype6, 5, t.rfldist6,)
DECODE (t.rfltype7, 5, t.rfldist7,)
DECODE (t.rfltype8, 5, t.rfldist8,)
NULL)))
(- launch_start) * distk * vop, 2) dist
OF dsltdr t
WHERE pr_id = 464528984
AND test_type = 2
ORDER BY pw CSA;
>
SELECT pw,
Round ((DECODE (t.rfltype1, 5, t.rfldist1,)))
DECODE (t.rfltype2, 5, t.rfldist2,)
DECODE (t.rfltype3, 5, t.rfldist3,)
DECODE (t.rfltype4, 5, t.rfldist4,)
DECODE (t.rfltype5, 5, t.rfldist5,)
DECODE (t.rfltype6, 5, t.rfldist6,)
DECODE (t.rfltype7, 5, t.rfldist7,)
DECODE (t.rfltype8, 5, t.rfldist8,)
NULL)))
(- launch_start) * distk * vop, 2) dist
OF dsltdr t
WHERE pr_id = 464529918
AND test_type = 2
ORDER BY pw CSA;
How to start with?
Thanks in advance.I removed the dbms_output statement because it does not seem to turn it on. If you do this from sqlplus
Make sure that you type "serverout on" and press return.declare vPW number := 0 ; vDistance number := 0 ; begin sp_dsl_test(3,'12345',vDistance,vPW) ; DBMS_OUTPUT.PUT_LINE('Distance = '|| vDistance || ' PW = '|| vPW); end;
Published by: FlyingGuy on March 3, 2011 14:24
-
How to get the sql query result?
Hello
Currently I use LV2012 to connect to an Oracle database server. After the Oracle Express and Oracle ODBC driver facilities/settings made.
I managed to use the SQL command to query the data through my command prompt window.
Now the problem is, how to do the same task in Labview using database connectivity tools?
I have build a VI to query as being attached, but I have no idea of what range to use to get the result of the query.
Please help me ~ ~
Here is a piece of code that I use to test the SQL commands, you can use the part that retrieves the results of sql.
It is also possible to get the rear column headers, but it's for the next lesson!
;-)
-
How to get the SQL query running of af: search?
I use JDeveloper 11.1.2.3.0. I have a page where I've set up an af:query and an array of result. The problem is that I can't get the exact query that is used during the execution of this component in a managed bean method. Is it possible to get the query string that is run within the af: query?
Thank you
Hello
Method of the ViewObject getQuery() returns what you need;
You can replace the executeQueryForCollection(), and prior to calling super, you can print the result of getQuery() method:
public void executeQueryForCollection (rowset Object,
Object [] params,
{int noUserParams)
System.out.println ("SQL =" + getQuery());
call the super method here...
}
-
How to convert MS SQL Server 2008 Stored Procedures of Oracle 11 g SPs?
We have an application from MS SQL Server 2008. We want to migrate to Oracle 11 g.
What is the recommended Oracle method for
(1) migration of data (Tables, triggers, sequences, views etc..)
(2) the stored Procedure migration.
What is the recommended tool or method pls?
We have 100s of MS Sql Server stored procedures. Then, needing a tool or method. We can rewrite all of them from scratch.Hello
Let me clarify some of the issues that you mention. But I advise you to get some professional help with migration because:
1. you must understand the architectural differences between SQL Server and Oracle. They are of different databases.
2. understand data type mappings.
3. understand the complete migration process. Just using the OTN article as a migration guide won't help because it just shows how use SQL Developer to this task.
4. understand that 100% of successful Oracle conversion is not possible with all the tools. There will always be gaps, gaps in functionality, bugs etc. So there will be some amount of manual work involved.
5. There are many other tasks involved in the migration that cannot be accomplished with SQL Developer.Get now your questions:
1. in 3.1, there is migration option for the "capture of database in offline mode". It is under the Tools option. So in 3.1 we do not have a separate tab, called "Migration."
2. use 3.1 because it is much better than 2.1 in terms of capabilities.
3 migration Wizard is the easiest way to migrate. Where are you getting confused?
4 "column data" seems to be a stored procedure in SQL Server. If it is not there in the underlying table, why he uses in the SQL statement in the procedure then? I think that we have a problem of "reserved word" with the name of column "Data". Will have to check that.
5 VARCHAR (@max) must be mapped to VARCHAR2 (4000) in Oracle. It may be a bug in SQL Developer. So during the mapping of data type in the migration wizard, you can change the default mappings.Concerning
Prakash
-
four months back someone updated my table of billing through sql developer.
How can I find the details of the request or the original data.
now the problem is that we rebooted the server, if it's not rest with time stamp.
log mode is Archieve record only.
Please help meI don't know why you're getting this error, I tried and it works:
SQL> exec dbms_logmnr.add_logfile( logfilename=> 'C:\oracle\product\11.2.0\dbhome_1\RDBMS\ARC0000000736_0765299251.0001', options=> dbms_logmnr.new); PL/SQL procedure successfully completed. SQL> EXECUTE DBMS_LOGMNR.START_LOGMNR(OPTIONS => DBMS_LOGMNR.DICT_FROM_ONLINE_CATALOG); PL/SQL procedure successfully completed. SQL> exec dbms_logmnr.start_logmnr PL/SQL procedure successfully completed. SQL> select seg_owner,seg_name,sql_redo,sql_undo from v$logmnr_contents; ..... 35 rows selected. SQL> exec dbms_logmnr.end_logmnr PL/SQL procedure successfully completed.
@Boris - you don't have to have an additional connection to the database. The thing is that if you don't have additional logging, Oracle will give you only the ROWID of the records and if it is not the same database or something has changed (as "alter table... move"), ROWID is not relevant. If you enable additional logging, you will get more information on the line (like the other columns or PK) which will help you a lot to identify RELEVANT changes. As I said, it is not mandatory, but as you say, if you want extra logging, it must be turned on BEFORE the changes in the database.
Hope that's clear,
Liron -
Hello
I already set date value as below.
SET THE VALUE OF START_TIME = 2011-08-12 09:00
and executes the table based on the defined date as below,
DEFINE END_TIME = 2011-08-12 10:00
Select * from my_table
) but now I want to query the table based on the time,
where
(to_date (Accounting_Start_Time,'yyyy-mm-dd HH24:MI:SS) > = to_date ('& start_time ',' yyyy-mm-dd HH24:MI:SS) and to_date (Accounting_Stop_Time,'yyyy-mm-dd HH24:MI:SS) < = to_date ('& end_time ',' yyyy-mm-dd HH24:MI:SS))
GOLD to_date (Accounting_Start_Time,'yyyy-mm-dd HH24:MI:SS) > = to_date ('& start_time ',' yyyy-mm-dd HH24:MI:SS) and to_date (Accounting_Stop_Time,'yyyy-mm-dd HH24:MI:SS) > = to_date ('& end_time ',' yyyy-mm-dd HH24:MI:SS) and to_date (Accounting_Start_Time,'yyyy-mm-dd HH24:MI:SS) < = to_date ('& end_time ',' yyyy-mm-dd HH24:MI:SS)
GOLD to_date (Accounting_Start_Time,'yyyy-mm-dd HH24:MI:SS) < = to_date ('& start_time ',' yyyy-mm-dd HH24:MI:SS) and to_date (Accounting_Stop_Time,'yyyy-mm-dd HH24:MI:SS) < = to_date ('& end_time ',' yyyy-mm-dd HH24:MI:SS) and to_date (Accounting_Stop_Time,'yyyy-mm-dd HH24:MI:SS) > = to_date ('& start_time ',' yyyy-mm-dd HH24:MI:SS)
GOLD to_date (Accounting_Start_Time,'yyyy-mm-dd HH24:MI:SS) < = to_date ('& start_time ',' yyyy-mm-dd HH24:MI:SS) and to_date (Accounting_Stop_Time,'yyyy-mm-dd HH24:MI:SS) > = to_date ('& end_time ',' yyyy-mm-dd HH24:MI:SS));
Any help please,.Hello
It is not very hard in SQL * more.
First of all, put your query in a script file, like this one, called hour_query.sql:
-- hour_query.sql Show data from my_table for a given time period PROMPT The data below shows the period from &1 to &2 PROMPT SELECT * FROM my_table WHERE accounting_start_time <= '&2' AND '&1' <= accounting_stop_time ;
Parameters & 1 and & 2 are beginning and end of time, for example "2011-08-12 09:00".
Note that this does not use TO_DATE. If you have incorrect strings in columns that must be DATEs, no errors occur.Assuming that hour_query.sql is located on p:\some_dir\, you want another script that runs hour_query.sql 24 times, like this one, which I will call all_hours.sql:
@p:\some_dir\hour_query "2011-08-12 09:00:00" "2011-08-12 10:00:00" @p:\some_dir\hour_query "2011-08-12 10:00:00" "2011-08-12 11:00:00" @p:\some_dir\hour_query "2011-08-12 11:00:00" "2011-08-12 12:00:00" ...
(I just did 3 hours to test. You can easily make that 24 hours).
The following code creates and then runs all_hours.sql:
-- Turn off SQL*Plus features that interfere with raw output SET FEEDBACK OFF SET PAGESIZE 0 SET VERIFY OFF -- Write all_hours.sql SPOOL p:\&some_dir\all_hours.sql WITH got_start_time AS ( SELECT TO_DATE ( '2011-08-12 09:00:00' , 'YYYY-MM-DD HH24:MI:SS' ) AS start_time FROM dual ) SELECT '@p:\some_dir\hour_query "' || TO_CHAR ( start_time + ((LEVEL - 1) / 24) , 'YYYY-MM-DD HH24:MI:SS' ) || '" "' || TO_CHAR ( start_time + ( LEVEL / 24) , 'YYYY-MM-DD HH24:MI:SS' ) || '"' FROM got_start_time CONNECT BY LEVEL <= 3 -- You can make this 24, or any other number ; SPOOL OFF -- Turn on SQL*Plus features turned off earlier SET FEEDBACK ON SET PAGESIZE 50 -- Except VERIFY. leave that OFF while all_hours runs --SET VERIFY OFF -- Run all_hours.sql @p:\some_dir\all_hours.sql SET VERIFY ON
Maybe you are looking for
-
Tecra S10 - 11W: WXP SP3 stuck while entering sleep mode
Hello people, I bought me a Tecra cos it came with a version of windows XP.Next to the strange effect once launched, it consumes about 800 MB, instead of the usual 300 MB, the system suspend frequently ends up in a kind of State of transition. I chec
-
NB200 - cursor jumps around the screen while typing
Hello When I type in MS Word or OpenOffice or any other text box on a Web site for example flushing prompt that identifies where the next word/character must be placed around the screen jumps. So when I type a line of text I then start another line b
-
2.1 to 1.5 downgrade?
Hello I remember Matt and/or users in trying to impregnation said brand would be able to downgrade 2.1 to 1.5 once the upgrade has been officially released. The upgrade was released, well, honestly, I would go back to 1.5. Anyone know where I can fin
-
With an average using the "basic DC/eff' VI
I seem to end up using the "basic DC/eff" VI a little average my data to my DAQ system. However, I have a question about what's going on "under the hood". Let's say, for simplicity I acquire data at 1 kHz into blocks of 1000 samples. Thus, all the 1
-
Add securities quotations of outgoing mail.
How can I include a quote on all of my outgoing email correspondence? I noticed a lot of people have sayings, titles, etc. that are still there. Help. Thank you