Split the text of an SQL query
I'd like to make the following :
transform the text (SQL code) of an SQL query into its
components... here is an example of what I need :
<cfsavecontent variable="my_query">
SELECT one, two, three FROM table1
WHERE one = 'yipee' or two = 'hi'
group by one, twho, three
order by one desc
</cfsavecontent>
I need a function that returns me a struct (for example) with
my_struct.select = "SELECT one, two, three"
my_struct.from = "FROM table1"
The hard part is that there is not always every element (for
example no GROUP or no ORDER BY)... so I'm beginning to make some
bad stuff with imbricated FindNoCase() and it's starting to me a
real mess.
I'm sure there is an alternative, something that can easily
split a string each time it contains a "reserved" sql word.
I imagine a split(my_query,"select,from,where,group by, order
by") for example...
I need help and suggestions and as usual, sorry for my bad
english
i think a regular expression is he way to go in your case...
Azadi Saryev
Sabai-dee.com
http://www.sabai-dee.com
Similar Messages
-
End the result of an sql query by Email as an excel file attachement
Hi,
I would like to create a PL/SQL function that send the result of an sql query by Email as an excel file attachement.
i'm newbie in pl/sql an d i dont know if it's possible to do such task.
regards,i think a regular expression is he way to go in your case...
Azadi Saryev
Sabai-dee.com
http://www.sabai-dee.com -
How to show the VALUE as the Column Header using SQL query?
Hi
I have a requirement to show the picked value as the column header using SQL query.
Example:
======
SELECT EMPNO FROM EMP
WHERE EMPNO=7934;
Result Should be:
7934
7934I have a requirement to show the picked value as the column header using SQL query.In sql*plus you can do
SQL> set verify on
SQL> def e = 7934
old: SELECT empno "&&e" FROM emp WHERE empno = &&e
new: SELECT empno "7934" FROM emp WHERE empno = 7934
SQL> SELECT empno "7934" FROM emp WHERE empno = 7934
7934
7934
1 row selected. -
Pass the result of a SQL Query as table_name for another SQL Query
Hi All,
How to pass the result of a SQL Query as parameter to another SQL Query
Eg: I am doing the steps below.
1) select distinct table_name as TAB1 from all_tab_cols where table_name like 'T_%' and column_name like '%XYZ'
2) I want to pass the table_name from step 1 above as parameter to another query "select * from TAB1"
ThanksNaveen B wrote:
Hi All,
How to pass the result of a SQL Query as parameter to another SQL Query
Eg: I am doing the steps below.
1) select distinct table_name as TAB1 from all_tab_cols where table_name like 'T_%' and column_name like '%XYZ'
2) I want to pass the table_name from step 1 above as parameter to another query "select * from TAB1"
ThanksYou should craete PL/SQL code with cursor which will accept a parameter and call that cursor inside the first one
But if the first sql returns only one row, you can do it with simple sql code
select * from (select distinct table_name as TAB1 from all_tab_cols where table_name like 'T_%' and column_name like '%XYZ')- - - - - - - - - - - - - - - - - - - - -
Kamran Agayev A. (10g OCP)
http://kamranagayev.wordpress.com
[Step by Step install Oracle on Linux and Automate the installation using Shell Script |http://kamranagayev.wordpress.com/2009/05/01/step-by-step-installing-oracle-database-10g-release-2-on-linux-centos-and-automate-the-installation-using-linux-shell-script/] -
SQL Subscription field shows * only with Dynamic Text Label in SQL query
We are using Hyperion Analyzer 7.2.x for showing budget and actual data. I have to show this financial data based on the security e.g. person in IT can see only IT dept. data. Hence I want to use dynamic text label <<userid>> for the security based on the person logging in to Analyzer.
But when I use dynamic text label <<userid>> in the SQL query in SQL Spreadsheet, SQL Subscription field shows * only selection option. Does anyone have idea how to solve this problem?
Thanks in advance for your help.
-SVHi
Okay i know this is a bit crazy way.....but i think this is the solution for your issue.
Create a report without the where clause (<<useris>>) then add a filter (sql subscription) then you can find all the values that are there in the SQL field (try to increase the query limit it is set to 250 as default) then edit the spreadsheet and add the where clause (<<userid>>).
This will help you having the filter and the dynamic text label. I think there is an issue when you try to filter it with a where clause.
Hope it helps.
CK -
Set Text Item To SQL Query Result
I am trying to set a text item to a SQL query result. Something like the following:
(I am trying to accomplish this in the SOURCE portion, set to 'SQL Query' source type, of the text item properties)
SELECT empno FROM emp WHERE empno = :SEARCH_EMPNO;
This only displays as the literal text when the application renders and not the value from the SQL query.
I apologize if this has already been posted but I could not find what I am looking for. I have seen posts that reference a pre-region computation but do not know the exact steps to accomplish the results I want.
Thanks in advance for anyone's time to help me with my issue.
KyleScott,
The literal that displayed (I have fixed it) was the actual SQL statement: SELECT empno FROM emp WHERE empno = :SEARCH_EMPNO;
I have resolved the issue, using SQL Query as the "Source Type" and Always, replacing any existing value in session state as the "Source Used" for the properties of the item.
What I was trying to accomplish is a search text item that would return the data for that record in a table into other text items, for each column in that record, for update; based on the search text item as a unique SQL query search for that record.
Thank you for your quick reply!
Kyle -
How to get text of Last SQL Query
Sorry if this has been covered, but the search page keeps erring on me.
I am trying to figure out how to get the text of the last SQL statement executed (succesfully or unsuccesfully) by my current login.
What it is, is i want in the exception handler of my procedure to be able to dump the text of the Query which was last run into the log file.
Any help with this will be greatly appreciated!
Thanks in advance,
Aaron.
[email protected]Well, ive been trying V$SQLTEXT in conjunction with V$SESSION and USERENV('SESSIONID'). This gets me my SQL statements, but the SQL_HASH_VALUE and PREV_HASH_VALUE, which are supposed to be the current and previous statements respectively always are the same and always point to the current statement..... is there some sort of flag you have to set to get PREV_HASH_VALUE (and PREV_SQL_ADDR) to actually point to the **PREVIOUS** statement??
-
How to access the text definition of sql indexes
I am able to access the text definition of stored procedures, views, triggers and functions from sys.sql_modules. I want to get the text definition of indexes.
Can somebody help me in getting the text definition of indexes in sql server.
Thanks,
PuneetNo, Actually I am trying to compare the indexes of two database programmatically.
I am able to compare the stored procedures, views, triggers and functions by getting text definition directly from 'sys.sql_modules', on similar lines do we have any way from where I could get the text definition of indexes
Not sure if there is any table which stores Index defination but there is a table "sys.indexex" which stores index details.
You may use below query to get index information (It will list out index details but not defination)
SELECT s.NAME 'Schema'
,t.NAME 'Table'
,i.NAME 'Index'
,c.NAME 'Column'
FROM sys.tables t
INNER JOIN sys.schemas s ON t.schema_id = s.schema_id
INNER JOIN sys.indexes i ON i.object_id = t.object_id
INNER JOIN sys.index_columns ic ON ic.object_id = t.object_id
INNER JOIN sys.columns c ON c.object_id = t.object_id
AND ic.column_id = c.column_id
WHERE i.index_id > 0
AND i.type IN (
1
,2
) -- clustered & nonclustered only
AND i.is_primary_key = 0 -- do not include PK indexes
AND i.is_unique_constraint = 0 -- do not include UQ
AND i.is_disabled = 0
AND i.is_hypothetical = 0
AND ic.key_ordinal > 0
ORDER BY ic.key_ordinal
- Also there is one more SP which you can create and then execute it by specifying DB names. It will list out table columns, indexes, constraints difference in one go.
EXEC SP_Comparedb db1,db2
Technet Gallary: Compare two databases for objects differences
Cheers,
Vaibhav Chaudhari -
How to Suppress The Output of a SQL Query In Oracle 11gR2
Hi Friends,
I am using oracle version 11.2.0.1, I have set a cronjob which will run on every 15 minutes and give us a log file mentioning the execution time taken for that SQL query:-
For example:
SQL> set timing on;
SQL> SELECT objProp FROM aradmin.arschema WHERE (schemaId = 175);
OBJPROP+
--------------------------------------------------------------------------------+
*6\60006\4\0\\60008\40\0\60009\4\0\\60010\4\0\\60018\4\0\\600*
*22\4\68\1\63\AR:jRL#*
Elapsed: 00:00:00.00
The above query will return the output as well as the time taken for execution of the query. I want to suppress the output of the query and only want the time taken to be printed. Is it possible by set commands. I have marked the output as bold and made it Italic.
Please help me at the earliest.
Regards,
Arijit>
I am using oracle version 11.2.0.1, I have set a cronjob which will run on every 15 minutes and give us a log file mentioning the execution time taken for that SQL query:-
The above query will return the output as well as the time taken for execution of the query. I want to suppress the output of the query and only want the time taken to be printed. Is it possible by set commands. I have marked the output as bold and made it Italic.
>
How would that even be useful?
A query from a tool such as sql*plus is STILL going to send the output to the client and the client. You can keep sql*plus from actually displaying the data by setting autotrace to trace only.
But that TIME TAKEN is still going to include the network time it takes to send ALL rows that the query returns across the network.
That time is NOT the same as the actual execution time of the query. So unless you are trying to determine how long it takes to send the data over the network your 'timing' method is rather flawed.
Why don't you tell us WHAT PROBLEM you are trying to solve so we can help you solve it? -
How to Use the Procedures in a Sql Query
Hi Friends,
Can anyone help me out whether can we use the procedure in the sql query..
if yes help me out with an example
my requirement is
i have one sql query .. in which i need to use the procedure which returns multiple values... how can i overcome it,can anyone help me out for this..
for your reference i am pasting the sql query
SELECT paf.person_id
FROM per_all_assignments_f paf START WITH paf.person_id = p_person_id
AND paf.primary_flag = 'Y'
AND paf.assignment_type IN('E', 'C')
AND l_effective_date BETWEEN paf.effective_start_date
AND paf.effective_end_date
CONNECT BY PRIOR paf.supervisor_id = paf.person_id
AND paf.primary_flag = 'Y'
AND paf.assignment_type IN('E', 'C')
AND l_effective_date BETWEEN paf.effective_start_date
AND paf.effective_end_date
and paf.person_id not in (>>>I HAVE TO USE THE PROCEDURE HERE<<<<);
Thanks in advanceWe never saw your procedure, but maybe you could wrap it in a function
SQL> create or replace procedure get_members(in_something IN number, out_members OUT sys_refcursor)
is
begin
open out_members for
'select level member_id from dual connect by level <= :num' using in_something;
end get_members;
Procedure created.
SQL> create or replace type numbers as table of number;
Type created.
SQL> create or replace function members(in_something IN number)
return numbers
as
member_cur sys_refcursor;
members numbers;
begin
get_members(in_something, member_cur);
fetch member_cur bulk collect into members;
close member_cur;
return members;
end;
Function created.
SQL> select * from table(members(4));
COLUMN_VALUE
1
2
3
4
4 rows selected.Variant on same using piplined function
SQL> create or replace function members_piped(in_something IN number)
return numbers pipelined
as
member_cur sys_refcursor;
rec number;
begin
get_members(in_something, member_cur);
loop
fetch member_cur into rec;
exit when member_cur%notfound;
pipe row(rec);
end loop;
close member_cur;
return;
end;
Function created.
SQL> select * from table(members_piped(4));
COLUMN_VALUE
1
2
3
4
4 rows selected.
SQL> drop function members_piped;
Function dropped.
SQL> drop function members;
Function dropped.
SQL> drop type numbers;
Type dropped.
SQL> drop procedure get_members;
Procedure droppedEdit:
Sorry Blu, had not seen you already posted similar thing
Edited by: Peter on Jan 27, 2011 5:38 AM -
Check the hints used in SQL Query (Parallel, First_Rows)
Hi,
I have used above hints in my sql query and found no difference in execution time.
I just want to know whether the hints are used in my sql are not.
Could you please let me know where to check for it.
Thanks in advanceCan you post the SQL which uses these hints and the execution plan with and without those hints here? Then only community can help you find out if the hints are really used or not.
Please use code tags to preserve the format of execution plan.
Edited by: Satish Kandi on Jun 23, 2009 5:37 PM -
Can we store procedure in a folder in text file using SQL QUERY
I want to create a folder in D drive and give folder name as current date. After that create no. of text files based on how many procedure are, text file name will be same as procedures name and insert a procedures inside the text files by using stored
procedure.I want to create a folder in D drive and give folder name as current date. After that create no. of text files based on how many procedure are, text file name will be same as procedures name and insert a procedures inside the text files by using stored
procedure.
You can use generate scripts wizard for this. It will by default give scripts in .sql format. You can then use a command line script to change all of them to .txt.
Another option is to have SSIS package and use File SYstem Task to rename it to .txt
Please Mark This As Answer if it solved your issue
Please Vote This As Helpful if it helps to solve your issue
Visakh
My Wiki User Page
My MSDN Page
My Personal Blog
My Facebook Page -
How to return in pl/sql the tuples of an sql query comming several tables
I have a select query whose result comes from several tables. The question is how to return the tuples of the select query using a pl/sql function. In othe words, is it possible to define a construct structure to store the values of sql query and return that construct. if yes how to define such a construct where its elements comming from several tables.
I appreciate very much ur helpThe way to return a resultset from a function is with a cursor variable. The lazy of doing this is using a weakly-typed ref cursor (in 9i use the predefined SYS_REFCURSOR).
Cheers, APC -
Error while calling the function which returns SQL Query!!!
Hi,
I have a Function which returns SQL query. I am calling this function in my APEX report region source.
The query is dynamic SQL and its size varies based on the dynamic "where clause" condition.
But I am not able to execute this function.It gives me the following error in APEX region source.
ORA-06502: PL/SQL: numeric or value error: character string buffer too small
Even in SQL* Plus or SQL developer also same error .
The length of my query is more than 4000. I tried changing the variable size which holds my query in the function.
Earlier it was
l_query varchar2(4000)
Now I changed to
l_query varchar2(32767).
Still it is throwing the same error.
Can anybody help me to resolve this.???
Thanks
AlakaHi Varad,
I am already using 32k of varchar2. Then also it is not working.
It is giving the same error. I think there is something to do with buffer size.
My query size is not more than 4200. Even if i give 32k of varchar2 also buffer is able to hold only 3997 size of the query only.
Error is
ORA-06502: PL/SQL: numeric or value error: character string buffer too small
Tried CLOB also. It is not working.
Any other solution for this.
Thanks
Alaka -
I am not able to see the trace files for SQL query
Hello, I am using windows vista OS.
SQL> select * from v$version;
BANNER
Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - Prod
PL/SQL Release 10.2.0.3.0 - Production
CORE 10.2.0.3.0 Production
TNS for 32-bit Windows: Version 10.2.0.3.0 - Production
NLSRTL Version 10.2.0.3.0 - Production
SQL>
I enabled the trace as below
alter system set timed_statistics=TRUE
alter system set sql_trace=TRUE
After this, I ran sql query from scott as below.
select count(*) from emp;
After this, i checked in user dump directory. The trace files are generating... But this sql code is not appearing in the trace files...
Am i missing anything... Any help is appreciated.
ThanksThis may happen when the trace file is not completely closed.You may try again doing like this,
alter session set sql_trace=true;
select * from emp;
alter session set sql_trace=false;After this,disconnect and exit from your session as well. This should close the file completely and you should be able to see your command in it.
HTH
Aman....
Maybe you are looking for
-
How can I read a line of numbers in a file?
Hello everybody, I have a ziped.file organized in this way: number1 number 2 number3 name1, name2, name3 number_of points information_about_number_of_point number4 number4 number4 number4 number4 number4 number4 number4 number4 number4 number5 number
-
Hi all, my scenario is the following : BAPI -> XI -> HTTP In my understanding, if I have a BAPI as sender, my scenario has to be synchronous. Is it correct ? The BAPI sends Purchase Orders. When we send one, everything seems OK on the sender side. In
-
How can I resolve 127.0.0.1 to my IP address?
How can I resolve 127.0.0.1 to my IP address?
-
New OS x Maverick won't allow iPhone and iMovie updates. Why?
I have just downloaded OS X Maverick and now can't update or access my iphoto or imovie. why and what can I do about it?
-
PLEASE HELP - Flash Website template
Hello I purchased a pretty cool flash website template for our film company and I have edited almost all of the website but I cannot figure out how to get my movie files to appear and play on my Portfolio page. Pleeeeeease help me. I am willing to se