question about pl/sql script
Hi allI need to manage other tables that will contain as follows:
whenever the user query it will be an insert in this table called mng_rishui_session that contain
track:
NUM of user's session id,
Date and time of execution of the request,
type of query
every 15 minutes, I need to delete the data of the user of some the various tables according to the type of the query.
the tables that contain the data:
mng_rishui_session / / DESC
session_id_num NOT NULL VARCHAR2 (30)
type_query not null number (2)
date of time_query
I want to write a pl/sql script like this:
declare cursor c1 as
select session_id_num,type_query
from mng_rishui_session
where time_query (/*here i need to do the condition that 15 minutes has passed from the time query
i don't know how to do this */
begin
for e in c1 loop
case e.type_query
when 1
delete query1_table where session_id_num :=e.session_id_num;
when 3
delete query3_table where session_id_num :=e.session_id_num;
end
end loop;
end;
issues related to the:1. how to check if 15 minutes where the past
2. it is good to do with loop for writing valid deletion in the loop
or do I have to do it another way to write this.
Thanks in advance
Naama
Hi, Naama,
Naama wrote:
... now my script looks like this:
mng_session. SQLdeclare cursor c1 as select session_id_num,type_query from mng_rishui_session where (sysdate - t_query) * 24 * 60 >= 15; begin for e in c1 loop case e.type_query when 1 then delete query1_table where session_id_num = e.session_id_num; when 3 then delete query3_table where session_id_num =e.session_id_num; end case; end loop; end;
first of all, I want to know where I'm going to do the validation, if I need to do.
In the PL/SQL code (so we won't do it in case of error) but after the LOOP is finished.
In other words, assuming you are using a LOOP. It will be much more effective if you just do a DELETE statement on each table. Think about it: If your mng_rishui_session has 1,000 rows where t_query (or time_query, if the column is always so called) is fortunate to have one of the type_queries you want at least 15 minutes, and 100 of these lines, then you must fetch the 1,000 rows (if not all of the table) , and separate 100 DELETE queries. It is more effective to extract 100 lines (assuming that there is an index composed of type_query and t_query) and to only 2 DELETE statements. See below.
Second:
I run this script through linux system, in order to head to sleep.
My problem is that I am trying to append the output of script;
but it won't let me
People on this site will try to help you. Why not try to help them do it?
Do not say "he won't let me": show all that you know the problem. What exactly have you tried? That's happened? If you got an error, display the full error message, including the line number. If you got the wrong results, describe what happened.
My goal is:
a script running the sql scripy called:
CS-mng-session:#!bin/bash sqlplus user/passwd@dbname @mng_session /*mng_session is the script were i declare the cursor etc.*/ in the command line i want to write : (sleep 600; sh cs-mng-session)&
the problem is that if I do not exit. He recorded in sql and the script does not return to the command line.
How do I overcome this problem?
Make an EXIT.
Try something like this:
DECLARE
cutoff_date DATE := SYSDATE - (15 / (24 * 60));
BEGIN
DELETE query1_table
WHERE session_id_num IN (
SELECT session_id_num
FROM mng_rishui_session
WHERE type_query = 1
AND t_query <= cutoff_date
);
DELETE query3_table
WHERE session_id_num IN (
SELECT session_id_num
FROM mng_rishui_session
WHERE type_query = 3
AND t_query <= cutoff_date
);
COMMIT; -- If desired
END;
/
EXIT;
Is there a reason why query1_table should be different from query3_table? Why can't you have just a query_table, with a column of type_query?
What happens if there is an error? You won't want to know? You must add an EXCEPTION section to write the details about the error in a log table and someone send an email on this subject.
Published by: Frank Kulash, August 31, 2010 09:07
Added / issue;
Tags: Database
Similar Questions
-
question about pl/sql exception
Hi all. the following text is an excerpt from the documentation of the language reference PL/SQL Oracle® database oracle 11g Release 1 (11.1):
Unhandled exceptions can also affect subroutines. If you exit a subprogram successfully, PL/SQL assigns values to parameters. However, if you come out with an unhandled exception, PL/SQL does not assign values for THE parameters (except if they are NOCOPY parameters). In addition, if a stored subprogram fails with an unhandled exception, PL/SQL does not restore database work carried out by the subprogramme of.
Note the bold text, is this true? I'm curious about it, so I wrote the following example to test.
-create a test table
CREATE TABLE e AS SELECT * FROM HR. EMPLOYEES;
-create p1 that will update a row in the table e
CREATE OR REPLACE PROCEDURE p1
IS
ex EXCEPTION;
e line % ROWTYPE;
BEGIN
Select * online e where employee_id = 100;
Row.employee_id: = 100;
Row.first_name: = 'yang ';
-updated
E UPDATE choose the LINE = line where employee_id = 100;
- and trigger an error
INVOKE;
END;
BEGIN
-call the above procedure
P1;
END;
-test update if successful
Select * e where employee_id = 100;
-the above query gives me
Steven
so my question is: am I right?Yang,
This only was not always true... ?
If a subpraogram fails and generates an unhandled exception, then it is up to the calling program decide what to do with it.
If none of the programs in the hierarchy above manipulate... then the changes are cancelled because oracle a pseudo code around the entire block similar to:
savepoint sp1; p1; if error then rollback to sp1;
-Check this example...
SQL> create table temp( 2 id number); Table created. SQL> create unique index unq_id on temp(id); Index created.
-If the program calling nt don't handle the error that the subprgram returns the error returned to Oracle and it cancels the entire transaction.
-because it's the oracle of how works the transaction...1 create or replace procedure p1(i_number in number) as 2 begin 3 insert into temp values (i_number); 4* end; SQL> / Procedure created. SQL> begin 2 p1(1); 3 p1(1); 4 end; 5 / begin * ERROR at line 1: ORA-00001: unique constraint (SCOTT.UNQ_ID) violated ORA-06512: at "SCOTT.P1", line 3 ORA-06512: at line 3 SQL> select * from temp; no rows selected
-If the calling program catches the exception... it will speak to the future course of action... commit / rollback...
In the code below, the error is ignored... and just pinted...SQL> ed Wrote file afiedt.buf 1 begin 2 p1(1); 3 p1(1); 4 exception 5 when dup_val_on_index then 6 dbms_output.put_line('duplicate value inserted...'); 7* end; SQL> / PL/SQL procedure successfully completed. SQL> select * from temp; ID ---------- 1
Hope that answers your question...
-Renon.
Published by: Rajesh Chamarthi 18 November 2009 22:57 (added for example).
-
vRA 7 - questions about the SQL installer
So we are trying on a new installation of vRA 7 in the lab environment. I installed a new SQL Server and installed SQL 2014 with all faults (standard).
During the installation process of vRA, however when I get to the validation of SQL I get this error:
- Lab - vra - iaas.ad.he - biotechnical (SQL Server: lab-sql01)
- Another instance of the component is already installed on this server.
I don't understand what this is saying. I was not supposed to install SQL?
Just do an audit of the Programs window in Control Panel. This message indicates that you tried a facility previously and there are a few artifacts on area lab - vra - iaas.ad.he - biotech
Grant
-
Question about the ImportAction script
Hello
I use FDM ERPI to load data from BSE to Planning (11.1.2.1).
I would like to use the script ImportAction in FDM only relevant data (delete accounts of class 1 to 5 for example).
So I think that I have to delete the data duiring the event StartMapProcess, isn't?
to join this event, I do the following test:
but nothing happens :-/If strEventName="StartMapProcess" Then 'Show user a message RES.PlngActionType = 2 RES.PstrActionValue = "Dans StartMapProcess " Else 'Show user a message RES.PlngActionType = 2 RES.PstrActionValue = CStr(strEventName) End If
could you please help me please?
Thank you
FannyBecause a series of events occurs during the import, the user messages will appear not unless you stop the import immediately after the message you want to display. You can test your code with writing a logfile instead.
-
Hi experts,
I try to construct a statement select, but without success...
I have a table that contains a name and a date. The name is NOT unique, it may appear with different dates.
This is the content of my table:
Select GroupName, ggs_checkpoint AUDIT_TS;
GROUP_NA AUDIT_TS
-------- -----------------------------
08:16:03.623583 M2_AKDE4 2013-07-17
08:16:03.393275 M2_AKDE2 2013-07-17
09:07:28.114293 M2_AKDE4 2013-07-17
08:16:03.623347 M2_AKDE3 2013-07-17
09:07:30.358294 M2_AKDE1 2013-07-17
09:07:30.974761 M2_AKDE2 2013-07-17
09:07:30.974773 M2_AKDE3 2013-07-17
08:16:03.623541 M2_AKDE1 2013-07-178 selected lines.
I tried not to build a select statement of the filters for each name of the one with the date of the most recent, so my result should select 4 rows, those "BOLD"
My test was as follows:
Select GroupName g1, ggs_checkpoint AUDIT_TS
where AUDIT_TS = (select max (audit_ts) in the ggs_checkpoint where GroupName = g1)
Does anyone have an idea for this select?
Use the analytical functions.
Like: -.
Select GroupName, audit_ts
BeO
Select GroupName, audit_ts, row_number() over (partition by GroupName arrested by audit_ts desc) rn
of ggs_checkpoint
) where rn = 1
/
-
A question about the order of COLUMN sqlplus and PL/SQL
Hello everyone.
I would like to ask a question about sqlplus command COLUMN that I use in order to define the length of my queries of output columns. So, for example, I run something like:
That is why any column with the name 'the market' will be composed by sqlplus as 20 characters.COLUMN market FORMAT a20
Currently I'm working on a PL/SQL script that makes this automatic procedure, in other words, instead of manually write for each column in the above COLUMN order, it uses the DBMS_SQL. He read first as input the name of the table and then inside a loop, it detects the maximum length.
For those interested, here is the Oracle documentation page that I found (example 8)
http://download.Oracle.com/docs/CD/B19306_01/AppDev.102/b14258/d_sql.htm
If everything worked well enough I managed to recover the maximum of each column in my table length, except that I don't know how to use the COLUMN sqlplus command in my PL/SQL block. I would like to do something like that (it's just a pseudo-code)
I would like to know is there a command in PL/SQL to define the appropriate column typeset in sqlplus length?FOR colIndex in 1 .. numberOfColumns LOOP currentColumnName = getColumnName(tableDescriptionObject, colIndex); currentColumnLength = getColumnLength(tableDescriptionObject, colIndex); COLUMN currentColumnName FORMAT a -- and here after 'FORMAT a' I have to write currentColumnLenth but I don't know how to proceed. END LOOP;
Thanks in advance,
DariyooshHi, Dariyoosh,
Sory, I don't think that there is a simple way to publish SQL * most orders fom PL/SQL.
PL/SQL runs in the database (back-end); There isn't any direct contact with SQL * more at the front end.The best way I know is that PL/SQL script (myfile.sql) with orders of the COLUMN, and then have SQL * more run the script (@myfile).
-
Question about OWA scripts - how much time do need to run or not at all
Just a question about OWA on Exchange 2010 scripts. I have a site and unique Exchange Server. I noticed that we have a powershell script scheduled in the Task Scheduler running daily that defines all the mailbox OWA strategy. This policy is defined in the EMC access client/organizational Configuration (EMC) tab.
My question is... If the policy is already configured in the access client/organizational Configuration tab, should this powershell script run at all? Not all new users get this strategy by default (since we have only one policy OWA) If you enable Outlook Web access on the mailbox of the user in the appearance of the mailbox tab? My thought is that the powershell script and the calendar was just a postponement of the old Exchange 2003 for strategies for the OWA...
Thank you.
Hello
Your question is beyond the scope of this community.
I suggest that repost you your Question in Exchange for TechNet Forums.
https://social.technet.Microsoft.com/forums/Office/en-us/home?category=ExchangeServer
Or here:
https://social.technet.Microsoft.com/forums/Exchange/en-us/home?Forum=exchangesvrgeneral
See you soon.
-
question about how to combine the two scripts.
HelloI have a sql script that can display a table (or view) all the information, it works fine. I call it validate_table.sql, as below:
command prompt
accept invites owner "Enter table owner:
accept invites from TABLE_NAME "Enter object (table/View...) "name:"
column owner format a10 column 'owner '.
column format a30 topic 'Object name' object_name
column object_type format a15 direction "Type of object".
Status format a10 column titled "Status".
in the heading of column created format a20 "created."
the LAST_DDL_TIME format a20, heading 'LAST_DDL_TIME.
Select
owner
object_name
object_type
status
, to_char (created, "DD_MON_YY hh24:mi:ss") created
LAST_DDL_TIME,
Of
DBA_OBJECTS
where
object_name = upper ('& table_name') and owner = upper ('& owner');
command promptprompt -- ----------------------------------------------------------------------- ---
Guest - table/view structure-
prompt -- ----------------------------------------------------------------------- ---
command prompt
describe and owner... & table table_namecommand prompt
prompt -- ----------------------------------------------------------------------- ---
guest - list assigned user/subsidies-
prompt -- ----------------------------------------------------------------------- ---
command prompt
set pagesize 50000
set linesize 10000
set verify off
Set feedback off
column lvl format A4 direction "Lvl".
proprietary format of columns A14
format column in table_name A29
A38 dealer column format
column privilege A10 format
SELECT 'Role' lvl, t.table_name, t.grantee, t.owner, t.privilege
OF dba_tab_privs t
WHERE t.grantee IN (SELECT FROM dba_roles role WHERE = role t.grantee) and t.table_name = upper ('& table_name') and t.owner = upper ('& owner')
UNION
SELECT 'User' lvl t.table_name, t.grantee, t.owner, t.privilege
OF dba_tab_privs t
WHERE t.grantee IN (SELECT username FROM dba_users WHERE username = t.grantee) and t.table_name = upper ('& table_name') and t.owner = upper ('& owner')
UNION
SELECT 'Pub' lvl, t.table_name, t.grantee, t.owner, t.privilege
OF dba_tab_privs t
WHERE t.grantee = 'PUBLIC' and t.table_name = upper ('& table_name') and t.owner = upper ('& owner')
ORDER BY 1, 2, 3;command prompt
prompt -- ----------------------------------------------------------------------- ---
guest - list of synonyms created.
prompt -- ----------------------------------------------------------------------- ---
command prompt
proprietary format of columns A15
synonym_name A20 column format
A15 table_owner column format
format column in table_name A40
DB_link A40 column formatSelect the owner, synonym_name, table_owner, table_name, DB_link from DBA_synonyms where Table_name = upper ('& table_name') stopped by the owner;
command promptprompt -- ----------------------------------------------------------------------- ---
guest - list index created-
prompt -- ----------------------------------------------------------------------- ---
command prompt
Select
table-name
index_name
index_type
nom_tablespace
status
of DBA_indexes
WHERE table_name = upper ('& table_name') and owner = upper ('& owner')
order of table_name, index_name;
command promptprompt -- ----------------------------------------------------------------------- ---
guest - list of constraints-
prompt -- ----------------------------------------------------------------------- ---
command prompt
format column in table_name A15
format of column cons_type A15
cons_name A20 column format
check_cons A25 column format
VALIDATED A20 column format
column status A10 format
last_change A20 column formatSelect
table-name
(case constraint_type
When 'P', then 'Primary Key '.
When 'R' then 'Foreign Key'
When 'C' then 'check '.
When 'U' then 'single '.
When 'o' then 'read only display '.
When 'V' then 'check the view. "
When 'H' then 'Hash expression. "
When 'F' then 'REF column.
When the of ' then 'additional logging.
cons_type end)
constraint_name cons_name
condition_de_recherche check_cons
status
VALID
last_change
of dba_constraints
where owner = upper ('& owner')
and table_name = upper ('& table_name')
order of cons_type;I have another script that allows to display the newly created tables (table, table names) in the last 24 hours.
SET SERVEROUTPUT ON;
DECLARE
CURSOR tmp_cur IS
SELECT master, object_name
FROM dba_objects
WHERE object_type in ('TABLE', 'SEE') and the owner not in ('SYS', 'SYSTEM', 'GENERAL', "XDB", "OUTLN", "SYSMAN") and last_ddl_time > sysdate - 1;
tmp_rec tmp_cur % ROWTYPE;
BEGIN
FOR tmp_rec IN tmp_cur LOOP
DBMS_OUTPUT. PUT_LINE)
tmp_rec. Owner | ' ' || tmp_rec.object_name);
END LOOP;
END;
/
The gap of the first script (validate_table.sql) is that it can only check table one by one by manual entry, then how can I combine these two scripts, to make a scipt that can check all newly created tables (not a table) in the last 24 hours?
I thank very you much in advance!
Hello
If you already know how to find the owner and all the tables created table_name recently. One thing you can do is to change all the WHERE clauses in validate_table.sql, so instead of things like
where object_name = upper ('& table_name') and owner = upper('&owner');
you say
WHERE (owner, object_name) IN
(
SELECT master, object_name
FROM dba_objects
WHERE object_type in ('TABLE', 'SEE')
AND owner NOT IN ('SYS', 'SYSTEM', 'GENERAL', "XDB", "OUTLN", "SYSMAN")
AND last_ddl_time > SYSDATE - 1
)
;
Here is another approach:
Validate_table. SQL is quite handy as it is. You may want to run this script for tables, even when you know that they are not new. Divide into 2 scripts: one called ask_and_describe_table.sql, which looks like this:
-Ask_and_Describe_Table.sql
accept invites owner "Enter table owner:
accept invites from TABLE_NAME "Enter object (table/View...) "name:"
-You can use any name path instead of d:\some_dir below:
@d:\some_dir\describe_table & owner, table_name
and the other one called Describe_Table.sql, which starts like this:
-Describe_Table.sql
DEFINE owner = & 1
DEFINE table_name = & 2
column owner format a10 column 'owner '.
...
and continues with the same exact content as validate_table.sql.
Now, to write another script (I'll call it Describe_Recent_Tables.sql):
-Describe_Recent_Tables.sql - create and run Describe_Many_Tables.sql
-Turn OFF the devices designed to help people to read the output:
SET ECHO OFF
SET FEEDBACK OFF
SET PAGESIZE 0
VERRIFY OFF SET
-Create a Describe_Many_Tables.sql:
COIL d:\some_dir\describe_many_tables.sql
SELECT ' @d:\some_dir\describe_table '
|| owner
|| ' '
|| object_name
FROM dba_objects
WHERE object_type in ('TABLE', 'SEE')
AND owner NOT IN ('SYS', 'SYSTEM', 'GENERAL', "XDB", "OUTLN", "SYSMAN")
AND last_ddl_time > SYSDATE - 1;
SPOOL OFF
-Features lighting designed to help people to read the output:
SET ECHO ON
SET FEEDBACK ON
SET PAGESIZE 50
SET VERRIFY ON
-Describe_Many_Tables.sql performance
@d:\some_dir\describe_many_tables
I guess that all of your tables have standard names (for example, start with a letter, no spaces in the name,...), which don't require quotation marks. If they could, then the same basic approach will work, but the details are a little messier.
When you want to see the information on a single table or view, no matter how old it is, driven
Ask_and_Describe_Table
or, if you do not need to question the owner of the table and the name, something like
Describe_Table SCOTT EMP
(You can find that you really need not Ask_and_Describe_Table.sql).
When you want to do this for all the tables created in the last 24 hours:
Describe_Recent_Tables
-
I have a question about my script and why Im not return desired output. Could someone please help me solve this and also let me know what I was doing wrong, why their working version vs my return empty result. Thanks in advance and have a nice day.
Mike P.
First of all, I ran this for a list of all virtual cards ovf all my virtual machines. It comes out OK but gave me too much, I was looking for something a little more specific.
Get - VM | Get-NetworkAdapter | Select-Object Parent, name, NetworkName, ConnectionState
the script above has given me all the names of VM, AdapterName, PortGroup name and the connection status of the adapter of the said
I wanted to filter this down a little more. I was looking for netowrk adapters connected to a specific NetworkName with a ConnectionState connected object. Mainly because I have another script, I want to run after the fact that would make this particular NotConnected and NoStartConnected adapter.
I thought I could do it with the following script. The script works fine without errors and filter unwanted information. However, my problem is that it does not return what it finds on the screen as the previous script. I'm missing a piece for this script that will give me the output of the screen for each card that meets the criteria. I tried out channelling to a .csv, of course, it was empty as well. I tried a failed in an echo statement after him as well.
Get - VM | Get-NetworkAdapter | where {$_.NetworkName - eq "Network 1" - and $_.} ConnectioState - eq 'Connected'}
Thanks again for your help!
You can better use the operator contains this
{$_.NetworkName -eq "Network 1" -and "Connected","NoGuestControl","StartConnected" -contains $_.ConnectionState}
It checks if the value property is present in the array of values that you give on the left side
-
Questions about scripts in ai2
Hello
Two questions about the new install script.
(1) where to find documents on the "object model" which is available for use during the writing of scripts. There the Javadocs available to all classes, getters, setters, etc that can be used?
For example, I want to write a custom rule to detect foreign keys "without columns. For some reason, this error occurs during generation DOF, but I have not found a standard rule of prior design detect these problems before the generation of DDL. So, I'm interested in knowing how to navigate through the object model to create a rule of mine (IE is it a table.getFK (.getColumns ()) use?).
(2) is it possible to use Groovy as a scripting language? If Yes, does anyone have the docs (or even draft notes) on how join as a script engine in the Data Modeler?
Thank you, BPHi BP,.
to detect foreign keys "without columns. For some reason, this error occurs during generation DDL
What version did you use to create these cases? There was such a problem in one of the pre-production versions published two years ago.
Meta definitions, you can watch datamodeler\datamodeler\xmlmetadata directory.
In fact, it is preferable to define the rule of index/constraint - you will get a clue that is used to represent the PK, UK, the FK constraints and indexes.
So for your rule, you select index/constraint as object and the next Java scrip will be your rule:
var index;{if (index.isFK () & {index.getElements () .length == 0)}
fake;
} else {}
true;
}If you remove index.isFK (control) then the rule will be valid for all PK, UK, the FK constraints and indexes.
For script engines - you can start here - https://scripting.dev.java.net/
I see groovy is supported - http://groovy.codehaus.org/JSR+223+Scripting+with+Groovy
How to install it - you can follow the instructions in the first link above, it's much easier just to copy related jar in the "ext" directory - for groovy I copied "groovy - 1.7.5.jar" (I downloaded 1.7.5 version)
in the "D:\jdk1.6.0_20\jre\lib\ext" directory on my computer. You must restart the Data Modeler - I engine script groovy as a choice in the engine drop-down list box.You must test how Groovy will return true or false for the Data Modeler - generally ordinary (not library), it is strange that you see in the example. If the library is used then the standard return is used.
Philippe
-
A question about the count of several lines of table in a PL/SQL block
Hi all
I have a problem on counting the rows from several tables in a PL/SQL block, and I would be grateful if you could kindly give me a helping hand. Here's my problem: file in Microsoft Excel (one column) I have a list of several names of tables. For each table, when the number of rows is equal to 10000 I have to call a procedure. Here's how I tried to do:
I already checked this code with tables inividual and it works. The only problem isDECLARE CURSOR tb_cursor IS WITH my_table_names AS ( SELECT 'table1' AS tbname FROM DUAL UNION SELECT 'table2' AS tbname FROM DUAL UNION SELECT 'table3' AS tbname FROM DUAL UNION SELECT 'table4' AS tbname FROM DUAL UNION . . Here I continue writing one line for each table in order . to have the table names stored in my Excel file as a table to be queried by SELECT statement . ) SELECT * FROM my_table_names; BEGIN -- Here I verify that for each table having more than 10000 lines -- I call the specified procedure which is needed FOR I IN tb_cursor LOOP DECLARE -- Here I declare a cursor for counting the number of rows CURSOR currentTableRowCounter IS SELECT COUNT(*) AS rowsNum FROM I.tbname; numberOfRows currentTableRowCounter%ROWTYPE; BEGIN OPEN currentTableRowCounter; FETCH numberOfRows INTO numberOfRows; CLOSE currentTableRowCounter; IF (numberOfRows.rowsNum > 10000) THEN -- And here I will call the procedure which has to be run END IF; END; END LOOP; END; /
Indeed, oracle considers "I.tbname" as an unknown table name (although he refers to by its exact name).. . . SELECT COUNT(*) AS rowsNum FROM I.tbname; . . .
How can I solve this problem? I mean, how to use a variable (in my example, I.tbname) as the table name in the FROM clause to query a table instead of explicitly write the name of the table?SQL> @script.sql FROM I.tbname; * ERROR at line 99: ORA-06550: line 99, column 12: PL/SQL: ORA-00942: table or view does not exist
Thanks in advance,
DariyooshReplace the following code:
DECLARE -- Here I declare a cursor for counting the number of rows CURSOR currentTableRowCounter IS SELECT COUNT(*) AS rowsNum FROM I.tbname; numberOfRows currentTableRowCounter%ROWTYPE; BEGIN OPEN currentTableRowCounter; FETCH numberOfRows INTO numberOfRows; CLOSE currentTableRowCounter; IF (numberOfRows.rowsNum > 10000) THEN -- And here I will call the procedure which has to be run END IF; END;
By the following:
Declare numberOfRows number; begin EXECUTE IMMEDIATE 'select count(*) from '||I.tbname into numberOfRows; IF (numberOfRows.rowsNum > 10000) THEN -- And here I will call the procedure which has to be run END IF; end;
Max
[My Italian blog Oracle | http://oracleitalia.wordpress.com/2010/01/10/crittografia-in-plsql-utilizzando-dbms_crypto/]Published by: Massimo Ruocchio, January 12, 2010 15:25
Added Variable Declaration -
can the run/run .sql script in another application?
Hello..
I have a problem to run my .sql script (for example: @c:\Users\test.sql) in my netbeans application. There is no problem when I want to run/run my sql query (for example: "select * from...").
But when I want to run my script, no presentation of the result. my script content my query to export to the csv file.
script: @c:\Users\test.sql
in the script:
coil c:\Users\test.csv;
' Select ' ' ' | LOT_NUMBER | « «, » » || DEVICENUMBER | « «, » » || DEVICENAME | « «, » » || STEP_NAME | « «, » » || INSERT_DATE | « «, » » || STATUS | « «, » » || DISPOSEDBY | « «, » » || ACCEPTBY | « «, » » || AVAILABLE | « «, » » || GENDISPOSITION | » » »
of RF_LOT_ON_HOLD_LIST;
spool off;
Thank you.
bunch
Yes, we know what talking about your question.
a .sql script is just a plain text file containing everything you want. The code in it can be a pure SQL statements, it may contain of the PL/SQL code, and it can also include SQL * more specific orders (keep in mind SQL * more is a tool, not a language, so that these commands are specific to this tool and other tools which can also interpret the same commands).
Not quite sure how your question relates to this blog, as this blog is showing the code that gets the data in JSON format in a jqGrid (jQuery grid?) and then exports the data in an Excel file.
What you're trying to do is to take a series of SQL * Plus and SQL statements in a text file and generate a CSV file from them.
As already mentioned, SPOOL is a SQL * more order, specific to SQL * more command line tool. The database itself has no idea what "spool" means, while passing to the database somehow does not work. I also doubt that netbeans knows what that means, either.
So, in short, how you try to do, not you cannot.
-
Running SQL scripts on different databases
Hello!
At my work we have many databases on a server. I have to make a request so that users can run the application on a selected database SQL scripts.
So my question may be separated into 2 sections:
1 - is possible to let users SQL scripts run directly from the application?
I think a database to create a page that displays the list of all the SQL scripts, that we want to use, and when you click on a specific script name in the list, it asks something like "Where the database you want to run the script?", and then, as confirmed by the user, it would show results running the script on a different page.
is 2 - possible to let users choose what database to run these scripts?
Any information would be helpful, I'm at the beginning of the project and am not sure at all about how to proceed, or if it is at all possible.
Thank you!
Fallen_Kaede wrote:
Thanks for the quick response. I confirm that we are talking about databases on a server.
The request is to "debug" to other databases. For example, be run scripts to the locks on the list, to show the different indexes on a table, etc. to help diagnose problems.
It looks like the 'users' are DBA who should use OEM/Grid Control to do so.
1 - is possible to let users SQL scripts run directly from the application?
Lol the only way to run scripts in the APEX is the use of the SQL Scripts for SQL workshop component.
The key word in your question is 'application '. SQL * more and Developer SQL are applications that allow users to run SQL scripts on the desktop. Scripts SQL is an APEX integrated application that allows developers to run SQL scripts on the web. However, there is no documented way supported for end users to run SQL scripts in a custom of APEX application that you created. Therefore, rethink your approach. Rather than create an application APEX runs scripts, you must convert the scripts in PL/SQL, APEX packages, pages, components and applications leverage features of the APEX and reports, graphics and interactivity (e.g. exploration links; timed refreshes etc.). This will give you a user experience improved, beyond what is possible using static SQL scripts.
is 2 - possible to let users choose what database to run these scripts?
The APEX applications would exist on an instance of the APEX in a database and access other databases using the database links (which can have a performance impact). It would be possible to create a LOV based on the view of the USER_DB_LINKS dictionary and use in a selection set to a global page list to provide a control to set the current context of the database. Region data sources will have to be generated dynamically in the packages of PL/SQL use the links from relevant database based on this value LOV.
-
A question about external authentication with PHP OCI8 using a portfolio store
Hello
SQL> SELECT * FROM v$version; BANNER -------------------------------------------------------------------------------- Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production PL/SQL Release 11.2.0.1.0 - Production CORE 11.2.0.1.0 Production TNS for Linux: Version 11.2.0.1.0 - Production NLSRTL Version 11.2.0.1.0 - Production SQL>
I have a question about OCI8 connection to the Oracle server via portfolio, which I understand is a good practice because we do not have to hard code the users password. I'm trying to read pages 117 and 118 of the book The Underground PHP and Oracle manual online to learn how to set up a portfolio. I proceeded by steps as explained in these two pages (except that at the end I connect, as a normal user, not a privileged user) yet, apparently PHP does not detect the user.OS: Linux Fedora Core 17 (x86_64) PHP Version: 5.4.14 Apache version (httpd): Apache/2.2.23 (Fedora)
Here's what I write in my script
the training is the name of the user that I use in my PHP scripts to connect to the oracle database and the password is mypassword (is not true, just for the purpose of this thread :)) the code above gives me the following error:)$connection = oci_connect ( "training", "", "php_ora_usr", "AL32UTF8" );
But if I also provide the password which is,Warning: oci_connect(): ORA-01005: null password given; logon denied in /var/www/html/myscript.php on line 91 Fatal error: Connection step: ORA-01005: null password given; logon denied in /var/www/html/myscript.php on line 13
Obviously it works, but at the same time, this means that my wallet is not operational.$connection = oci_connect ( "training", "mypassword", "php_ora_usr", "AL32UTF8" );
So I'll write here, step by step, how I did according to the instructions contained in the pages 117 and 118 of the above mentioned book and I would be grateful if you could kindly tell where I made the mistake (s)
The following text was performed under my oracle linux (so the dbagroup)
Step 01:_
I created and provided the password for the directory of portfolio
Step 02:_mkstore -wrl /home/oracle/wallet_dir -create
I created an entry for my oracle user that will be used in my PHP scripts to connect to oracle
user: training
password: mypassword
I also checked that the entry was actually created for my user in the portfoliomkstore -wrl "/home/oracle/wallet_dir" -createCredential php_ora_usr training mypassword
Step 03:_$ mkstore -wrl "/home/oracle/wallet_dir" -listCredential Oracle Secret Store Tool : Version 11.2.0.1.0 - Production Copyright (c) 2004, 2009, Oracle and/or its affiliates. All rights reserved. Enter wallet password: List credential (index: connect_string username) 1: php_ora_usr training $
I added the following to my $TNS_ADMIN/tnsnames.ora
Step 04_. . . php_ora_usr = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521)) (CONNECT_DATA = (SERVER = DEDICATED) (SERVICE_NAME = db02) ) ) . . .
I added the following to my $TNS_ADMIN/sqlnet.ora
_ Step 05# sqlnet.ora Network Configuration File: /u01/app/oracle/product/11.2.0/db_1/network/admin/sqlnet.ora # Generated by Oracle configuration tools. NAMES.DIRECTORY_PATH= (TNSNAMES, EZCONNECT) ADR_BASE = /u01/app/oracle WALLET_LOCATION = (SOURCE = (METHOD = FILE) (METHOD_DATA = (DIRECTORY = /home/oracle/wallet_dir) ) ) SQLNET.WALLET_OVERRIDE = TRUE SSL_CLIENT_AUTHENTICATION = FALSE SSL_VERSION = 0
The TNS_ADMIN environment variable is already set correctly in * / etc/sysconfig/httpd * so I didn't need to do something for this step
Step 06_
I gave to access Apache (as root) in the directory of portfolio (in fact, it seems that the user oracle (dba) of linux also has the required privileges to grant this access to the apache)
Step 07_# setfacl -m u:apache:rx /home/oracle/wallet_dir # setfacl -m u:apache:r /home/oracle/wallet_dir/{cwallet.sso,ewallet.p12}
Restart Apache
Step 08_# service httpd restart
Finally make a test connection using the connection string php_ora_usr which the entry was created earlier. And the test was not successful, as indicated above
The error message:$connection = oci_connect ( "training", "", "php_ora_usr", "AL32UTF8" );
I would appreciate it if you could kindly shed some light.Warning: oci_connect(): ORA-01005: null password given; logon denied in /var/www/html/myscript.php on line 91 Fatal error: Connection step: ORA-01005: null password given; logon denied in /var/www/html/myscript.php on line 13
Thanks in advance,
DariyooshThat gives a good clue to begin with. With your platform/Apache/DB, you might need different ACLs. Test directory and permissions. Check what euid your Apache runs as. Good luck.
-
A question about the REEL in sqlplus command
Hi all
I have a question about the order of the COIL and I would be grateful if you could kindly give me a helping hand. Consider the following sql script.
It works pretty well, and all the contents of the table "MyTable" is exported to the textfile "result.txt". However, sqlplus also prints the number of linesSPOOL result.txt SELECT * FROM mytable; SPOOL OFF;
Print after each query. So after you run this script, the end of the file, I always have a line like
How can I avoid this line (the number of returned rows) in my output file?... "20541 lines returned"
Thanks in advance,
DariyooshType this command prior to winding.
set feedback off
Kind regards
Prazy
Maybe you are looking for
-
black bar more close, minimize and full page.
Even so, the close, minimize and full symbols page still work, they are hidden by a black bar in the upper right of the screen. This showed up a couple of days. I've just updated to Firefox 30.0, but it does not eliminate the black bar.
-
I can't install the drivers for the modem braodband on a ProBook 6475 b at work. I tried the "Ericson pilots Mobile Broadband' and the ' Sierra Wireless Driver Package for add-on unit high flow Mobile HP un2430" listed for this model in the download
-
HP 2009 m: adjustment of brightness of the screen
my monitor went Dim... do not understand the controls on the front of the monitor. can get the menu up, but don't know how to access and manipulate the shown topics. I'm trying to adjust the brightness on the monitor. need basic help cause I am not t
-
EventID: 1206 Event Source: Active Directory Web Services ADWS failed to determine whether the computer is a global catalog server. What will be the solution for this.
-
Do it programmatically detecting bluetooth and file transfer
Hi BB developers,. I need to know how to programmatically detect bluetooth and file transfer, can be done in blackberry, if there is no article or code, it will be a great help. Thank you all for your support SujithRavindran