Dynamic rowsize from select statement.
Hi, I'm trying to get the lenght if the returned row from a select statement but I'm not sure how to do this properly.
The statement contains 530 columns of different type, mostly VARCHAR but also different number formats and timestamps.
I've tried to use LENGTH() + LENGTH() but our interactive SQL client is not very happy with the enormous statement size.
Thank you in advance.
/76...
I think you need something like this:
select column_name "name", data_type "type",
data_length "length", nullable "null"
from all_tab_columns
where table_name =' Your table_name'
Similar Messages
-
Dynamic field in Select Statement
I am able to create a dynamic statement to insert into the where clause of my sql, but I am unable to dynamically create a select statement. Oracle Reports produces the following error:
REP-0499: Column " selected by the query is incompatible with report definition.
Here is an example of my select:
Select
&dynamic_field
from
any_table
Any help is appreciated.I figured it out. Thanks
-
How to find the number of fetched lines from select statement
Hi Experts,
Can you tell me how to find the number of fetched lines from select statements..
and one more thing is can you tell me how to check the written select statement or written statement is correct or not????
Thanks in advance
santoshHi,
Look for the system field SY_TABIX. That will contain the number of records which have been put into an internal table through a select statement.
For ex:
data: itab type mara occurs 0 with header line.
Select * from mara into table itab.
Write: Sy-tabix.
This will give you the number of entries that has been selected.
I am not sure what you mean by the second question. If you can let me know what you need then we might have a solution.
Hope this helps,
Sudhi
Message was edited by:
Sudhindra Chandrashekar -
How to pass rowtype argument to a function from select statement?
Hi all!
I have function that takes mytable%rowtype as in parameter. can I pass entire row of mytable to the function from select statement? kind of
select myfunction(mytable.*) from mytable where ....
Thanks in advanceThe function can be used in a SQL statement only if it accepts SQL types and returns SQL type. %ROWTYPE being PL/SQL construct and not a SQL datatype, can not be used in this context.
http://download-west.oracle.com/docs/cd/B14117_01/server.101/b10743/datatype.htm#i2093 -
Dynamic internal table from SELECT - statement ?
Hi, is it possible to define an internal table just after a select statement is executed so that this internal table holds all the data that come back from the statement ?
thanks in advance,Check the link -
Re: Create Dynamic internal table
Regards,
Amit -
Dynamic sql for select statement
Hi,
Please help me with the below code:
It is updating null if the select statment returns one values. If it fetches multiple values then it throughs the below error msg when running the program.
Please let me know how to modify the below code. Or let me know is there anyother way to write this code.
Logic for development:
* View name should be passed as dynamic.
CREATE OR REPLACE
PROCEDURE "PKEP_LOAD_SO_EU" (p_var1 IN VARCHAR2)
IS
lv_sql VARCHAR2 (4000);
lv_name VARCHAR2 (20);
BEGIN
lv_sql :=
' SELECT DISTINCT LEVEL2
FROM BIIO_SALES_OB_IMPORT_'|| p_var1;
EXECUTE IMMEDIATE lv_sql
INTO lv_name;
BEGIN
UPDATE BIIO_SALES_OB_IMPORT_NA2 --table name for updation
SET SOB_1 = NULL,
SOB_DATE_1 = NULL
WHERE level2 = lv_name; -- validation ( eg. Select distinct level2 from biio_sales_ob_import_'||p_var1)
COMMIT;
EXCEPTION
WHEN OTHERS
THEN
DBMS_OUTPUT.put_line (SQLERRM);
NULL;
END;
END;
BEGIN
PKEP_LOAD_SO_EU ('NA1');
end;
Error report:
ORA-01422: exact fetch returns more than requested number of rows
ORA-06512: at "DEMANTRA.PKEP_LOAD_SO_EU", line 11
ORA-06512: at line 2
01422. 00000 - "exact fetch returns more than requested number of rows"
*Cause: The number specified in exact fetch is less than the rows returned.
*Action: Rewrite the query or change number of rows requested
Thanks.
PadmaPadu wrote:
Please let me know whether is anyother way to write this code as im a beginner for SQl.You dont need to have a seperate SELECT statement. Just a single UPDATE will do the job for you.
create or replace procedure pkep_load_so_eu
p_var1 in varchar2
as
begin
lSql := ' update biio_sales_ob_import_na2 ' ||
' set sob_1 = null ' ||
' , sob_date_1 = null ' ||
' where level2 in ( ' ||
' select level2 ' ||
' from biio_sales_ob_import_' || p_var1 ||
execute immediate lSql;
end; -
Dynamic Parameter LOV Select Statement
I have a parameter form with a value for the fiscal year and equipment ID. I want to populate the equipment ID list of values based on the fiscal year that is selected.
My query for the equipment ID list of values would be SELECT EQPID,NAME FROM EQPLIST WHERE FY = :FY.
When I tried to add this query to the list of values of the equipment ID parameter I get REP-0781: Bind variables are not allowed in the Select statement.
Is there a way to dynamically generate the list of values select statement in a reports trigger?Hi,
What version of Oracle Reports are you using?
Unfortunately, it is a limitation of Oracle Reports to not restrict values based on other parameters - for sure until Reports 6i and I believe until the recent new versions.
The other way to do what you want to do is to do it outside of Reports, if you have an Oracle Forms application. For example, you can create a simple Oracle Form that captures the Report parameters and then submits the report from the Forms. In Forms, you can implement the solution you are looking for - restricting values based on values of other parameters. In reports, you can't do that.
If you have a few other reports that have similar requirements, then you can create a form to launch reports and submit all your reports from there after capturing all your parameters there.
Venkat -
Specify database field's name dynamically in a select statement
Hi to all!!
I have the following problem:
I got a paraneters statement where the user is to choose the month of the year,once i have the month, i need to make a query on a database(select field_name) of a field whose name deppend on the month that the user chose before, is it possible?
What I need? I think i can do it using field simbols but I've never worked with field simbols and I have no time to learn it now.
Thanks everybodyHi,
<b>Below code is the Simple one:</b>
<b>DATA: DYN_FIELD(15)
SELECT single (DYN_FIELD)
into corresponding fields of <IT_TABLE>
from <TABLE> where XXX = YYY.</b>
This is the complex program, have a look at it ...
REPORT zdany_dynamic_select.
* We use some parameters to dynamically control the select, this is not very
* clever but this is just a test program !!
PARAMETER : p_tabnam TYPE tabname DEFAULT 'SFLIGHT',
p_selfl1 TYPE edpline DEFAULT 'CARRID',
p_selfl2 TYPE edpline DEFAULT 'CONNID',
p_selfl3 TYPE edpline DEFAULT 'FLDATE',
p_selfl4 TYPE edpline DEFAULT 'PRICE',
p_selfl5 TYPE edpline DEFAULT 'CURRENCY',
p_where1 TYPE edpline DEFAULT 'PRICE > 300',
p_where2 TYPE edpline DEFAULT 'AND CURRENCY = ''EUR'''.
FIELD-SYMBOLS : <lt_outtab> TYPE ANY TABLE,
<ls_outtab> TYPE ANY,
<l_fld> TYPE ANY.
DATA: lt_where TYPE TABLE OF edpline,
lt_sel_list TYPE TABLE OF edpline,
lt_group TYPE TABLE OF edpline,
l_having TYPE string,
l_wa_name TYPE string,
l_sel_list TYPE edpline,
dref TYPE REF TO data,
itab_type TYPE REF TO cl_abap_tabledescr,
struct_type TYPE REF TO cl_abap_structdescr,
elem_type TYPE REF TO cl_abap_elemdescr,
comp_tab TYPE cl_abap_structdescr=>component_table,
comp_fld TYPE cl_abap_structdescr=>component.
TYPES: f_count TYPE i.
* Creation of the output table including a non standard field, f_count
* see ABAP FAQ #14 for more information on this topic
struct_type ?= cl_abap_typedescr=>describe_by_name( p_tabnam ).
elem_type ?= cl_abap_elemdescr=>describe_by_name( 'F_COUNT' ).
comp_tab = struct_type->get_components( ).
* We remove the unnecessary fields
LOOP AT comp_tab INTO comp_fld.
IF comp_fld-name <> p_selfl1 AND
comp_fld-name <> p_selfl2 AND
comp_fld-name <> p_selfl3 AND
comp_fld-name <> p_selfl4 AND
comp_fld-name <> p_selfl5.
DELETE TABLE comp_tab WITH TABLE KEY name = comp_fld-name.
ENDIF.
ENDLOOP.
comp_fld-name = 'F_COUNT'.
comp_fld-type = elem_type.
APPEND comp_fld TO comp_tab.
struct_type = cl_abap_structdescr=>create( comp_tab ).
itab_type = cl_abap_tabledescr=>create( struct_type ).
l_wa_name = 'l_WA'.
CREATE DATA dref TYPE HANDLE itab_type.
ASSIGN dref->* TO <lt_outtab>.
CREATE DATA dref TYPE HANDLE struct_type.
ASSIGN dref->* TO <ls_outtab>.
* Creation of the selection fields and the "group by" clause
APPEND p_selfl1 TO lt_sel_list.
APPEND p_selfl1 TO lt_group.
APPEND p_selfl2 TO lt_sel_list.
APPEND p_selfl2 TO lt_group.
APPEND p_selfl3 TO lt_sel_list.
APPEND p_selfl3 TO lt_group.
APPEND p_selfl4 TO lt_sel_list.
APPEND p_selfl4 TO lt_group.
APPEND p_selfl5 TO lt_sel_list.
APPEND p_selfl5 TO lt_group.
APPEND 'COUNT(*) AS F_COUNT' TO lt_sel_list.
* creation of the "where" clause
APPEND p_where1 TO lt_where.
APPEND p_where2 TO lt_where.
* Creation of the "having" clause
l_having = 'count(*) >= 1'.
* THE dynamic select
SELECT (lt_sel_list)
FROM (p_tabnam)
INTO CORRESPONDING FIELDS OF TABLE <lt_outtab>
WHERE (lt_where)
GROUP BY (lt_group)
HAVING (l_having)
ORDER BY (lt_group).
* display of the results
LOOP AT <lt_outtab> ASSIGNING <ls_outtab>.
LOOP AT comp_tab INTO comp_fld.
ASSIGN COMPONENT comp_fld-name OF STRUCTURE <ls_outtab> TO <l_fld>.
WRITE: <l_fld>.
ENDLOOP.
SKIP.
ENDLOOP.
Have a look at the link, this link will have lot of examples :-
http://www.susanto.id.au/papers/DynOpenSQL.asp
Regards
Sudheer -
Dynamic fields in select statement
Hi all,
In selection screen we are having period as select option.The values for period are 01 to 16. Based on
the values entered in selection screen for period we need to select HSLXX from FAGLFLEXT.
For example if we enter 01 to 03 in selection screen then we need to select HSL01 HSL02 HSL03
from FAGLFLEXT.
Like this we need to select fields dynamically in select statement. Can any one tell me how to restrict fields dynamically.
Regards,
Swethahi Swetha,
the third select statemnet will work for you..
try this..
_Dynamic where clause in select query.._
* With a variable, result: AND rbusa = '5145'
concatenate 'AND rbusa = ' '''' i_tab-zgsber ''''
append where_clause to where_tab.
* Select
select * from zcostfreq
where (where_tab).
endselect.
_Using a dynamic table name_
parameters:
p_tab type tabname.
start-of-selection.
select count(*) from (p_tab) into l_count.
_Dynamic retrieval and writing of data_
FIELD-SYMBOLS:
<row> TYPE ANY,
<component> TYPE ANY.
PARAMETERS:
p_tab TYPE tabname.
CREATE DATA dataref TYPE (p_tab).
* The variable dataref cannot be accessed directly, so a field symbol is
* used
ASSIGN dataref->* TO <row>.
SELECT *
FROM (p_tab) UP TO 10 ROWS
INTO <row>.
NEW-LINE.
DO.
* Write all the fields in the record
ASSIGN COMPONENT sy-index
OF STRUCTURE <row>
TO <component>.
IF sy-subrc <> 0.
EXIT.
ENDIF.
WRITE <component>.
ENDDO.
ENDSELECT.
Regards,
Prabhduas -
Storing variable from select statement
I need to store a variable from a select statement into a session. Before I was taken what was passed from another page and throwing it into a session.--
String Password= request.getParameter("Password");
String sql = "Select WEB_USER_ID FROM Web_User WHERE PASSWORD = '" + Password +"'";
session.setAttribute("USER",Password);
Now though I need to put in Web_User_Id and cannot find the proper syntax. Can someone help
session.setAttribute("User",???????);WEB_USER_ID is unidentified because it is a column name, not a variable name. You should first assign its value to a variable and then put the variable name into the setAttribute statement instead.
Your query may return more than one result based on the way it is written. It sounds like you are trying to find all users with a password that is equal to the value of Password. If this is correct, then are you trying to create an attribute for each user?
If your intention is to locate a user, then the user id and password should have been provided. A variable should be defined for both the password and user id. You should then add the user id to the where clause. After a successful search, the attributes can be created using the same syntax. -
Dynamic table in select statement
Hi All,
I have a requirement where i have a select option in which the input is table name , i need to use this input in my select statement and fetch entries in the table where bname is eq to ' ' or uname eq ' '.
the challenge that i am facing is not all the tables have both the fields (uname and Bname).
Request your help on how to code the above requirements.
Thanks,
Bhanu.Bhanu,
I don't know what exactly is your requirement but I don't see any reason why a business user enters a table name as input in the selection screen.
MANDT NAME TYPE NUMB SIGN OPTI LOW HIGH
223 ZPROGNAME P 0001 I EQ XXX ZTABLENAME
You can maintain an entry like the above in TVARVC table and get the table name using a select query on TVARVC and then use the table as below
SELECT SINGLE * FROM (l_tabname)
into g_wa_tab2
WHERE quosrc EQ g_wa_tab1-quosrc AND
quotyp EQ g_wa_tab1-quotyp AND
quotno EQ g_wa_tab1-quotno AND
quotdate EQ g_wa_tab1-quotdate.
Funda is using TAVRVC to maintain the table names and determine the table based on a condition and the using the table in the select query.
Thanks,
K.Kiran. -
Calling PL/SQL code from Select statement
Hi
I have a PL/SQL function to calculate a value.
create or replace procedure "SR_GROSS_MARGIN"
(netsales IN NUMBER,
margin IN NUMBER,
GM OUT NUMBER)
is
BEGIN
IF NETSALES = 0 THEN
GM := 0;
ELSIF
NETSALES < 0 THEN
GM := 0;
ELSE
GM := NETSALES / MARGIN;
END IF;
END;How do I call this from a SELECT statement?
Regards
Adamhere you go:
create or replace function SR_GROSS_MARGIN
(netsales IN NUMBER,
margin IN NUMBER)
return number
is
gm number;
BEGIN
IF NETSALES = 0 THEN
GM := 0;
ELSIF
NETSALES < 0 THEN
GM := 0;
ELSE
GM := NETSALES / MARGIN;
END IF;
return gm;
END;then you can:
select gm(2500,20) from dual; -
Snapshot too old ORA-01555 from select statement (discoverer)??
Hi All
Am I loosing the plot .. but we have a select statement run from discoverer which is causing the famous snapshot too old error.
My understanding is that undo is generated from select/insert/update.
So why is the following discoverer Select statement causing the error?
from alert
ORA-01555 caused by SQL statement below (SQL ID: gk0wxgqmx66sh, Query Duration=3866 sec, SCN: 0x001e.089cf3f9):
SELECT ( ROUND(( TO_DATE(SYSDATE)-o101038.HIRE_DATE )/365,2) ) as
" bla bla
ORDER BY o101020.SUB_ORGANIZATION_NAME ASC
Thanks in Advancesimon.9999 wrote:
Hi All
Am I loosing the plot .. but we have a select statement run from discoverer which is causing the famous snapshot too old error.
My understanding is that undo is generated from select/insert/update.
So why is the following discoverer Select statement causing the error?
from alert
ORA-01555 caused by SQL statement below (SQL ID: gk0wxgqmx66sh, Query Duration=3866 sec, SCN: 0x001e.089cf3f9):
SELECT ( ROUND(( TO_DATE(SYSDATE)-o101038.HIRE_DATE )/365,2) ) as
" bla bla
ORDER BY o101020.SUB_ORGANIZATION_NAME ASC
Thanks in Advance
The SELECT statement is the victim.
Some session is doing DML against the same table against which the SELECT occurs & is likely doing COMMIT inside a LOOP. -
Passing values to OnDemandProcess from Select Statement on Reports Page
I think I'm just missing some of the proper syntax, Can somebody please help me.
As I've come to understand this process of passing the values,
I recognize it as (3) steps.
1. Referencing the "javascript" in the Select Statement of the Reports Page.
2. Including the "javascript" in the Page Header region.
3. Defining the Process as an OnDemand Application Process.
My problem is:
a. I can't seem to get the Value passed to the Application Process.
b. I don't know how to reference the Value passed once I get it passed.
Here's what I've got done so far:
1. (The Select Statement)
onClick="javascript:ORDER_CONNECT_SEQUENCE('||ID||')
{code}
2. (The javascript)
{code}
function ORDER_CONNECT_SEQUENCE('+ID+')
var get = new htmldb_Get(null,$x('pFlowId').value,'APPLICATION_PROCESS=ORDER_CONNECT_SEQUENCE',0);
get.add('+ID+');
gReturn = get.get('+ID+');
{code}
3. (The Application Process)
{code}
BEGIN
Select '+ID+' into THIS_CIRCUIT from dual;
{code}
I Know that the Application Process is being referenced and that the OnClick routine is working properly,
because if I plug a Value into the Application Process, instead of using '+ID+',
Then I get all of my desired results.
Any help you can give me here is greatly appreciated.
Thanks- GaryDimitri, Thanks for your efforts here, but its still not working for me.
Here's what I understand from your suggestions:
1. (changes to the javascipt)
a. replace function ORDER_CONNECT_SEQUENCE('+ID+')
with
function ORDER_CONNECT_SEQUENCE(pId)
b. replace get.add('+ID+')
with
get.addParam('x01',pId)
c. replace getReturn = get.get('+ID+')
with
getReturn = get.get()
get = null2. (chages to the Application Process)
a. add l_value varchar2(4000) to my list of declarations
b. add l_value := wwv_flow.g_x01 below the begin statement
c. I guess then I would reference the l_value like this:
Select l_value into THIS_CIRCUIT from dual* Also, You didn't mention any changes in my Select statement in the Reports region of the page.
FYI.
onClick="javascript:ORDER_CONNECT_SEQUENCE('||ID||')
{code}
The 'ID' which I'm referencing here is an ID from the table which I'm querying.
Am I misunderstanding you somewhere?
Thanks- gary -
View last 5 lines from select statement?
Hi,
I would like to view only the last 5 lines from a select statement, how would this be done?
Something like:
select * from a .................
regards
RobHHi RobH,
First of all: You need to identify a criterion that helps to sort your data in the desired way.
Done that you can start to read about analytical functions, maybe ROW_NUMBER(), RANK() and / or DENSE_RANK() might be interesting.
Edit:
Changed rn() to row_number()
Maybe you are looking for
-
Solution manager with MaxDB 64bit NW7
I am able to successfully complete ABAP stack and getting erro in "creating java user" step INFO 2009-11-03 06:59:36.582 Output of F:\usr\sap\CBM\DVEBMGS02\exe\jlaunch.exe UserCheck.jlaunch com.sap.security.tools.UserCheck "C:\Program Files\sapinst_i
-
So I am a current Verizon customer with a contract on a basic phone that ends in September of this year. I want an iPhone now, so I went to the Verizon store to ask them if I could get one. I was told that if I want to keep my number I will have to p
-
Best way of dealing with multiple sites?
As I make more and more sites the time it takes to "publish to folder" grows because I have all the old sites in my project file, so everything gets re-published to the folder, even old sites I have no interest in editing any more. What is the best w
-
Calling A Window's Program From Webforms
Is it possible to call a windows EXE program (such as NOTEPAD, WINWORD, EXCEL, etc) from forms6.0 running on the web? This should preferably be calling the programs residing in the CLIENT PC rather than the APP SERVER machine. I tried using both HOST
-
Active mq - reading few times the same message
Hi, i've got a question (problem?) about active mg. Firstly, i must admit that i'm a newbie to JMS. ok, so i wrote 2 threads - one for reading messages, second for sending them. The thread for sending, sends only one (test) message and it finishes. t