Select query in method endmethod
Hi all,
I am writing code in a method which is not accepting into table in select query, How to pass data into internal table using select query in method. As per my knowlegde we have to write code using field-symbols. can anybody please help me.
Thanks in advance.
Ranjith
it is possible to do a select into table. in your case the exporting parameter may be defined normal structure. if you want to define the internal table you have to use table types to behave the parameter as Internal table.
exporting
e_flight type sflight_1ab1
select * from sflight
into table e_flight
up to 30 rows.
Similar Messages
-
(view hint or Query writing method) using views in Select Query
Need Assistance,
Hi all,
My database having many views. while i am joining the views in a select query increase the cost of the querys due to the complex joins in the conditions.
While checking the select query with views individualy taking less cost.
Does any hint or query writing method is availabe to avoid the merging of the execution plan of the views?
I have browsed many related to the mentioned issues,couldn't found any thing that helps me.
Please help me on this issue,it will be very much helpfull for me.
Thanks,
SenthurPlease read the two threads linked to in the FAQ: {message:id=9360003} and post the relevant details they request, so that people can help you better with your issue.
We cannot help if you just say "my query is slow what do I do to fix it" as we cannot see your queries, your data, or any other information we would need to help. If the answer was that simple, it would be built into oracle so that the optimiser would fix it for you. -
Using case when statement in the select query to create physical table
Hello,
I have a requirement where in I have to execute a case when statement with a session variable while creating a physical table using a select query. let me explain with an example.
I have a physical table based on a select table with one column.
SELECT 'VALUEOF(NQ_SESSION.NAME_PARAMETER)' AS NAME_PARAMETER FROM DUAL. Let me call this table as the NAME_PARAMETER table.
I also have a customer table.
In my dashboard that has two pages, Page 1 contains a table with the customer table with column navigation to my second dashboard page.
In my second dashboard page I created a dashboard report based on NAME_PARAMETER table and a prompt based on customer table that sets the NAME_ PARAMETER request variable.
EXECUTION
When i click on a particular customer, the prompt sets the variable NAME_PARAMETER and the NAME_PARAMETER table shows the appropriate customer.
everything works as expected. YE!!
Now i created another table called NAME_PARAMETER1 with a little modification to the earlier table. the query is as follows.
SELECT CASE WHEN 'VALUEOF(NQ_SESSION.NAME_PARAMETER)'='Customer 1' THEN 'TEST_MART1' ELSE TEST_MART2' END AS NAME_PARAMETER
FROM DUAL
Now I pull in this table into the second dashboard page along with the NAME_PARAMETER table report.
surprisingly, NAME_PARAMETER table report executes as is, but the other report based on the NAME_PARAMETER1 table fails with the following error.
Error Codes: OPR4ONWY:U9IM8TAC:OI2DL65P
State: HY000. Code: 10058. [NQODBC] [SQL_STATE: HY000] [nQSError: 10058] A general error has occurred. [nQSError: 16001] ODBC error state: S1000 code: 1756 message: [Oracle][ODBC][Ora]ORA-01756: quoted string not properly terminated. [nQSError: 16014] SQL statement preparation failed. (HY000)
SQL Issued: SET VARIABLE NAME_PARAMETER='Novartis';SELECT NAME_PARAMETER.NAME_PARAMETER saw_0 FROM POC_ONE_DOT_TWO ORDER BY saw_0
If anyone has any explanation to this error and how we can achieve the same, please help.
Thanks.Hello,
Updates :) sorry.. the error was a stupid one.. I resolved and I got stuck at my next step.
I am creating a physical table using a select query. But I am trying to obtain the name of the table dynamically.
Here is what I am trying to do. the select query of the physical table is as follows.
SELECT CUSTOMER_ID AS CUSTOMER_ID, CUSTOMER_NAME AS CUSTOMER_NAME FROM 'VALUEOF(NQ_SESSION.SCHEMA_NAME)'.CUSTOMER.
The idea behind this is to obtain the data from the same table from different schemas dynamically based on what a session variable. Please let me know if there is a way to achieve this, if not please let me know if this can be achieved in any other method in OBIEE.
Thanks. -
Need help in writing a select query to pull required data from 3 tables.
Hi,
I have three tables EmpIDs,EmpRoles and LatestRoles. I need to write a select Query to get roles of all employees present in EmpIDs table by referring EmpRoles and LatestRoles.
The condition is first look into table EmpRoles and if it has more than one entry for a particular Employee ID than only need to get the Role from LatestRoles other wise consider
the role from EmpRoles .
Sample Script:
Create Table #EmpIDs
(EmplID int )
Create Table #EmpRoles
(EMPID int,Designation varchar(50))
Create Table #LatestRoles
EmpID int,
Designation varchar(50)
Insert into #EmpIDs values (1),(2),(3)
Insert into #EmpRoles values (1,'Role1'),(2,'Role1'),(2,'Role2'),(3,'Role1')
Insert into #LatestRoles values (2,'Role2')
Employee ID 2 is having two roles defined in EmpRoles so for EmpID 2 need to fetch Role from LatestRoles table and for
remaining ID's need to fetch from EmpRoles .
My Final Output of select query should be like below.
EmpID Role
1 Role1
2 Role2
3 Role1
Please help.
MohanMohan,
Can you check if this answers your requirement:
Create Table #EmpIDs
(EmplID int )
Create Table #EmpRoles
(EMPID int,Designation varchar(50))
Create Table #LatestRoles
EmpID int,
Designation varchar(50)
Insert into #EmpIDs values (1)
Insert into #EmpIDs values (2)
Insert into #EmpIDs values (3)
Insert into #EmpRoles values (1,'Role1')
Insert into #EmpRoles values (2,'Role2')
Insert into #EmpRoles values (2,'Role1')
Insert into #EmpRoles values (3,'Role1')
Insert into #LatestRoles values (2,'Role2')
--Method 1
select e.EmplID,MIN(ISNULL(l.Designation,r.Designation)) as Designation
from #empids e
left join #emproles r on e.emplID=r.EmpID
left join #latestRoles l on e.emplID=l.EmpID
group by e.EmplID
--Method 2
;with cte
as
select distinct e.EmplID,r.Designation,count(*) over(partition by e.emplID) cnt
from #empids e
left join #emproles r on e.emplID=r.EmpID
select emplID,Designation
from cte
where cnt=1
UNION ALL
select a.EmplID,l.Designation
from
(select distinct EmplID from cte where cnt>1) a
join #Latestroles l on a.EmplID=l.EmpID
order by emplID
Thanks,
Jay
<If the post was helpful mark as 'Helpful' and if the post answered your query, mark as 'Answered'> -
Multiple Schema select Query problem
Hi everyone,
when I tried to execute a select query as following,
select A.field1, B.field2 from S1.table1 A, S2.table2 B
in a session bean, it gives an exception as follows
" An illegal attempt to use multiple resources that have only one-phase capability has occurred within a global transaction"
Can anyone pls help me in this regard.
Thanking you
D. Suresh KumarThis is the query i thought of executing
SELECT * FROM SCH2.AP_TRANSACTION_EPS A, TRANSACTION_TYPES B WHERE C_FUND_CODE = '" + fundCode + "'AND D_TRADE_DATE = to_date('" + date + "','yyyy-mm-dd') AND A.C_TRANS_CODE = B.C_TRANS_CODE " + " AND B.C_TRANS_TYPE = '" + transType + "' ";
where "fundCode", "date","transType" are java variables.
The error message is
[8/1/03 12:38:49:688 IST] 491a6a5 TransactionIm E WTRN0062E: An illegal attempt to use multiple resources that have only one-phase capability has occurred within a global transaction.
[8/1/03 12:38:49:750 IST] 491a6a5 ConnectO A CONM6014I: Received exception (IllegalStateException) in method (enlist). Issuing new exception (IllegalTransactionStateException). The original exception's stack trace was: java.lang.IllegalStateException
Thanking you -
Cursor in select query in row to column format
Hi
I have the query like below
SELECT d.department_id,
CURSOR(SELECT e.first_name,
e.last_name
FROM employees e
WHERE e.department_id = d.department_id
) emps
FROM depatments dI want the result set in a format of Row To columns like
10 20
<cursor result> <cursor result>pls give ur suggestions how to achieve this in a efficient way?I tried the method of "max(decode(.." but dont think so its possible with thisvishnu prakash wrote:
Hi
I have the query like below
SELECT d.department_id,
CURSOR(SELECT e.first_name,
e.last_name
FROM employees e
WHERE e.department_id = d.department_id
) emps
FROM depatments dI want the result set in a format of Row To columns like
10 20
<cursor result> <cursor result>pls give ur suggestions how to achieve this in a efficient way?I tried the method of "max(decode(.." but dont think so its possible with thisNumber of column of a select query is static. Must be known at the parsing time itself. But in your case i dont think the number of columns will be limited to 2 (10 and 20) there could be many more.
You can search this forum to see how to PIVOT your data. There are lot of example. You can also try dynamic pivot. Its all in here, just search. -
Select query in case of Multiple line items
Hi Gurus ,
I've a doubt in general SQL select query. I want to know , if suppose I've an internal table - itab . I've fetched G/L Account numbers 1st, based on the input selections . Next , I want to loop on those G/L accounts. However, if the G/L account has multiple line items, then I personally use this select query -- >
loop at itab.
select <field> from <table> appending corresponding fields of <itab1> where hkont eq itab-hkont.
endloop.
Now, the execution time for this query is longer than expected. The biggest problem here is, i've to sum up the totals as well. So totaling is an added load. I want to reduce the execution time of this. Kindly suggest me some good method in case u have any.
I've pasted the code which I've written , for u ppl to understand--
SELECT DISTINCT HKONT BELNR
FROM BSIS
INTO CORRESPONDING FIELDS OF TABLE OTAB
WHERE HKONT IN S_RACCT
* AND PRCTR IN P_PRCTR
AND MONAT IN S_POPER
AND BUKRS EQ P_BUKRS
AND GJAHR EQ P_GJAHR
AND PRCTR IN S_PRCTR.
***The code below takes a lot of time to execute.***
LOOP AT OTAB .
SELECT DMBTR HKONT
FROM BSIS APPENDING CORRESPONDING FIELDS OF TABLE CREDITS
WHERE HKONT EQ OTAB-HKONT
AND BELNR EQ OTAB-BELNR
AND MONAT IN S_POPER
AND BUKRS EQ P_BUKRS
AND GJAHR EQ P_GJAHR
AND PRCTR IN S_PRCTR
AND SHKZG EQ 'H'.
COLLECT CREDITS.
ENDLOOP.Hi,
First of all try to avoid doing select into corresponding fields. THis would improve the performance of the program.
Try to do a single fetch from the BSIS table . fetch the hkont, belnr, dmbtr fields in to a master internal table. Manipulate and play with the data as required. Don't hit the data base table more than once (unless it is required) . This would improve the performance of your code.
Try to code this way.
types: begin of ty_bsis,
hkont type hkont,
belnr type belnr_d,
dmbtr type dmbtr,
end of ty_bsis.
data: it_bsis type standard table of ty_bsis,
wa_bsis type ty_bsis,
select hkont belnr dmbtr
from bsis
into table it_bsis
WHERE HKONT IN S_RACCT
AND PRCTR IN P_PRCTR
AND MONAT IN S_POPER
AND BUKRS EQ P_BUKRS
AND GJAHR EQ P_GJAHR
AND PRCTR IN S_PRCTR.
Using the data availabe in the it_bsis, you can manipulate as required.
Hope this would be helpful
Regards
Ramesh Sundaram -
I have a select query which uses a session variable in the
where clause like so:
select employee_lastname
from employee
where employee_id IN (#session.ids#)
This runs fine if I have only 1 employee id in session.ids,
but if I have multiple (i.e. 22,26,49) it crashes. Do I need to do
some sort of list or string conversion on my session variable?
Thanks in advance!
DaveI re-read my reply and it came off as if i didn't read your
(op) last post, sorry about that. I attempted to recreate your
effect (see code below) I did a 'quick' session on the output page;
<cfquery datasource="#DSN#" name="test">
select busName, ID
from Hernandomembers
</cfquery>
<body>
<form id="form1" name="form1" method="post"
action="delme.cfm">
<label>
<select name="list" id="select" multiple="multiple">
<cfoutput query="test">
<option value="#ID#">#busName#</option>
</cfoutput>
</select>
</label>
<label>
<input type="submit" name="button" id="button"
value="Submit" />
</label>
</form>
Collects the selections of members from my DB and sends it to
a page with ....
<cfset SESSION.employee_ids=StructNew()>
<cfset SESSION.employee_ids="#form.list#">
<cfoutput>#SESSION.employee_ids#<br />
</cfoutput>
<cfquery datasource="#DSN#" name="test">
select busName,ID
from Hernandomembers
where ID IN(#SESSION.employee_ids#)
</cfquery>
<cfoutput query="test">
#ID# - #busName#<br />
</cfoutput>
And it works just as yours should.. So i guess I'd still like
to see how your getting the selections into the session, if not the
same way as me. -
Update a field based on a max select query
Hi
I am just learning SQL so apologies if this is simple to you guys.
I have a table called [Stock WIP Table] which has duplicates in it. I have an [autonumber] field, a [palletid] field, and a [number5] field. I have the select query working to show the most recent record for each palletID:
SELECT
PalletID,MAX(autonumber)
FROMdbo.[Stock
WIP Table]
GROUPBYPalletID
How do I get the query to now delete all rows that are not in the select query?
Alternatively how could I add update the [number5] field to '1' where the [autonumber] is in the select and I can then delete all records that do not contain a '1' in [number5]
Can anyone help?
Thanks
AJHi
I am just learning SQL so apologies if this is simple to you guys.
I have a table called [Stock WIP Table] which has duplicates in it. I have an [autonumber] field, a [palletid] field, and a [number5] field. I have the select query working to show the most recent record for each palletID:
SELECT
PalletID,MAX(autonumber)
FROMdbo.[Stock
WIP Table]
GROUPBYPalletID
How do I get the query to now delete all rows that are not in the select query?
Alternatively how could I add update the [number5] field to '1' where the [autonumber] is in the select and I can then delete all records that do not contain a '1' in [number5]
Can anyone help?
Thanks
AJ
Simply this for the DELETE
DELETE t
FROM dbo.[Stock WIP Table]t
WHERE EXISTS (SELECT 1
FROM dbo.[Stock WIP Table]
WHERE PalletID = t.PalletID
AND autonumber > t.autonumber)
No need of UPDATE bit value and then deleting. just above will ensure it gets deleted in single step
another method you may use is this
DELETE t
FROM dbo.[Stock WIP Table] t
CROSS APPLY (SELECT MAX(autonumber) AS MaxID
FROM dbo.[Stock WIP Table]
WHERE PalletID = t.PalletID
)t1
WHERE t1.MaxID <> t.autonumber
Please Mark This As Answer if it helps to solve the issue Visakh ---------------------------- http://visakhm.blogspot.com/ https://www.facebook.com/VmBlogs -
Select query on a table with 13 million of rows
Hi guys,
I have been trying to perform a select query on a table which has 13 millions of entries however it took around 58 min to complete.
The table has 8 columns with 4 Primary keys looks like below:
(PK) SegmentID > INT
(PK) IPAddress > VARCHAR (45)
MAC Address > VARCHAR (45)
(PK) Application Name > VARCHAR (45)
Total Bytes > INT
Dates > VARCHAR (45)
Times > VARCHAR (45)
(PK) DateTime > DATETIME
The sql query format is :
select ipaddress, macaddress, sum(totalbytes), applicationname , dates,
times from appstat where segmentid = 1 and datetime between '2011-01-03
15:00:00.0' and '2011-01-04 15:00:00.0' group by ipaddress,
applicationname order by applicationname, sum(totalbytes) desc
Is there a way I can improve this query to be faster (through my.conf or any other method)?
Any feedback is welcomed.
Thank you.
MusTolls wrote:
What db is this?
You never said.
Anyway, it looks like it's using the Primary Key to find the correct rows.
Is that the correct number of rows returned?
5 million?
Sorted?I am using MySQL. By the way, the query time has been much more faster (22 sec) after I changed the configuration file (based on my-huge.cnf).
The number of rows returned is 7999 Rows
This is some portion of the my.cnf
# The MySQL server
[mysqld]
port = 3306
socket = /var/lib/mysql/mysql.sock
skip-locking
key_buffer = 800M
max_allowed_packet = 1M
table_cache = 256
sort_buffer_size = 1M
read_buffer_size = 1M
read_rnd_buffer_size = 4M
myisam_sort_buffer_size = 64M
thread_cache_size = 8
query_cache_size= 16M
log = /var/log/mysql.log
log-slow-queries = /var/log/mysqld.slow.log
long_query_time=10
# Try number of CPU's*2 for thread_concurrency
thread_concurrency = 6
Is there anything else I need to tune so it can be faster ?
Thanks a bunch.
Edited by: user578505 on Jan 17, 2011 6:47 PM -
Select query on QALS table taking around 4 secs to fetch one record
Hi,
I have one select query that takes around 4 secs to fetch one record. I would like to know if there are any ways to reduce the time taken for this select.
SELECT
b~prueflos
b~matnr
b~lagortchrg
a~vdatum
a~kzart
a~zaehler
a~vcode
a~vezeiterf
FROM qals AS b LEFT OUTER JOIN qave AS a ON
bprueflos = aprueflos
INTO TABLE t_qals1
FOR ALL ENTRIES IN t_lgorts
WHERE matnr = t_lgorts-matnr
AND werk = t_lgorts-werks
AND lagortchrg = t_lgorts-lgort
AND stat35 = c_x
AND art IN (c_01,c_08).
When I took the SQL trace, here I found other details :
Column No.Of Distinct Records
MANDANT 2
MATNR 2.954
WERK 30
STAT34 2
HERKUNFT 5
Analyze Method Sample 114.654 Rows
Levels of B-Tree 2
Number of leaf blocks 1.126
Number of distinct keys 16.224
Average leaf blocks per key 1
Average data blocks per key 3
Clustering factor 61.610
Also note, This select query is using INDEX RANGE SCAN QALS~D.
All the suggestions are welcome
Regards,
VijayaHi Rob,
Its strange but, the table t_lgorts has only ONE record
MATNR = 000000000500003463
WERK = D133
LAGORTCHRG = 0001
I have also seen that for the above criteria the table QALS has 2266 records that satisfy this condition.
I am not sure..but if we write the above query as subquery instead of Outer join..will it improve the performance?
Will check it from my side too..
Regards,
Vijaya -
the table i have
create table test of xmltype;
and the xml that i have loaded is
<root>
<company>
<department>
<id>10</id>
<name>Accounting</name>
</department>
<department>
<id>11</id>
<name>Billing</name>
</department>
</company>
</root>
select query using xmltable is
select id,name from test,xmltable('/root/company/department'
passing object_value
columns
id number path 'id',
name varchar2(20) 'name');
the query is working fine but issue is performance
i have imlplemented index using extract() and extractstringval() functions but as i have multiple
occurance of data ther two are not working. I have non-schema-based xmltype table.
I need help for creating index on multiple occurance element
Any help is appreciatedFirst of all "XMLOptimizationCheck" AFAIK is not yet explained. Haven't checked support.oracle.com for a while though.
It's more or less currently an internal used, but for the public a fast method to detect, that Oracle internal XQuery / XPath optimization rewrites towards SQL methods (shortcuts) are not properly working. SYS_XQEXVAL probably means something like XQuery Element XML Value/validation (??? towards SQL value) isn't producing a simple construct with a predicate validation. The reasons section gives insight, just like a 10053 trace, on what attempts/rules where applied and failed or worked. I am guessing that the overall cost for the use of the normal PK index is so high because it can not be properly matched and/or optimized against the global index structure supporting the partitions.
In all, a bit more info regarding the table/partition structure and its used index regime/structure would be helpful.
Beside that. THIS IS A BUG and should be reported, request for help, via support.oracle.com
Edited by: Marco Gralike on Mar 23, 2011 9:35 PM -
"Create Table from select Query" Vs "Insert into"
Hi
Schenaio:
My Select Query returns more than 10 million records, these records needs to be inserted into another table.
Approach 1:
I created table called TABLE1, and inserted the records using INSERT statement as a batch (batch size is 5000).
Approach 2:
I create table like,
CREATE TABLE TABLE1 AS <SELECT QUERY>
Here Apporach-1 took almost 40 minutes to complete the insert but Approach-2 took only 6 minutes.
If anybody knows why it is? And is there any way to improve the performance of Approach-1?.
Thanks
NidhiMost "batch" methods execute the same query multiple times. Row filtering is done after the rows are fetched from the source. The process of fetching all the rows could be a FullTableScan.
Therefore, a FullTableScan is executed for each batch of 5000 rows.
However, your query and batch definitions may well be different. We haven't seen the query and the execution plan.
Another point : How are you "filtering" the rows (i.e the second execution inserts rows 5001 to 10000 and does not attempt to reinsert rows 1 to 5000) ?
What is the overhead imposed by the filter ? (does the third execution have to exclude rows 1 to 10000 and inserts rows 10001 to 15000 and so on)
Hemant K Chitale -
How can i use param in my select query ( see code)
Hi ,
I need to use the param instead of hardcoding the value in the select query , when i did that it is working .
I think the limit of args is only till the end of main and my select query is in a method called Load() .
How can i use the param in my select query .
public static void main(String[] args){
name = args[0];
class= args[1];
new Load();
}//end of main
public Load()
try {
Class.forName(JDBC_DRIVER);
connection = DriverManager.getConnection(DATABASE_URL,"username","pw");
statement = connection.createStatement();
//First Query : pin and ticket number
ResultSet resultSet = statement.executeQuery("SELECT pin , ticketnumber from airport ,year where "+ "year.year_name= Here i need to use the param (instead of hardcoding) and year.class_year= Here too i need to use param");
}// end of method Load()Edited by: 1sai on Sep 24, 2008 7:34 AM
Edited by: 1sai on Sep 24, 2008 7:35 AMMight I suggest you change the structure of your program to the following:
public class Load {
private Connection conn;
private PreparedStatement statement;
public Load(String sql) {
init(sql);
protected void init(String sql) throws Exception {
Class.forName(JDBC_DRIVER);
conn = DriverManager.getConnection(DATABASE_URL, "username", "pw");
statement = conn.prepareStatement(sql);
public ResultSet execute(String p1, String p2) throws Exception {
statement.setString(1, p1);
statement.setString(2, p2);
return statement.executeQuery();
public void close() throws Exception {
if (statement != null)
statement.close();
statement = null;
if (conn != null)
conn.close();
conn = null;
public static void main(String[] args) throws Exception {
String sql = args[0];
String param1 = args[1];
String param2 = args[2];
Load load = new Load(sql);
ResultSet rs = load.execute(param1, param2);
while (rs.next())
System.out.println(rs.get(0));
rs.close();
load.close();
}This allows you to use the same "Load" object for multiple queries with different parameters.
I do not recommend you actually use the code above in any sort of production application. You should really take a look at Spring Framework along with an ORM tool like Hibernate or Ibatis to simplify your DAO layer.
Hope this helps,
David -
Pls help me in select query......
My problem is...
I have to use a select query in such a manner that i can compare the last 8 characters or ignore the first one...Hi Aarif,
Try this :
parameters :
p_field1(30) type c.
Data :
w_string(8) type c,
w_firstchar type c,
t_itab ......,
fs_itab like line of itab.
w_string = p_field1+22(8) " passing last 8 chars into w_string
w_firstchar = p_field1+0(1).
select *
from DataTab Name
into table IntTab Name
where <field name> eq w_string
or <field name> ne w_firstchar.
If you are accepting the value from user then first pass the last 8 characters into w_string and in your select query get the fields where the value is equal to w_string. And pass the first character into another field and to ignore write NE W_FIRSTCHAR.
There can be other methods also. This is one of the ways.
Regards,
Swapna.
Edited by: NagaSwapna Thota on Jul 19, 2008 9:23 AM
Maybe you are looking for
-
Exclude stills in import window Final Cut Pro X
I export from a memory card removed from my camera which I use for both still RAW images and videos. Ther are always way more stills than videos and I would like a way to have the import window show only the videos. I use Aperture to import the still
-
Hello Experts, I have assigned alternate Payee in the vendor master record and aswell as the purchase order. While doing the Vendor invoice (MIRO) its showing the error that the alternate Payee is not defined . Account number xxxxxxxxx specified for
-
Is there a way to delete folders in mass without sitting and clicking on the dialog box for each folder?
-
Create credit request through E-commerce B2B application
Hello Experts, My client has a requirement to allow the customers to create a Credit Memo request through E-Commerce B2B application. As I understand Credit request is of type Sales Transaction, which is normally created with reference to a billing d
-
I just downloaded 7.0.2 to my IPad. When I open my iBooks, I can't get my books to download...any ideas?