Create table problem using Dynamic Query
Hi all,
I want to create a temporary table within a stored procedure so I decided to do it using a dynamic query:
create or replace procedure p1
as
begin
execute immediate 'CREATE GLOBAL TEMPORARY TABLE tt(id number(2))';
end;
/ It created successfuly but when I execute that procedure I got:SQL> exec p1;
BEGIN p1; END;
ERROR at line 1:
ORA-01031: insufficient privileges
ORA-06512: at "SCOTT.P1", line 4
ORA-06512: at line 1 While I can create that table using the same user without any problem!
My question is:What privilege should I grant to user(minimum of privileges please! ) to execute that procedure successfuly?
-Thanks
Hi,
To say a little bit more about Nicolas' answer:
SQL> grant create table to scott;
This is the right answer, but you might wonder why you have to do so if you usually can create tables with this user..
11:59:19 TEST.SQL>CREATE USER UTEST
11:59:28 2 IDENTIFIED BY UTEST;
User created.
11:59:35 TEST.SQL>CREATE ROLE RTEST;
Role created.
11:59:40 TEST.SQL>GRANT RTEST TO UTEST;
Grant succeeded.
11:59:45 TEST.SQL>GRANT CREATE SESSION TO RTEST;
Grant succeeded.
11:59:54 TEST.SQL>GRANT CREATE TABLE TO RTEST;
Grant succeeded.
12:00:03 TEST.SQL>GRANT UNLIMITED TABLESPACE TO UTEST;
Grant succeeded.
12:00:17 TEST.SQL>CREATE PROCEDURE UTEST.CT_TEST
12:00:32 2 IS
12:00:33 3 BEGIN
12:00:35 4 EXECUTE IMMEDIATE 'CREATE TABLE UTEST.TTEST (A NUMBER)';
12:00:56 5 END;
12:00:58 6 /
Procedure created.
12:00:59 TEST.SQL>EXEC UTEST.CT_TEST;
BEGIN UTEST.CT_TEST; END;
ERROR at line 1:
ORA-01031: insufficient privileges
ORA-06512: at "UTEST.CT_TEST", line 4
ORA-06512: at line 1
12:01:06 TEST.SQL>GRANT CREATE TABLE TO UTEST;
Grant succeeded.
12:01:15 TEST.SQL>EXEC UTEST.CT_TEST;
PL/SQL procedure successfully completed.Don't forget that when you're using PL/SQL, privileges granted via roles are ignored!
Regards,
Yoann.
Similar Messages
-
Create Table Control using Dynamic Internal Table.
Hi,
I have requirement in which I will create a Dynamic Internal Table and then I need to create a Table Control Using that Internal Table. Now this can't be done using Screen Editor as it requires a pre-defined internal table or a DDIC Object.
Please Help.This should be correct answer(I am not author of code below):
REPORT ztablemaintace NO STANDARD PAGE HEADING.
TYPE-POOLS: rsds.
DATA: is_x030l TYPE x030l,
it_dfies TYPE TABLE OF dfies,
is_dfies TYPE dfies,
it_fdiff TYPE TABLE OF field_dif,
is_fdiff TYPE field_dif.
DATA: w_selid TYPE rsdynsel-selid,
it_tables TYPE TABLE OF rsdstabs,
is_tables TYPE rsdstabs,
it_fields TYPE TABLE OF rsdsfields,
it_expr TYPE rsds_texpr,
it_ranges TYPE rsds_trange,
it_where TYPE rsds_twhere,
is_where TYPE rsds_where,
w_active TYPE i.
DATA: it_content TYPE REF TO data,
it_modif TYPE REF TO data,
it_fcat TYPE lvc_t_fcat.
DATA: w_okcode TYPE sy-ucomm.
FIELD-SYMBOLS: <itab> TYPE STANDARD TABLE,
<ntab> TYPE STANDARD TABLE.
* Macros
DEFINE table_error.
message e398(00) with 'Table' p_table &1.
END-OF-DEFINITION.
DEFINE fixed_val.
is_fdiff-fieldname = is_dfies-fieldname.
is_fdiff-fixed_val = &1.
is_fdiff-no_input = 'X'.
append is_fdiff to it_fdiff.
END-OF-DEFINITION.
* Selection screen
SELECTION-SCREEN: BEGIN OF BLOCK b01 WITH FRAME.
PARAMETERS: p_table TYPE tabname OBLIGATORY "table
MEMORY ID dtb
MATCHCODE OBJECT dd_dbtb_16.
SELECTION-SCREEN: BEGIN OF LINE,
PUSHBUTTON 33(20) selopt USER-COMMAND sel,
COMMENT 55(15) selcnt,
END OF LINE.
SELECTION-SCREEN: SKIP.
PARAMETERS: p_rows TYPE i. "rows
SELECTION-SCREEN: END OF BLOCK b01,
SKIP,
BEGIN OF BLOCK b02 WITH FRAME.
PARAMETERS: p_displ TYPE c AS CHECKBOX. "display
SELECTION-SCREEN: END OF BLOCK b02.
* Initialization
INITIALIZATION.
MOVE '@4G@ Filter records' TO selopt.
* PBO
AT SELECTION-SCREEN OUTPUT.
IF w_active IS INITIAL.
CLEAR: selcnt.
ELSE.
WRITE w_active TO selcnt LEFT-JUSTIFIED.
ENDIF.
* PAI
AT SELECTION-SCREEN.
IF p_table NE is_x030l-tabname.
CALL FUNCTION 'DDIF_NAMETAB_GET'
EXPORTING
tabname = p_table
IMPORTING
x030l_wa = is_x030l
TABLES
dfies_tab = it_dfies
EXCEPTIONS
OTHERS = 1.
IF is_x030l IS INITIAL.
table_error 'does not exist or is not active'.
ELSEIF is_x030l-tabtype NE 'T'.
table_error 'is not selectable'.
* ELSEIF is_x030l-align NE 0.
* table_error 'has alignment - cannot continue'.
ENDIF.
* Default values for system fields
REFRESH: it_fdiff.
is_fdiff-tabname = p_table.
LOOP AT it_dfies INTO is_dfies.
IF is_dfies-datatype = 'CLNT'.
fixed_val sy-mandt.
ELSEIF is_dfies-rollname = 'ERDAT'
OR is_dfies-rollname = 'ERSDA'
OR is_dfies-rollname = 'AEDAT'
OR is_dfies-rollname = 'LAEDA'.
fixed_val sy-datum.
ELSEIF is_dfies-rollname = 'ERTIM'
OR is_dfies-rollname = 'AETIM'.
fixed_val sy-uzeit.
ELSEIF is_dfies-rollname = 'ERNAM'
OR is_dfies-rollname = 'AENAM'.
fixed_val sy-uname.
ENDIF.
CALL FUNCTION '/SAPDMC/DATAELEMENT_GET_TEXTS'
EXPORTING
name = is_dfies-rollname
IMPORTING
text_middle = is_dfies-reptext
EXCEPTIONS
not_found = 1
OTHERS = 2.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
MODIFY it_dfies FROM is_dfies.
ENDLOOP.
* Prepare free selection on table
REFRESH it_tables.
is_tables-prim_tab = p_table.
APPEND is_tables TO it_tables.
CLEAR: w_selid.
ENDIF.
IF sy-ucomm = 'SEL'.
IF w_selid IS INITIAL.
* Init free selection dialog
CALL FUNCTION 'FREE_SELECTIONS_INIT'
EXPORTING
expressions = it_expr
IMPORTING
selection_id = w_selid
expressions = it_expr
TABLES
tables_tab = it_tables
EXCEPTIONS
OTHERS = 1.
ENDIF.
* Display free selection dialog
CALL FUNCTION 'FREE_SELECTIONS_DIALOG'
EXPORTING
selection_id = w_selid
title = 'Selection'
status = 1
as_window = 'X'
IMPORTING
expressions = it_expr
field_ranges = it_ranges
number_of_active_fields = w_active
TABLES
fields_tab = it_fields
EXCEPTIONS
OTHERS = 1.
ENDIF.
* Start of processing
START-OF-SELECTION.
PERFORM f_create_table USING p_table.
PERFORM f_select_table.
PERFORM f_display_table.
* FORM f_create_table *
FORM f_create_table USING in_tabname.
FIELD-SYMBOLS: <fcat> TYPE lvc_s_fcat.
CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
EXPORTING
i_structure_name = in_tabname
CHANGING
ct_fieldcat = it_fcat
EXCEPTIONS
OTHERS = 1.
IF sy-subrc = 0.
* Complete field catalog
LOOP AT it_fcat ASSIGNING <fcat>.
<fcat>-tabname = in_tabname.
ENDLOOP.
CALL FUNCTION 'LVC_FIELDCAT_COMPLETE'
CHANGING
ct_fieldcat = it_fcat
EXCEPTIONS
OTHERS = 1.
ELSE.
WRITE: 'Error building field catalog'.
STOP.
ENDIF.
* Create dynamic table for data
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = it_fcat
IMPORTING
ep_table = it_content.
IF sy-subrc = 0.
ASSIGN it_content->* TO <itab>.
ELSE.
WRITE: 'Error creating internal table'.
STOP.
ENDIF.
* Create dynamic table for modif
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = it_fcat
IMPORTING
ep_table = it_modif.
IF sy-subrc = 0.
ASSIGN it_modif->* TO <ntab>.
ELSE.
WRITE: 'Error creating internal table'.
STOP.
ENDIF.
ENDFORM. "f_create_table
* FORM f_select_table *
FORM f_select_table.
IF w_active = 0.
SELECT * FROM (p_table)
INTO CORRESPONDING FIELDS OF TABLE <itab>
UP TO p_rows ROWS.
ELSE.
* Selection with parameters
CALL FUNCTION 'FREE_SELECTIONS_RANGE_2_WHERE'
EXPORTING
field_ranges = it_ranges
IMPORTING
where_clauses = it_where.
READ TABLE it_where INTO is_where WITH KEY tablename = p_table.
SELECT * FROM (p_table)
INTO CORRESPONDING FIELDS OF TABLE <itab>
UP TO p_rows ROWS
WHERE (is_where-where_tab).
ENDIF.
IF sy-dbcnt = 0.
WRITE: 'No record selected'.
STOP.
ENDIF.
ENDFORM. "f_select_table
* FORM f_display_table *
FORM f_display_table.
DATA: l_answer TYPE c,
l_eflag TYPE c.
CLEAR: w_okcode.
REFRESH: <ntab>.
* Display table contents
CALL FUNCTION 'STC1_FULLSCREEN_TABLE_CONTROL'
EXPORTING
header = p_table
tabname = p_table
display_only = p_displ
endless = 'X'
no_button = space
IMPORTING
okcode = w_okcode
TABLES
* nametab = it_dfies
table = <itab>
* fielddif = it_fdiff
modif_table = <ntab>
EXCEPTIONS
OTHERS = 1.
IF sy-subrc = 0.
IF p_displ IS INITIAL AND w_okcode = 'SAVE'.
* Confirm update
CALL FUNCTION 'POPUP_TO_CONFIRM'
EXPORTING
titlebar = p_table
text_question = 'Do you want to update table ?'
default_button = '2'
display_cancel_button = ' '
IMPORTING
answer = l_answer
EXCEPTIONS
OTHERS = 1.
IF l_answer = '1'.
* Apply modifications
IF NOT <ntab>[] IS INITIAL.
PERFORM f_add_system USING space.
MODIFY (p_table) FROM TABLE <ntab>.
IF sy-subrc NE 0.
l_eflag = 'X'.
ENDIF.
ENDIF.
* Apply deletions
IF l_eflag IS INITIAL.
REFRESH: <ntab>.
CALL FUNCTION 'STC1_GET_DATA'
TABLES
deleted_data = <ntab>
EXCEPTIONS
OTHERS = 1.
IF NOT <ntab>[] IS INITIAL.
DELETE (p_table) FROM TABLE <ntab>.
IF sy-subrc NE 0.
ROLLBACK WORK.
l_eflag = 'X'.
ENDIF.
ENDIF.
ENDIF.
* Apply creations
IF l_eflag IS INITIAL.
REFRESH: <ntab>.
CALL FUNCTION 'STC1_GET_DATA'
TABLES
new_data = <ntab>
EXCEPTIONS
OTHERS = 1.
IF NOT <ntab>[] IS INITIAL.
PERFORM f_add_system USING 'X'.
INSERT (p_table) FROM TABLE <ntab>.
IF sy-subrc NE 0.
ROLLBACK WORK.
l_eflag = 'X'.
ENDIF.
ENDIF.
ENDIF.
IF l_eflag IS INITIAL.
COMMIT WORK.
MESSAGE s261(53).
ELSE.
MESSAGE s075(3i).
PERFORM f_select_table.
ENDIF.
ENDIF.
* Display table again
PERFORM f_display_table.
ENDIF.
ENDIF.
ENDFORM. "f_display_table
* FORM f_add_system *
FORM f_add_system USING new TYPE c.
FIELD-SYMBOLS: <irec> TYPE ANY,
<upd> TYPE ANY.
LOOP AT it_fdiff INTO is_fdiff.
READ TABLE it_dfies INTO is_dfies
WITH KEY fieldname = is_fdiff-fieldname.
LOOP AT <ntab> ASSIGNING <irec>.
ASSIGN COMPONENT is_fdiff-fieldname OF STRUCTURE <irec> TO <upd>.
IF is_dfies-datatype = 'CLNT'.
<upd> = sy-mandt.
ELSE.
CASE is_dfies-rollname.
WHEN 'AENAM'.
<upd> = sy-uname.
WHEN 'AEDAT' OR 'LAEDA'.
<upd> = sy-datum.
WHEN 'AETIM'.
<upd> = sy-uzeit.
WHEN OTHERS.
ENDCASE.
ENDIF.
ENDLOOP.
ENDLOOP.
ENDFORM. "f_add_system -
How to use dynamic query for Result table
Hello Experts,
I want to use dynamic query and then display the result in the assignment block.
Using dynamic query BTQAct and BTQRAct and base on some search criteria i want tofilter and then append the result in the result table of that custom context node, and then it should display the result in the view in UI.
SO can you please provide me the samplle code on how to use the dynamic query and append in the result table.
Regards.Hi,
Please find below sample code:
data: query TYPE REF TO cl_crm_bol_dquery_service,
result TYPE REF TO if_bol_bo_col.
DATA: lt_params TYPE crmt_name_value_pair_tab,
lwa_params TYPE crmt_name_value_pair.
query = cl_crm_bol_dquery_service=>get_instance( 'BTQAct' ). " Get instance of dynamic query
Set general query parameter for maximum number of hits
lwa_params-name = 'MAX_HITS' .
lwa_params-value = '50'.
APPEND lwa_params TO lt_params.
query->set_query_parameters( it_parameters = lt_params ).
query->add_selection_param( iv_attr_name = 'OBJECT_ID'
iv_sign = 'I'
iv_option = 'EQ'
iv_low = <lv_objectid>
iv_high = '' ). " Set your search criteria. Repeat this code if you have multiple parameters
"You can find possible search options for a query object in GENIL_BOL_BROWSER
result ?= query->get_query_result( ). " Get result from your search query
me->typed_context-> <your result context node>->set_collection( result ).
Here you will have to create a context node in your view which would refer to query result object like for BTQAct its BTQRAct
Hope this helps.
e Regards,
Bhushan -
Can I use table function inside Dynamic query ?
Dear Gurus,
I have following code
DECLARE
TYPE CRITERIA_LIST_TABLE AS TABLE OF VARCHAR2(20);
OtherNoList CRITERIA_LIST_TABLE; /* CRITERIA_LIST_TABLE is index by table*/
QUERY_STRING VARCHAR2(4000);
BEGIN
OtherNoList := CRITERIA_LIST_TABLE();
SELECT DISTINCT REGEXP_SUBSTR('1,5,6,4', '[^\,]+',1, LEVEL ) BULK COLLECT INTO OtherNoList
FROM DUAL
CONNECT BY LEVEL <= REGEXP_COUNT('1,5,6,4', '\,') + 1 ;
QUERY_STRING := 'INSERT INTO TAB1 (C1,C2) '||
'SELECT C1,'||
'C2 '||
'FROM TAB1 ,'||
'TABLE( '||
'CAST (OtherNoList AS CRITERIA_LIST_TABLE) '||
') OTHRNOS '||
'WHERE TAB1.C1 = OTHRNOS.COLUMN_VALUE ';
DBMS_OUTPUT.PUT_LINE('Query String is '||QUERY_STRING);
EXECUTE IMMEDIATE QUERY_STRING;
END;
Can I use Table function inside dynamic query.
Thanking in advance
SanjeevTry:
DECLARE
TYPE CRITERIA_LIST_TABLE AS TABLE OF VARCHAR2(20);
OtherNoList CRITERIA_LIST_TABLE; /* CRITERIA_LIST_TABLE is index by table*/
QUERY_STRING VARCHAR2(4000);
BEGIN
OtherNoList := CRITERIA_LIST_TABLE();
SELECT DISTINCT REGEXP_SUBSTR('1,5,6,4', '[^\,]+',1, LEVEL ) BULK COLLECT INTO OtherNoList
FROM DUAL
CONNECT BY LEVEL <= REGEXP_COUNT('1,5,6,4', '\,') + 1 ;
QUERY_STRING := 'INSERT INTO TAB1 (C1,C2) '||
'SELECT C1,'||
'C2 '||
'FROM TAB1 ,'||
'TABLE( '||
'CAST (:OtherNoList AS CRITERIA_LIST_TABLE) '||
') OTHRNOS '||
'WHERE TAB1.C1 = OTHRNOS.COLUMN_VALUE ';
DBMS_OUTPUT.PUT_LINE('Query String is '||QUERY_STRING);
EXECUTE IMMEDIATE QUERY_STRING using OtherNoList;
END;p.s. not tested
Amiel Davis -
Finding minimum value in each row using dynamic query
need to find the minimum and maximum value from each row using dynamic query
[from curr] will be given as input
TukyDECLARE @t TABLE(a INT,b INT,c INT);
INSERT @t VALUES(1,2,3),(9,8,7),(4,6,5);
SELECT *
, ( SELECT MAX(val)
FROM (VALUES (a)
, (b)
, (c)
) AS value(val)
) AS MaxVal
, ( SELECT MIN(val)
FROM (VALUES (a)
, (b)
, (c)
) AS value(val)
) AS MinVal
FROM @t;
Best Regards,Uri Dimant SQL Server MVP,
http://sqlblog.com/blogs/uri_dimant/
MS SQL optimization: MS SQL Development and Optimization
MS SQL Consulting:
Large scale of database and data cleansing
Remote DBA Services:
Improves MS SQL Database Performance
SQL Server Integration Services:
Business Intelligence -
How to use three part name with using dynamic query.
Dear all, (sqlserver 2008 express r2)
q1)following is showing error, is it possible to accomplish the task with out using dynamic query.
DECLARE @A VARCHAR(100)
DECLARE @A1 VARCHAR(100)
SET @A='DB1'
SET @A1='DBO'
SELECT * FROM @[email protected]
q2) table value function is not accepting dynamic query , is there any way to do this task.
yours sincerleyCertain parts in an SQL query like FROM tablename cannot be local variables. In such a case, dynamic SQL can be applied:
http://www.sqlusa.com/bestpractices/dynamicsql/
As noted above, more information needed to decide if dynamic SQL the correct solution in this instance.
Kalman Toth Database & OLAP Architect
SQL Server 2014 Design & Programming
New Book / Kindle: Exam 70-461 Bootcamp: Querying Microsoft SQL Server 2012 -
Converting rows to columns using dynamic query.
I am trying to use the below code that I founnd on the web to conver rows to columns. the reason that I want to use dynamic query is that the number of rows are not know and changes.
declare
lv_sql varchar2(32767) := null ;
begin
lv_sql := 'SELECT Iplineno ';
for lv_rec in (SELECT distinct vendor from bidtabs where letting = '10021200' and call ='021')
loop
lv_sql := lv_sql
|| CHR(10)
|| ', MAX( DECODE( vendor, '
|| chr(39)
|| lv_rec.vendor
|| CHR(39)
|| ', bidprice, NULL ) ) as "'
|| lv_rec.vendor
|| '" ' ;
end loop;
lv_sql := lv_sql
|| CHR(10)
|| 'FROM bidtabs where letting = ''10021200'' and call = ''021'' and lineflag = ''L'' '
|| CHR(10)
|| 'GROUP BY iplineno ;' ;
here is the result
BIDPRICE CALL IPLINENO LETTING VENDOR
9,585 021 0010 10021200 C0104
1,000 021 0020 10021200 C0104
1,000 021 0030 10021200 C0104
17 021 0040 10021200 C0104
5 021 0050 10021200 C0104
11,420 021 0010 10021200 K0054
1,100 021 0020 10021200 K0054
1,100 021 0030 10021200 K0054
5 021 0040 10021200 K0054
3 021 0050 10021200 K0054
8,010 021 0010 10021200 V070
900 021 0020 10021200 V070
1,320 021 0030 10021200 V070
11 021 0040 10021200 V070
3 021 0050 10021200 V070
and here is the desired output
CALL IPLINENO LETTING C0104 K0054 V070
021 0010 10021200 9,585 11,420 8,010
021 0020 10021200 1,000 1,100 900
021 0030 10021200 1,000 1,100 1,320
021 0040 10021200 17 5 11
021 0050 10021200 5 3 3Here is the error message I am getting:
RA-06550: line 22, column 43:
PLS-00103: Encountered the symbol "end-of-file" when expecting one of the following:
begin case declare end exception exit for goto if loop mod
null pragma raise return select update while with
<an identifier> <a double-quoted delimited-identifier>
<a bind variable> << close current delete fetch lock insert
open rollback savepoint set sql execute commit forall merge
pipe -
Created Webi report using BEx Query.
Hi All,
I am going to upgrade in BW and using BEx & Webi Report. I have created webi report using BEx query. Now I need to test data in webi report.
Can anyone tell me how to test data?
Regards,Hi,
compare the webi report data with Bex report. more you can compare webi report with SAP R3 system for random records.
Thanks,
Amit -
The new ibook app and ibook update is designed for iPhone 5 operating system. When my iPhone4 recently updated the ibook app, it created many problems using the ibook to download and read my books. Can I get the previous ibook app back on my phone.
Check your trash can on the desktop. The old version is automatically moved to the trashcan. You should be able to move it from the trashcan back to the Apps folder within the iTunes folder. The update that was pushed out was for iBooks to work with iOS 7 not iPhone 5. iOS 7 was released today.
-
Using dynamic query to create sequence
Hello,
I created the sequence dynamically in a Procedure, but when I executed, it gave me an Insufficient privileges error:
SQL> create table dummy (id number, module_id varchar2(20), p_order number, status varchar2(1));
SQL> insert into dummy values (10, 'test', 0, 'D');
SQL> CREATE OR REPLACE PROCEDURE PRO_SEQ_ARRNGE(P_ID NUMBER) AS
V_MOD DUMMY.MODULE_ID%TYPE;
v_query1 varchar2(200);
v_query2 varchar2(200);
V_COUNT NUMBER;
begin
v_query1 := 'drop sequence unqid';
v_query2 := 'create sequence unqid start with 1 increment by 1 minvalue 1';
SELECT COUNT(*)
INTO V_COUNT
FROM USER_SEQUENCES
WHERE SEQUENCE_NAME = 'UNQID';
IF V_COUNT = 0 THEN
execute immediate v_query2;
ELSE
execute immediate v_query1;
execute immediate v_query2;
END IF;
SELECT distinct MODULE_ID INTO V_MOD FROM DUMMY WHERE ID = P_ID;
update dummy
set P_order = 0, status = 'D'
WHERE ID = P_ID
and module_id = v_mod;
--COMMIT;
execute immediate 'UPDATE DUMMY SET P_ORDER = UNQID.NEXTVAL WHERE MODULE_ID = V_MOD AND STATUS = ''A''';
--COMMIT;
END PRO_SEQ_ARRNGE;
SQL> exec PRO_SEQ_ARRNGE(10);
BEGIN PRO_SEQ_ARRNGE(10); END;
ERROR at line 1:
ORA-01031: insufficient privileges
ORA-06512: at "SYSTEM.PRO_SEQ_ARRNGE", line 15
ORA-06512: at line 1
Can you please advise how to resolve it?
Thanks in advance,
TinkuWhen I try it, I get a different error
SQL> create table dummy (id number, module_id varchar2(20), p_order number, status varchar2(1));
Table created.
SQL> insert into dummy values (10, 'test', 0, 'D');
1 row created.
SQL> CREATE OR REPLACE PROCEDURE PRO_SEQ_ARRNGE(P_ID NUMBER) AS
2 V_MOD DUMMY.MODULE_ID%TYPE;
3 v_query1 varchar2(200);
4 v_query2 varchar2(200);
5 V_COUNT NUMBER;
6 begin
7 v_query1 := 'drop sequence unqid';
8 v_query2 := 'create sequence unqid start with 1 increment by 1 minvalue 1';
9 SELECT COUNT(*)
10 INTO V_COUNT
11 FROM USER_SEQUENCES
12 WHERE SEQUENCE_NAME = 'UNQID';
13
14 IF V_COUNT = 0 THEN
15 execute immediate v_query2;
16 ELSE
17 execute immediate v_query1;
18 execute immediate v_query2;
19 END IF;
20
21 SELECT distinct MODULE_ID INTO V_MOD FROM DUMMY WHERE ID = P_ID;
22
23 update dummy
24 set P_order = 0, status = 'D'
25 WHERE ID = P_ID
26 and module_id = v_mod;
27 --COMMIT;
28
29 execute immediate 'UPDATE DUMMY SET P_ORDER = UNQID.NEXTVAL WHERE MODULE_ID = V_MOD AND STATUS = ''A''';
30 --COMMIT;
31
32 END PRO_SEQ_ARRNGE;
33 /
Procedure created.
SQL> exec PRO_SEQ_ARRNGE(10);
BEGIN PRO_SEQ_ARRNGE(10); END;
ERROR at line 1:
ORA-00904: "V_MOD": invalid identifier
ORA-06512: at "SCOTT.PRO_SEQ_ARRNGE", line 29
ORA-06512: at line 1The problem is that you can't refer to a local variable like V_MOD in a dynamic SQL statement. You'd need to use a bind variable
SQL> ed
Wrote file afiedt.buf
1 CREATE OR REPLACE PROCEDURE PRO_SEQ_ARRNGE(P_ID NUMBER) AS
2 V_MOD DUMMY.MODULE_ID%TYPE;
3 v_query1 varchar2(200);
4 v_query2 varchar2(200);
5 V_COUNT NUMBER;
6 begin
7 v_query1 := 'drop sequence unqid';
8 v_query2 := 'create sequence unqid start with 1 increment by 1 minvalue 1';
9 SELECT COUNT(*)
10 INTO V_COUNT
11 FROM USER_SEQUENCES
12 WHERE SEQUENCE_NAME = 'UNQID';
13 IF V_COUNT = 0 THEN
14 execute immediate v_query2;
15 ELSE
16 execute immediate v_query1;
17 execute immediate v_query2;
18 END IF;
19 SELECT distinct MODULE_ID INTO V_MOD FROM DUMMY WHERE ID = P_ID;
20 update dummy
21 set P_order = 0, status = 'D'
22 WHERE ID = P_ID
23 and module_id = v_mod;
24 --COMMIT;
25 execute immediate 'UPDATE DUMMY SET P_ORDER = UNQID.NEXTVAL WHERE MODULE_ID = :1 AND STATUS = ''A'''
26 using v_mod;
27 --COMMIT;
28* END PRO_SEQ_ARRNGE;
29 /
Procedure created.
SQL> exec pro_seq_arrnge(10);
PL/SQL procedure successfully completed.Of course, I'm not using the SYSTEM schema. You should really, really avoid SYS and SYSTEM-- things often work differently there than they do normally. I also join the other folks that have tried to help you in suggesting that creating a sequence dynamically in a procedure is a very poor idea and almost certainly indicates that you need to reconsider your design.
Justin -
How to create olap cube using Named Query Table in Data source View
I Create on OLAP Cube using Existing Tables Its Working Fine But When i Use Named Query Table with RelationShip To other Named query Table It Not Working .So give me some deep Clarification On Olap Cube for Better Understanding
ThanksHi Pawan,
What do you mean "It Not Working"? As Kamath said, please post the detail error message, so that we can make further analysis.
In the Data Source View of a CUBE, we can define a named query. In a named query, you can specify an SQL expression to select rows and columns returned from one or more tables in one or more data sources. A named query is like any other table in a data source
view (DSV) with rows and relationships, except that the named query is based on an expression.
Reference:Define Named Queries in a Data Source View (Analysis Services)
Regards,
Charlie Liao
TechNet Community Support -
Using 2 tables framing of dynamic query wherein columns are decided runtime
Hi Team,
I had a requirement could anyone help me out or suggest your views. we are using Adf faces as UIlayer and Toplink for dataaccess. In that we had 2 tables systemdefinedTable and userdefinedTable which has one-to-one relation. Userdefinedtable has columns col1,col2,col3.......col50 and this comes at runtime from xml like col1 as Lastname,col2 as firstname.
Now we need to generate a dynamic query that joins the systemdefinedTable and userdefinedTable to produce the result for the UI layer. Now suppose if the xml has 2 cols tag.
The dynamic query may look like this:
Select S.ID, S.NAME, S.STATUS, U.COL1 as FirstName, U.COL2 as LastName
From userdefinedTable U, systemdefinedTable S
Where S.QID = U.QID
Next if the xml has 3 more column tags then COL1,COL2,COL3 ...like wise columns will be decided runtime..So please share your views or any related blogs to achieve this.
Thanks in Advance for your help.Hello,
If you are using TopLink and need dynamically generated queries, why not use TopLink Expressions for your queries, and return java objects back. Then you can display which ever fields from the fully populated objects that you need.
See the docs for TopLink queries here:
http://docs.oracle.com/cd/E17904_01/web.1111/b32441/qryun.htm#autoId28
A simple example returning all systemdefinedObjects would be:
ReadAllQuery query = new ReadAllQuery(systemdefinedObject.class);
query.addJoinedAttribute(query.getExpressionBuilder().get("user"));
Collection<systemdefinedObject> results = session.executeQuery(query);
This allows populating the cache and for caching the statements and the query results.
But I'm not sure exactly what you are after.
Best Regards,
Chris -
Create table statement in Dynamic SQL
Hello,
I am trying to create a table as a select query through a PL/SQL block using dynamic SQL. Following is the query,
declare
stmt varchar2(2000);
begin
stmt := '''CREATE TABLE output AS SELECT PATIENT_ID, FIRST_NAME FROM employee''';
execute immediate stmt;
end;
it throws the following error.
declare
ERROR at line 1:
ORA-00900: invalid SQL statement
ORA-06512: at line 5
I have tried to execute the statement without the variable and it executes fine. I mean,
begin
execute immediate ' CREATE TABLE output AS SELECT PATIENT_ID, FIRST_NAME FROM employee ';
end;
works flawlessly. Can you please help me with this.
ThanksHi,
declare
stmt varchar2(2000);
begin
stmt := 'CREATE TABLE output AS SELECT PATIENT_ID, FIRST_NAME FROM employee';
execute immediate stmt;
end;Nothing different from what Anurag has shown above.
But you will have to consider a few things.
1) Since it is possible it is not a must to use it
2) It is considered a bad design where in you have to create tables on the fly.
3) Consider if it is absolutely required.If u can give us an idea of your requirement.I am sure the Gurus here can give you suggestions
4) this kind of design will lead you into trouble sooner or later for sure
Regards,
Bhushan -
ADF table based on dynamic query
I am new in JDeveloper and ADF.
I want to add an updatable ADF table on a JSF page, but I want to use
dynamic criteria for the query on which the table will be based on.
The user will fill in some fields then press a button. Then a daynamic
where clase will be created and the table
will be populated.
How can I do this?Hi,
You should get aquainted with ViewCriteria for your ViewObject. -
Unable to retrieve results using dynamic query
Hi Experts,
I have created a custom table and have created a custom bol to integrate it with web ui. I have redefined the dynamic query result method of genil layer. I find the data into LT_RESULT but when I invoke the root list method the LR_OBJECT does not contain the values.
Please see below the code that I have written.
====================================
METHOD IF_GENIL_APPL_INTLAY~GET_DYNAMIC_QUERY_RESULT.
DATA: LR_OBJECT TYPE REF TO IF_GENIL_CONT_ROOT_OBJECT,
LT_RESULT TYPE TABLE OF ZCRMST_XXXX,
LV_DYN_WHERE TYPE STRING,
LV_LEN TYPE I,
LS_RANGE TYPE SELOPTOBJ.
DATA: LT_XXXX TYPE TABLE OF SELOPTOBJ,
LT_YYYY TYPE TABLE OF SELOPTOBJ.
FIELD-SYMBOLS: <LFS_RESULT> TYPE ZCRMST_XXXX,
<LFS_SELECTION_RANGE> TYPE GENILT_SELECTION_PARAMETER.
decomposition of selection parameters and build a dynamic where condition
SELECT * FROM ZXXXX INTO TABLE LT_RESULT[].
CHECK LINES( LT_RESULT[] ) > 0.
LOOP AT LT_RESULT[] ASSIGNING <LFS_RESULT>.
LR_OBJECT = IV_ROOT_LIST->ADD_OBJECT( IV_OBJECT_NAME = 'Root'
IS_OBJECT_KEY = <LFS_RESULT>-XXXX ).
CHECK LR_OBJECT IS BOUND.
LR_OBJECT->SET_QUERY_ROOT( ABAP_TRUE ).
ENDLOOP.
ENDMETHOD.
==================================================
Thanks in advance,Hi,
Please check your get_objects method of the genil class. I made some changes to my implementation of get_objects method and it fixed the problem.
Regards,
Sandeep
Maybe you are looking for
-
Hi all, Can anybody give me a report which shall show all POs for which GR has been done but invoice is still to be done. regards -Bansal
-
my audio is being funny on my mac. It is brand new, and hasn't had trouble since this update. It gets stuck at full blast with a / though it. then no audio comes out. Once I turn it off it fixes it self thouhgh, or if I wait a while it finally fixes
-
AR - How to split receivable account for several accounts.
Has enyone know how to split Receivable account for transaction in distribution window on 3 diffrent accounts eg. Total amount for transaction line is 5000 I have to create accounting as follow: 1st Receivable account Dt: 2000 2nd Receivable account
-
OCIStmtFetch Fails do I need to do an exec again
Here is my problem. We have a C program that goes out and retrieves data from the V$datafile view. Every once in awhile we receive an ORA-00235 error which the only remedy for this according to Oracle metalink support is to try the query again. The p
-
Can't set temp files folder or set cache size
I have a workstation that will not download files, or pick up the auto-proxy settings. Other workstations on the same network work fine, so it is not the user profile or proxy server/config. It happens to all users on this workstation, including the