Display dynamic SQL statement result
HelloIs it possible to view the sql statement in the procedure below, after that the variables are applied?
In my view, a solution would be to put the entire statement in an important variable, then use DBMS_OUTPUT. Put_line (my_large_variable) but I'm hoping to save this step.
Thanks in advance for your help,
Lou
create or replace
PROCEDURE TEST1_PROC)
p_refcur ON SYS_REFCURSOR,
p_where in VARCHAR2,
p_order_by in VARCHAR2
)
IS
v_id ci_summrpt_report_codes.id% TYPE;
v_descr ci_summrpt_report_codes.descr% TYPE;
v_valid_flag ci_summrpt_report_codes.valid_flag% TYPE;
v_order_by VARCHAR2 (100);
BEGIN
IF p_order_by IS NULL THEN
v_order_by: = NULL;
ON THE OTHER
v_order_by: = "ORDER BY". p_order_by;
END IF;
DBMS_OUTPUT. Put_line (p_where);
DBMS_OUTPUT. Put_line (v_order_by);
P_refcur OPEN FOR ' SELECT id, descr, valid_flag OF |
«(SELECT 1 AS 'ID', "A" AS "DESCR", "Y" AS "VALID_FLAG" OF THE DOUBLE ' |)»
"UNION ALL" |
"SELECT 2,"TWO","Y"OF THE DOUBLE ' |
"UNION ALL" |
"SELECT 3,"THREE"," Y "DOUBLE" |
"UNION ALL" |
SELECT 4, "FOUR", "Y" DOUBLE) ' |
p_where |
v_order_by
;
END TEST1_PROC;
In my view, a solution would be to put the entire statement in an important variable, then use DBMS_OUTPUT. Put_line (my_large_variable) but I'm hoping to save this step.
This isn't a big problem, I think, is - this? :
create or replace procedure test1_proc (p_refcur out sys_refcursor,
p_where in varchar2,
p_order_by in varchar2)
is
v_id ci_summrpt_report_codes.id%type;
v_descr ci_summrpt_report_codes.descr%type;
v_valid_flag ci_summrpt_report_codes.valid_flag%type;
v_order_by varchar2 (100);
v_stmt long;
begin
if p_order_by is null
then
v_order_by := null;
else
v_order_by := ' ORDER BY ' || p_order_by;
end if;
dbms_output.put_line (p_where);
dbms_output.put_line (v_order_by);
v_stmt :=
'SELECT id, descr, valid_flag FROM '
|| '(SELECT 1 AS "ID", ''ONE'' AS "DESCR", ''Y'' AS "VALID_FLAG" FROM DUAL '
|| 'UNION ALL '
|| 'SELECT 2, ''TWO'', ''Y'' FROM DUAL '
|| 'UNION ALL '
|| 'SELECT 3, ''THREE'',''Y'' FROM DUAL '
|| 'UNION ALL '
|| ' SELECT 4, ''FOUR'',''Y'' FROM DUAL) '
|| p_where
|| v_order_by;
dbms_output.put_line (v_stmt);
open p_refcur for v_stmt;
end test1_pro;
Tags: Database
Similar Questions
-
Zero error of iteration - the treatment of dynamic sql statements in dbms_xmlgen
Hello
I have a procedure that creates a dynamic sql v_sql
cursor v_curr is
Select *.
of btctl_msg_log;
BEGIN
Select count (*) in the v_cnt of btctl_msg_log;
IF v_cnt > 0 THEN
C1 in v_curr
LOOP
v_sql: = "' | ' SELECT * from '. C1.msg_rcrd_src_tbl_nm | |' where rowid = ' | " ' ||'' ' || C1.msg_rcrd_src_tbl_id | " ' ||'' ' ||'' ' ;
Select DBMS_XMLGEN.getXMLtype (v_sql) in the double v_xml;
gives me an error
ORA-19202: an error has occurred in the processing of XML
ORA-24333: zero number of iterations
ORA-06512: at "SYS." DBMS_XMLGEN", line 288
ORA-06512: at line 1
I don't know why is this error happening.
Any help much appreciated.881575 wrote:
HelloI have a procedure that creates a dynamic sql v_sql
cursor v_curr is
Select *.
of btctl_msg_log;BEGIN
Select count (*) in the v_cnt of btctl_msg_log;IF v_cnt > 0 THEN
C1 in v_curr
LOOP
v_sql: = "' | ' SELECT * from '. C1.msg_rcrd_src_tbl_nm | |' where rowid = ' | " ' ||'' ' || C1.msg_rcrd_src_tbl_id | " ' ||'' ' ||'' ' ;
Select DBMS_XMLGEN.getXMLtype (v_sql) in the double v_xml;gives me an error
ORA-19202: an error has occurred in the processing of XML
ORA-24333: zero number of iterations
ORA-06512: at "SYS." DBMS_XMLGEN", line 288
ORA-06512: at line 1I don't know why is this error happening.
Any help much appreciated.Standard when boards (ab) use of EXECUTE IMMEDIATE is to compose the SQL statement in a single VARCHAR2 variable
Then print the variable before passing to EXECUTE IMMEDIATE.
COPY the statement & PASTE in sqlplus to validate its correctness. -
Helps with the syntax of dynamic sql statements
Hi all
How can I pass the value of the result of my dynamic select statement to a Ref Cursor?
I try the following statement but does not work, I get this error:
ORA-00932: inconsistent data types: expected - was - ORA-06512: at
Any ideas?Procedure getItems(v_first In number, v_second In Number, arg_Cursor IN OUT CUSTOM_REF_CURSOR) is sqlString varchar(3000); Begin sqlString := 'select* from bla where o.arg_1 = :1 and arg_2 = :2'; execute immediate sqlString into arg_Cursor using v_first, v_second; End getItems;
Thank you
JohnnyPROCEDURE getitems (v_first IN NUMBER, v_second IN NUMBER, arg_cursor IN OUT sys_refcursor) IS sqlstring VARCHAR (3000); BEGIN sqlstring := 'select* from bla where o.arg_1 = :1 and arg_2 = :2'; OPEN arg_cursor FOR sqlstring USING v_first, v_second; END getitems;
-
GETTING AN ERROR - slider 'P_REFCUR' cannot be used in the OPEN dynamic SQL stat
DECLARE
create or replace procedure partial_single (p_fileid in NUMBER, p_filename IN VARCHAR2 (2000), p_temptablename IN VARCHAR2 (2000), p_temppartialtablename IN VARCHAR2 (2000), p_retval ON the NUMBER)
--)
p_fileid NUMBER;
p_filename VARCHAR2 (2000);
p_temptablename VARCHAR2 (2000);
p_temppartialtablename VARCHAR2 (2000);
p_retval NUMBER;
p_refcur types_pkg.return_cur;
v_strquery varchar2 (4000);
BEGIN
p_fileid: = 5080;
p_filename: = "TAGSUR1HM2011013111160838654.000019265";
-p_temptablename: = "TEMP_RECORDS_MED_0004";
p_temptablename: = 'TEMP_RECORDS_MED_DATE ';
p_temppartialtablename: = 'TEMP_MED_PARTIAL_RECORDS_0002 ';
p_retval: = 0;
v_strquery: = 'SELECT imsi, connectedcallingnumber, callstart MIN (calleventstarttimestamp), SUM (calleventduration), MAX (sequence_number) sequencenumber, msisdn, max (callreleasetime) callreleasetime period';
v_strquery: = v_strquery | ' A ' | p_temppartialtablename | ' GROUP BY connectedcallingnumber, imsi, msisdn';
OPEN p_refcur - GETTING AN ERROR - slider 'P_REFCUR' cannot be used in a dynamic OPEN SQL statement
FOR v_strquery;
FOR CC IN (SELECT imsi,
connectedcallingnumber,
Callstart MIN (calleventstarttimestamp),
Duration of the SUM (calleventduration),
SequenceNumber MAX (sequence_number),
MSISDN,
Max (callreleasetime) callreleasetime
OF TEMP_MED_PARTIAL_RECORDS_0002
GROUP BY connectedcallingnumber, imsi, msisdn)
LOOP
UPDATE TEMP_RECORDS_MED_DATE
SET calleventstarttimestamp = cc.callstart,
calleventduration = calleventduration + cc.duration
WHERE connectedcallingnumber = cc.connectedcallingnumber
AND imsi = cc.imsi
AND sequencenumber = cc.sequencenumber + 1
AND msisdn = cc.msisdn
AND calleventstarttimestamp = cc.callreleasetime;
IF SQL % ROWCOUNT > 0
THEN
UPDATE TEMP_MED_PARTIAL_RECORDS_0002
SET isprocessed = 1
WHERE connectedcallingnumber = cc.connectedcallingnumber
AND imsi = cc.imsi
AND msisdn = cc.msisdn;
- AND callreleasetime = cc.callreleasetime;
ON THE OTHER
UPDATE TEMP_MED_PARTIAL_RECORDS_0002
SET calleventduration = calleventduration + cc.duration
IMSI WHERE = cc.imsi
AND msisdn = cc.msisdn
AND callreleasetime = cc.callreleasetime
AND calleventduration! = cc.duration;
END IF;
END LOOP;
REMOVE FROM TEMP_MED_PARTIAL_RECORDS_0002
WHERE isprocessed = 1;
p_retval: = 0;
-VALIDATION;
/ * EXCEPTION
WHILE OTHERS
THEN
-RESTORATION;
p_retval: = 1;
p3_errorlog ("partial" p_fileid, SQLERRM, |) ':' || p_filename);
COMMIT;
*/
END;Is - what your refcursor has a return type? In this case you can not open it with dynamic SQL. Change the Refcursor as a weakly typed cursor and give it a try.
-
Char invalid when you use dynamic sql statements with cursor
Hello guys,.
I'm opening a following cursor with dynamic sql
my cursor statement isv_sql := 'SELECT OS.table_name FROM OBJECT_STATS_CONTROL OS, ALL_TABLES AT WHERE OS.analyze_flag <> ''N'' AND OS.last_analyze < sysdate -1 AND AT.last_analyzed < sysdate - 1 '||v_1||';';
I get an error messageBEGIN OPEN v_cur FOR v_sql; LOOP FETCH v_cur INTO v_tabname; ......
can any body suggest me where I'm wrong0911 invalid char
Thank youRemove the semicolon at the end:
||';' -- remove this.
-
problems with my dynamic sql statement
Hello
I'm not a pl/sql developer, but just trying to write a simple piece of pl/sql code. My intentions are simple. I want to find all tables with a specified column name, with a specific value in that column. Also, I just want to print these tables which have information in them.
I have read the documentation on oracle to find this information, but I can't seem to get this to work, and I don't see what my problem...
Here is the code I wrote.
declare
number of v_number;
sql_statement varchar2 (200);
cursor pick_table is
Select the table table_name from user_tab_columns
where upper (column_name) = upper ('md_file_id');
Start
because me in pick_table
loop
sql_statement: = ' SELECT count (*) from "| i.table_name | 'where md_file_id = 22410';
dbms_output.put_line (sql_statement);
EXECUTE IMMEDIATE sql_statement in v_number;
dbms_output.put_line ('number' | v_number);
If v_number > 0
then
dbms_output.put_line (i.table_name);
end if;
end loop;
end;
/
This works perfectly well if I try not to insert the table_name dynamically using i.table_name and a writing of the database table names in the select statement. It runs also fine if I take "v_number" information on my execute immediate command.
Of course I can't do it with logic I.
What is happening is that the procedure is pretending to hang himself.
I'd appreciate any help that can be given.
Thanks in advanceuser10869417 wrote:
...
What is happening is that the procedure is pretending to hang himself.It doesn't seem to be anything wrong with your code. It seems that you have:
has a lot of tables in your schema with the column MD_FILE_ID (perhaps having value 22410), or
(b) you have only a few tables but huge with this columnIn my test with only 1 db such table, your PL/SQL block is running almost instantly:
test@XE> test@XE> -- test@XE> drop table t; Table dropped. test@XE> create table t as 2 select 22410 md_file_id from dual; Table created. test@XE> test@XE> set timing on test@XE> test@XE> @test.sql test@XE> declare 2 v_number number; 3 sql_statement varchar2(200); 4 cursor pick_table is 5 select table_name from user_tab_columns 6 where upper(column_name) = upper('md_file_id'); 7 begin 8 for i in pick_table 9 loop 10 sql_statement := 'SELECT count(*) from ' || i.table_name || ' where md_file_id = 22410'; 11 dbms_output.put_line(sql_statement); 12 EXECUTE IMMEDIATE sql_statement into v_number; 13 dbms_output.put_line('count returned ' || v_number); 14 if v_number > 0 15 then 16 dbms_output.put_line(i.table_name); 17 end if; 18 end loop; 19 end; 20 / SELECT count(*) from T where md_file_id = 22410 count returned 1 T PL/SQL procedure successfully completed. Elapsed: 00:00:00.33 test@XE> test@XE>
which means that if you wait long enough, the pl/sql block will reach eventually up to completion.
isotope
-
execute the dynamic sql statement
Hi all
CREATE TABLE XX_OFFICE_USER_IMP ( ID NUMBER, OFFICE VARCHAR2(10 BYTE), USER_NAME VARCHAR2(10 BYTE), BANK_ACCOUNT_ID NUMBER, TRANSFERED NUMBER )
Insert into xx_office_user_imp (ID,OFFICE,USER_NAME,BANK_ACCOUNT_ID,TRANSFERED) values (421,'0000','F0000',10029,null); Insert into xx_office_user_imp (ID,OFFICE,USER_NAME,BANK_ACCOUNT_ID,TRANSFERED) values (422,'0000','F0000',10031,null); Insert into xx_office_user_imp (ID,OFFICE,USER_NAME,BANK_ACCOUNT_ID,TRANSFERED) values (423,'0000','F0000',10033,null); Insert into xx_office_user_imp (ID,OFFICE,USER_NAME,BANK_ACCOUNT_ID,TRANSFERED) values (424,'0000','F0000',10036,null); Insert into xx_office_user_imp (ID,OFFICE,USER_NAME,BANK_ACCOUNT_ID,TRANSFERED) values (425,'0000','F0000',10037,null); Insert into xx_office_user_imp (ID,OFFICE,USER_NAME,BANK_ACCOUNT_ID,TRANSFERED) values (426,'0000','F0000',10039,null); Insert into xx_office_user_imp (ID,OFFICE,USER_NAME,BANK_ACCOUNT_ID,TRANSFERED) values (427,'0000','F0000',10041,null); Insert into xx_office_user_imp (ID,OFFICE,USER_NAME,BANK_ACCOUNT_ID,TRANSFERED) values (428,'0000','F0000',10046,null); Insert into xx_office_user_imp (ID,OFFICE,USER_NAME,BANK_ACCOUNT_ID,TRANSFERED) values (429,'0000','F0000',10048,null); Insert into xx_office_user_imp (ID,OFFICE,USER_NAME,BANK_ACCOUNT_ID,TRANSFERED) values (430,'0000','F0000',10067,null); Insert into xx_office_user_imp (ID,OFFICE,USER_NAME,BANK_ACCOUNT_ID,TRANSFERED) values (431,'0000','F0000',10072,null); Insert into xx_office_user_imp (ID,OFFICE,USER_NAME,BANK_ACCOUNT_ID,TRANSFERED) values (432,'0000','F0000',10087,null); Insert into xx_office_user_imp (ID,OFFICE,USER_NAME,BANK_ACCOUNT_ID,TRANSFERED) values (433,'0000','F0000',10092,null); Insert into xx_office_user_imp (ID,OFFICE,USER_NAME,BANK_ACCOUNT_ID,TRANSFERED) values (434,'0000','F0000',10008,null); Insert into xx_office_user_imp (ID,OFFICE,USER_NAME,BANK_ACCOUNT_ID,TRANSFERED) values (435,'0000','F0000',10012,null); Insert into xx_office_user_imp (ID,OFFICE,USER_NAME,BANK_ACCOUNT_ID,TRANSFERED) values (436,'0000','F0000',10013,null); Insert into xx_office_user_imp (ID,OFFICE,USER_NAME,BANK_ACCOUNT_ID,TRANSFERED) values (437,'0000','F0000',10014,null); Insert into xx_office_user_imp (ID,OFFICE,USER_NAME,BANK_ACCOUNT_ID,TRANSFERED) values (438,'0000','F0000',10017,null); Insert into xx_office_user_imp (ID,OFFICE,USER_NAME,BANK_ACCOUNT_ID,TRANSFERED) values (439,'0000','F0000',10019,null); Insert into xx_office_user_imp (ID,OFFICE,USER_NAME,BANK_ACCOUNT_ID,TRANSFERED) values (440,'0000','F0000',10024,null); Insert into xx_office_user_imp (ID,OFFICE,USER_NAME,BANK_ACCOUNT_ID,TRANSFERED) values (441,'0000','F0000',10025,null); Insert into xx_office_user_imp (ID,OFFICE,USER_NAME,BANK_ACCOUNT_ID,TRANSFERED) values (442,'0000','F0000',10001,null); Insert into xx_office_user_imp (ID,OFFICE,USER_NAME,BANK_ACCOUNT_ID,TRANSFERED) values (443,'0000','F0000',10002,null);
CREATE TABLE XXBG_CASIER_CASH ( CASHIER VARCHAR2(32 BYTE), BANK_ACCOUNT_ID NUMBER(38,0) )
After execute the PL/SQL block I get the message:declare v_exe_grant varchar2(32767 char); begin for i in (select * from xx_office_user_imp where office = '0000') loop insert into XXBG_CASIER_CASH values (i.user_name, i.bank_account_id); v_exe_grant := 'create user ' || i.user_name || ' identified by ' || i.user_name || ';' || 'GRANT create session to ' || i.user_name || ';' || 'GRANT select on apps.XXBG_CE_STATEMENT_HEADERS_CASH to ' || i.user_name || ';' || 'GRANT SELECT ON APPS.FND_USER TO ' || i.user_name || ';' || 'GRANT SELECT ON APPS.dFND_DESCR_FLEX_COL_USAGE_TL TO ' || i.user_name || ';' || 'GRANT select on apps.fnd_descr_flex_column_usages to ' || i.user_name || ';' || 'GRANT select on apps.fnd_descriptive_flexs to ' || i.user_name || ';' || 'GRANT select on apps.fnd_descriptive_flexs_tl to ' || i.user_name || ';' || 'GRANT select on ce.ce_statement_headers to ' || i.user_name || ';' || 'GRANT SELECT ON APPS.fnd_doc_sequence_assignments TO ' || i.user_name || ';' || 'GRANT SELECT ON CE.CE_STATEMENT_HEADERS_S TO ' || i.user_name || ';' || 'GRANT EXECUTE ON APPS.XXBG_GET_NEXTVAL TO ' || i.user_name || ';' || 'GRANT SELECT ON CE.CE_STATEMENT_LINES TO ' || i.user_name || ';' || 'GRANT SELECT ON APPS.XXBG_CE_STATEMENT_LINES TO ' || i.user_name || ';' || 'GRANT select on apps.CE_BANK_ACCOUNTS to ' || i.user_name || ';' || 'GRANT SELECT ON APPS.CE_BANK_BRANCHES_V TO ' || i.user_name || ';' || 'GRANT SELECT ON CE.XXBG_CASIER_CASH TO ' || i.user_name || ';' || 'GRANT EXECUTE ON APPS.XXBG_ST TO ' || i.user_name || ';' || 'GRANT select on ce.xxbg_ce_statement_lines_detail to ' || i.user_name || ';' || 'GRANT SELECT ON APPS.ce_transaction_codes TO ' || i.user_name || ';' || 'GRANT select on ce.ce_statement_lines_s to ' || i.user_name || ';' || 'GRANT SELECT ON CE.XXBG_CE_STATEMENT_LINES_DET_SQ TO ' || i.user_name || ';' || 'GRANT select on apps.xx_pko_lines to ' || i.user_name || ';' || 'GRANT SELECT ON apps.xx_rko_lines TO ' || i.user_name || ';' || 'GRANT select on apps.XX_INVOICE_RELATIONS_CASH to ' || i.user_name || ';' || 'GRANT select on APPS.PO_VENDOR_SITES_ALL to ' || i.user_name || ';' || 'GRANT select on ap.AP_INVOICE_LINES_INTERFACE_S to ' || i.user_name || ';' || 'GRANT select on ap.AP_INVOICE_LINES_INTERFACE to ' || i.user_name || ';' || 'GRANT select on APPS.ap_distribution_set_lines_all to ' || i.user_name || ';' || 'GRANT SELECT ON APPS.AP_INVOICES_INTERFACE_S TO ' || i.user_name || ';' || 'GRANT SELECT ON APPS.AP_INVOICES_INTERFACE TO ' || i.user_name || ';' || 'GRANT SELECT ON APPS.AP_DISTRIBUTION_SETS_ALL TO ' || i.user_name || ';' || 'GRANT select on apps.ce_lookups to ' || i.user_name || ';' || 'GRANT select on ar.HZ_CUST_SITE_USES_ALL to ' || i.user_name || ';' || 'GRANT select on ar.HZ_LOCATIONS to ' || i.user_name || ';' || 'GRANT select on ar.HZ_PARTIES to ' || i.user_name || ';' || 'GRANT select on ar.HZ_PARTY_SITES to ' || i.user_name || ';' || 'GRANT SELECT ON AR.HZ_CUST_ACCT_SITES_ALL TO ' || i.user_name || ';' || 'GRANT SELECT ON AR.HZ_CUST_ACCOUNTS TO ' || i.user_name || ';' || 'GRANT SELECT ON APPS.XXBG_CLAIMS_V TO ' || i.user_name || ';' || 'GRANT select on apps.xxbg_insis_agents_v to ' || i.user_name || ';' || 'GRANT select on ce.xxbg_cash_doc_types to ' || i.user_name || ';' || 'GRANT select on AP.AP_BANK_ACCOUNTS_ALL to ' || i.user_name || ';' || 'GRANT SELECT ON AP.AP_BANK_BRANCHES TO ' || i.user_name || ';' || 'GRANT SELECT ON APPS.FND_DESCR_FLEX_CONTEXTS TO ' || i.user_name || ';' || 'GRANT SELECT ON APPS.FND_DESCR_FLEX_CONTEXTS_TL TO ' || i.user_name || ';' || 'GRANT SELECT ON APPS.AP_SUPPLIERS to ' || i.user_name || ';' || 'GRANT SELECT ON APPS.per_employees_x TO ' || i.user_name || ';' || 'GRANT SELECT ON APPS.fnd_doc_seq_categories_ap_v TO ' || i.user_name || ';' || 'GRANT SELECT ON APPS.AP_LC_INVOICE_TYPES_V to ' || i.user_name || ';' || 'GRANT SELECT ON ce.xxbg_ce_statement_lines_sq to ' || i.user_name || ';' || 'GRANT SELECT ON APPS.XXBG_STATEMENT_HEADERS_CASH to ' || i.user_name || ';' || 'GRANT SELECT ON APPS.XXBG_INSIS_POLICY_V TO ' || i.user_name || ';' || 'GRANT insert ON ce.ce_statement_lines to ' || i.user_name || ';' || 'GRANT INSERT ON CE.XXBG_CE_STATEMENT_LINES_DETAIL TO ' || i.user_name || ';' || 'GRANT INSERT ON APPS.AP_INVOICES_INTERFACE TO ' || i.user_name || ';' || 'GRANT INSERT ON APPS.AP_INVOICE_LINES_INTERFACE TO ' || i.user_name || ';' || 'GRANT INSERT ON APPS.XX_RKO_LINES TO ' || i.user_name || ';' || 'GRANT INSERT ON APPS.XX_PKO_LINES TO ' || i.user_name || ';' || 'GRANT delete on ce.xxbg_ce_statement_lines_detail to ' || i.user_name || ';' || 'GRANT update on ce.XXBG_CE_STATEMENT_LINES_DETAIL to ' || i.user_name || ';' || 'GRANT DELETE ON CE.CE_STATEMENT_LINES TO ' || i.user_name || ';' || 'GRANT INSERT ON CE.CE_STATEMENT_HEADERS TO ' || i.user_name || ';' || 'GRANT update on CE.CE_STATEMENT_HEADERS to ' || i.user_name || ';' || 'GRANT update on ce.CE_STATEMENT_LINES to ' || i.user_name || ';' || 'GRANT select on apps.XX_AGENTS_NO_V to ' || i.user_name || ';' ; execute immediate v_exe_grant; update xx_office_user_imp set transfered = 1 where id = i.id ; v_exe_grant := ''; end loop; end; /
Any ideas? I think I call correct immediate execution.Error report: ORA-00911: invalid character ORA-06512: at line 79 00911. 00000 - "invalid character" *Cause: identifiers may not start with any ASCII character other than letters and numbers. $#_ are also allowed after the first character. Identifiers enclosed by doublequotes may contain any character other than a doublequote. Alternative quotes (q'#...#') cannot use spaces, tabs, or carriage returns as delimiters. For all other contexts, consult the SQL Language Reference Manual. *Action:
DB version: 11g
Unfortunately I can't provide you the sql code of the other tables to create their... Maybe you should try without all budgets... :)
Thanks in advance,
Bahchevanov.
Edited by: bahchevanov on 11 October 2012 06:14Bahchevanov wrote:
Any ideas?Sure. EXECUTE IMMEDIATE executes a unique statement when you try to run the job. So use:
execute immediate 'create user ' || i.user_name || ' identified by ' || i.user_name; execute immediate 'GRANT create session to ' || i.user_name; execute immediate 'GRANT select on apps.XXBG_CE_STATEMENT_HEADERS_CASH to ' || i.user_name; . . .
SY.
-
insufficient privileges when using dynamic sql statements in the procedure
Hello
I use following script on oracle 10g. and get the error not enough privs. Please advice.
SQL > show user
The user is 'GRSADM '.
SQL > create or replace procedure grsadm.test_proc as
a varchar2 (2000);
Start
a: =' VIEW to CREATE or REPLACE
TEST_VIEW
IN SELECT
"FLAS" one
THE DOUBLE ';
immediately run one;
end;
Created procedure.
SQL > start
grsadm.test_proc;
end;
Start
grsadm.test_proc;
end;
Error on line 16
ORA-01031: insufficient privileges
ORA-06512: at "GRSADM. TEST_PROC', line 9
ORA-06512: at line 2
SQL > select * from session_privs
where the privilege as "VIEW %.
PRIVILEGE
----------------------------------------
CREATE A VIEW
REMOVE ANY VIEW
CREATE A MATERIALIZED VIEW
MODIFY A MATERIALIZED VIEW
REMOVE ANY MATERIALIZED VIEW
5 selected lines.
Published by: Rous Sharma on November 24, 2011 12:00GRSADM has a privilege ' CREATE (all) VIEW ' live?
And not via a role...SSM
Samir,
GRSADM is the owner of this procedure, it seems that the EXECUTE priv, that you suggested is already involved. -
How to execute dynamically generated using GR 11, 2 SQL statements?
Hello
I would like to know if it is possible to do what the following statement which is intended :
in other words, is it possible to dynamically generate and execute a select statement in a from clause?select * from (select replace('select empno from emp', '', '') from dual);
Thank you for your help,
John
Published by: 440bx 16 July 2010 15:57 modified 'create' to 'generate' to the subjectLike many I know no. in SQL. Results of your query in the FROM clause will not be transformed as another query, but just a litral value and your outer query returns this value as "select empno from emp".
But you can use dynamic sql statements in PL/SQL using EXECUTE IMMEDIATE or DBMS_SQL.
Something like that.
DECLARE dynamic_from_clause VARCHAR2(4000) := 'select empno from emp'; vReturnVal NUMBER; BEGIN EXECUTE IMMEDIATE 'SELECT * FROM ('||dynamic_from_clause||')' into vReturnVal ; END; /
Just write memory have not tested it.
-
result of a dynamic select statement in variable
I have a function that generates a dynamic sql statement. I would then take the result of this statement and insert it into a variable. I tried this
but that gives me an error on this line of code. SQL is a count (*) select and works very well. It's just how to get it in the variable which is tripping me.execute immediate strSQL USING OUT intCounter;
Thank you
Evagood error ;)
Delete the final semicolon.
Of
..... = '||p_SiteID||');';
do
..... = '||p_SiteID||')';
-
Hey everyone, I'm trying to understand how to use dynamic sql statements in Application Express. Specifically, I'm trying to write a query using substitution/bind variables. I don't know if you need a description of the application or not, but here's the query that will run in sqlplus:
There are three substitution variables, reference_id & file_id and & table_name. My basic setup is that I have a table full of table names, so I ask her to get a table name in a variable, then query this table for my data.ACCEPT file_id PROMPT "Enter the file_id (a number, e.g. 3): " -- Preliminary Query, to set table_name COLUMN reference_id_col NEW_VALUE reference_id COLUMN table_name_col NEW_VALUE table_name SELECT f.reference_id AS reference_id_col , t.reference_table AS table_name_col FROM aa_files f JOIN aa_type t ON f.file_type = t.type_id WHERE f.file_id = &file_id ; -- Main Query SELECT * FROM &table_name WHERE reference_id = &reference_id ;
I work inside the window of SQL commands to try to find the proper syntax to make this work in the APEX. I'm pretty sure that APEX does not allow the use of substitution variables, because they are one thing on the side of client SQL more right?
I'm still a student, so I'm not known and Oracle Application Express, but reading the documentation of the APEX and the Googling, I tell myself that bind variable should be able to do this for me, but I don't know how. I searched for some examples or documentation on the use of dynamic SQL statements in the APEX, but I could not find anything. I'm sure I could do this using a PL/SQL block, but I'd rather do it in pure SQL if possible.
So if someone could help me or giving me an example of syntax I would have to use to write a query that is running in Application Express, or could direct me to the literature on the use of dynamic sql statements in Application Express, it would be greatly appreciated!
If you need more information on my application, I can post my create table statements and some inserts sample data, if that would be helpful.
Thank you!
Published by: username, June 21, 2010 07:34OK, so one of the great things about SQL is your ability to choose what columns you want to include in your result set. You don't have to use all of them. You can do this in two ways: with dynamic SQL or individual areas for each type of file. This will depend on your use as to how many types different files will be added each day on which you want to go with.
If you go with dynamic SQL (and because you don't know until run time what columns you want to use, it is an appropriate use), you will need to build your query based on the file type. Something like this:
declare qry_type VARCHAR2(10); sql_qry VARCHAR2(4000); qry_select VARCHAR2(500); qry_from VARCHAR2(100); qry_where VARCHAR2(400); qry_order VARCHAR2(100); begin qry_type := :PX_QRY_TYPE; --Build the SELECT clause qry_select := 'select a.FILE_NAME, a.FILE_NAME, a.FILE_TYPE, a.LOCATION'; CASE qry_type WHEN 'PDF' THEN qry_select := qry_select || ', pdf.DATE_MODIFIED, pdf.SUMMARY, pdf.AUTHOR'; WHEN 'XLS' THEN qry_select := qry_select || ', xls.DATE_MODIFIED, xls.SUMMARY, xls.TOTAL_VALUE'; ... END CASE; --Build the FROM clause qry_from := ' from AA_FILE a, AA_FILETYPE_PDF pdf, AA_FILETYPE_XLS xls, AA_FILETYPE_PHOTO p'; --Build the WHERE clause qry_where := ' where a.FILE_ID = pdf.FILE_ID (+)'; qry_where := qry_where || ' and a.FILE_ID = xls.FILE_ID (+)'; qry_where := qry_where || ' and a.FILE_ID = p.FILE_ID (+)'; --Build the ORDER BY clause qry_order := ''; --Put it all together sql_qry := qry_select || qry_from || qry_where || qry_order; EXECUTE IMMEDIATE sql_qry; ... end;
Now this does not cover the addition of new file types. I still think you're going to be better off planning for as much as you can and handle manually creating additional tables, but this is going to be to you. I know you are trying to generate code to do everything for you, but when it comes to databases, I found that the creation of objects can quickly become uncontrolled if you're not very careful. These are going to be permanent, not temporary memory built database objects. Just a word of warning.
If you decide to go with a region and by file type, it does not require nearly as much work. Simply create a report region based on the view and set the conditional display based on your file type.
select * from V_FILES_PHOTO where FILE_ID = :PX_FILE_ID; condition: FILE_TYPE = 'PDF'
While you will need to add a region again every time that you add a new file type, once again, the question that arises is: file types how are you really going to have to worry? If you're talking about a dozen, I would like to do things manually. If you're talking about a hundred, it's maybe worth trying to find a method of programming. It is your call to make.
-
How to escape ' in dynamic sql
Dear Experts,
I'm trying to escape single quote (') in dynamic sql, but could not find a way, I used the escape character / and two single quotes "but it did not work.
Here I am trying to generate dynamic SQL statements:
SQL > select ' exec dbms_stats.gather_index_stats (ownname = > \'SYSADM\', indname = >--------"|) INAME | '--------', estimate_percent = > DBMS_STATS. AUTO_SAMPLE_SIZE);' from test_missing_index;
Select ' exec dbms_stats.gather_index_stats (ownname = > 'SYSADM', indname = > "|) INAME | ", estimate_percent = > DBMS_STATS. AUTO_SAMPLE_SIZE);' from test_missing_index
*
ERROR on line 1:
ORA-00923: THE KEYWORD not found where expected
The desired to put should be:
exec dbms_stats.gather_index_stats (ownname = > 'SYSADM', indname = > 'test_index', estimate_percent = > DBMS_STATS.) AUTO_SAMPLE_SIZE);
Any help will be much appreciatedRajasekharan Dinesh wrote:
Dear Experts,I'm trying to escape single quote (') in dynamic sql, but could not find a way, I used the escape character / and two single quotes "but it did not work.
Two single quotes (withsome kind of escape aby) is correct.
From Oracle 10, you might find easier to use Q-rating:select Q'{exec dbms_stats.gather_index_stats(ownname=>'SYSADM', indname=>'}' || iname || Q'{', estimate_percent=>DBMS_STATS.AUTO_SAMPLE_SIZE);}' from test_missing_index;
Read all about it in the manual of the SQL language. Search for "literal text".
http://download.Oracle.com/docs/CD/B28359_01/server.111/b28286/sql_elements003.htm#sthref3372 quotes using simple (in any version of Oracle), you could do it like this:
select 'exec dbms_stats.gather_index_stats(ownname=>''SYSADM'', indname=>''' || iname || ''', estimate_percent=>DBMS_STATS.AUTO_SAMPLE_SIZE);' from test_missing_index;
The string must have a right single quotation mark before inname. It will be inside a literal text, so it must be doubled. Who is be the last thing in this literal text, so the single quotes that ends the literal comes just after him, having for result 3 consecutive single quotes.
Similarly, the literal immediately after iname begins with a single quote, therefore, immediately following the single quote which begins that literal, you have 2 single quotes.Published by: Frank Kulash, October 27, 2011 19:47
-
Tables created in a stored procedure cannot be used with dynamic SQL? The impact?
There is a thread on the forum which explains how to create tables within a stored procedure (How to create a table in a stored procedure , however, it does create a table as such, but not how to use it (insert, select, update, etc.) the table in the stored procedure.) Looking around and in the light of the tests, it seems that you need to use dynamic SQL statements to execute ddl in a stored procedure in Oracle DB. In addition, it also seems that you cannot use dynamic SQL statements for reuse (insert, select, update, etc.) the table that was created in the stored procedure? Is this really the case?
If this is the case, I am afraid that if tables cannot be 'created and used"in a stored procedure using the dynamic SQL, as is the case with most of the servers of DB dynamic SQL is not a part of the implementation plan and, therefore, is quite expensive (slow). This is the case with Oracle, and if yes what is the performance impact? (Apparently, with Informix, yield loss is about 3 - 4 times, MS SQL - 4 - 5 times and so on).
In summary, tables created within a stored procedure cannot be 'used' with dynamic SQL, and if so, what is the impact of performance as such?
Thank you and best regards,
Amedeo.
Published by: AGF on March 17, 2009 10:51AGF says:
Hi, Frank.Thank you for your response. I understand that the dynamic SQL is required in this context.
Unfortunately, I am yet to discover "that seeks to" using temporary tables inside stored procedures. I'm helping a migration from MySQL to Oracle DB, and this was one of the dilemmas encountered. I'll post what is the attempt, when more.
In Oracle, we use [global temporary Tables | http://www.psoug.org/reference/OLD/gtt.html?PHPSESSID=67b3adaeaf970906c5e037b23ed380c2] aka TWG these tables need only be created once everything like a normal table, but they act differently when they are used. The data inserted in TWG will be visible at the session that inserted data, allowing you to use the table for their own temporary needs while not collide with them of all sessions. The data of the TWG will be automatically deleted (if not deleted programmatically) when a) a commit is issued or b) the session ends according to the parameter that is used during the creation of the TWG. There is no real need in Oracle to create tables dynamically in code.
I noticed that many people say that the "Creation of the tables within a stored procedure" is not a good idea, but nobody seems necessarily explain why? Think you could elaborate a little bit? Would be appreciated.
The main reason is that when you come to compile PL/SQL code on the database, all explicit references to tables in the code must correspond to an existing table, otherwise a djab error will occur. This is necessary so that Oracle can validate the columns that are referenced, the data types of those columns etc.. These compilation controls are an important element to ensure that the compiled code is as error free as possible (there is no accounting for the logic of programmers though ;)).
If you start to create tables dynamically in your PL/SQL code, so any time you want to reference this table you must ensure that you write your SQL queries dynamically too. Once you start doing this, then Oracle will not be able to validate your SQL syntax, check the types of data or SQL logic. This makes your code more difficult to write and harder to debug, because inevitably it contains errors. It also means that for example if you want to write a simple query to get that one out in a variable value (which would take a single line of SQL with static tables), you end up writing a dynamic slider all for her. Very heavy and very messy. You also get the situation in which, if you create tables dynamically in the code, you are also likely to drop tables dynamically in code. If it is a fixed table name, then in an environment multi-user, you get in a mess well when different user sessions are trying to determine if the table exists already or is the last one to use so they can drop etc. What headache! If you create tables with table names, then variable Dynamics not only make you a lot end up creating (and falling) of objects on the database, which can cause an overload on the update of the data dictionary, but how can ensure you that you clean the tables, if your code has an exception any. Indeed, you'll find yourself with redundant tables lying around on your database, may contain sensitive data that should be removed.
With the TWG, you have none of these issues.
Also, what is the impact on the performance of the dynamic SQL statements in Oracle? I read some contrasting opinions, some indicating that it is not a lot of difference between static SQL and SQL dynamic in more recent versions of Oracle DB (Re: why dynamic sql is slower than static sql is this true?)
When the query runs on the database, there will be no difference in performance because it is just a request for enforcement in the SQL engine. Performance problems may occur if your dynamic query is not binding variable in the query correctly (because this would cause difficult analysis of the query rather than sweet), and also the extra time, to dynamically write the query running.
Another risk of dynamic query is SQL injection which may result in a security risk on the database.
Good programming will have little need for the tables of dynamically created dynamically or SQL.
-
Is Hi possible to create dynamic sql statements to create a select statement
for example I have table with 50 lines, I need to contract a statemnt for all columns selection how can I do this Dynamics
Hi Alex,
Start with something like this
select 'select ' || LISTAGG(column_name, ', ') within GROUP (ORDER BY COLUMN_ID ) || ' from ' || table_name || ';' as "-- select statement" from user_tab_columns where table_name like upper ( '&1' ) group by table_name;
concerning
Kay -
Need an example of loop with sql statement in shell script values
Hello
I have to present a simultaneous program to each line of the table through script shell (only).
The table has all the parameters required to pass to the concurrent program.
I have trouble in a loop with the lines of sql statement results.
Could someone give me an example of a shell script with a loop with the sql statement values.
appreciate your time and your help.
Thank you
Ganesh
Hello
Here is a guide using 3 parameters:
{
sqlplus-s $OA_USR / $OA_PWD<>
SET THE OFF POSITION;
SET FEEDBACK OFF;
SET LINESIZE 300;
SELECT param1, param2, param3
Of your_param_table;
ENDOFSQL
} | while reading line
do
If ['$line'] # line non-NULL
then
set $line
param1 = "$1."
param2 = "$2."
param3 = "$3."
# Pass parameters to a script, sql more
sqlplus-s $apps_usr / $apps_pwd @SUBMIT_CONC_PROG.sql $param1 $param2 $param3
FI
fact
}
In your SQL * more script you run 3 parameters into variables:
declare
VARCHAR2 (10) param1: = ' & &1';
VARCHAR2 (10) param2: = ' & &2';
param3 varchar2 (10): = ' & &3';
.....
Maybe you are looking for
-
iTunes doesn't see a iTunes library?
After that Scraping and re - install OS X El Capitan 10.11.5 on my iMac Intel Core i5 to 3.1 GHz, 4 GB 1333 MHz DDR3 and pulling the files from time BU machine drive... iTunes is not recognizing the library! In any case so that it points to the last
-
Compaq CQ62-219WM showing black screen AFTER the replacement.
So I guess my question is fairly simple. When I replaced my client on their Compaq CQ62-219WM screen and it appears black. When I shine a flashlight in it, I see the start menu and whatnot. This means that I must file a RMA right? I'm guessing tha
-
Can not activate WLan on Equium A200-1VO
Here goes I just configured my router netgear dg834 g v4 on my laptop and was instructed to do this via a wired connection, as said on the installation. I now cannot turn on the wireless and I would so I don't have to use an ethernet cable.I tried th
-
Y at - it updated firmware for the m3 RX100
Sony makes updates firmware for their cameras ie; RX100 m1/2/3, like to know before you buy one. Many sites seem to believe that it is rare that their cameras updated firmware. Cheers in advance
-
* Windows ADMINISTRATOR PROBLEMS
Hello: Recently I just changed my password, I AM the ADMINISTRATOR. I also have a 'secondary' account and the different password than my administrator password. I did not write the new password correctly, or just simply, I made an error along the lin