Recordset SQL variable
Hi,
I'm implementing an ASP Javascript page where the items in a
database are returned and sorted based on the results of a
drop-down function. I have it working as follows:
var Recordset1__MMColParam = "Cutting";
if (String(Request("MM_EmptyValue")) != "undefined"
String(Request("MM_EmptyValue")) != "") {
Recordset1__MMColParam = String(Request("MM_EmptyValue"));
%>
<SCRIPT RUNAT=SERVER LANGUAGE=VBSCRIPT>
if not isempty(request("Select")) then
select case request("Select")
case "Brand"
sql="SELECT * FROM Products WHERE Department = ? ORDER BY
Brand;"
case "High"
sql="SELECT * FROM Products WHERE Department = ? ORDER BY
Our_Price DESC;"
case "Low"
sql="SELECT * FROM Products WHERE Department = ? ORDER BY
Our_Price ASC;"
end select
else
sql="SELECT * FROM Products WHERE Department = ? ORDER BY
special_sort ASC;"
end if
</script>
<%
var Recordset1_cmd = Server.CreateObject ("ADODB.Command");
Recordset1_cmd.ActiveConnection = MM_stark_and_whyte_STRING;
Recordset1_cmd.CommandText = "SELECT * FROM Products;"
Recordset1_cmd.CommandText = sql;
Recordset1_cmd.Prepared = true;
Recordset1_cmd.Parameters.Append(Recordset1_cmd.CreateParameter("param1",
200, 1, 255, Recordset1__MMColParam)); // adVarChar
var Recordset1 = Recordset1_cmd.Execute();
var Recordset1_numRows = 0;
%>
The issue is the line in bold, setting the SQL statement to
be a variable statement where all the parameters are resolved
outside of Dreamweaver, except for the Department, which is defined
by MMColParam. When setting
Recordset1_cmd.CommandText = sql, Dreamweaver no longer
displays the Recordset1 in the Server Behaviour window and all the
server behaviours on the page have a red exclamation mark --
however, the page itself works perfectly (including all server
behaviours). Since I no longer see the Recordset in the server
behaviour window or in the Bindings tab, I can't add new behaviours
or add new bindings to the page (without hand-coding it).
Any ideas?
Neal.
MacGyver_971 wrote:
> That's kinda silly. There are many things you cannot do
within the Recordset
> dialog box, and it hasn't changed in years either. Add
to that, I've tried
> (unsuccessfully) to install the updated ADDT for CS4,
which may give me
> additional flexibility, but DW simply crashes when that
extension is installed.
ADDT is not yet compatible with CS4. I've heard others
mention early 2009 was when it would be released, but no news
recently.
> So how are we supposed to create something relatively
simple within
> Dreamweaver like sort a database based on the results of
a drop-down list box
> -- without breaking DW?
It's easy to filter a column value from a form field,
however, Dreamweaver seems to not be able to handle dynamic column
names (which you're doing) or even dynamic sort orders. And I'm
sure there are a number of other things that DW will potentially
choke on. As long as you end up with valid SQL, the generated
recordset can be used, but as you've seen the recordset may not be
available in the Server Behaviors panel, or in the bindings panel.
Here's a suggestion:
1. Copy your recordset opening code block. From your earlier
post:
<%
var Recordset1_cmd = Server.CreateObject ("ADODB.Command");
Recordset1_cmd.ActiveConnection = MM_stark_and_whyte_STRING;
Recordset1_cmd.CommandText = "SELECT * FROM Products;"
Recordset1_cmd.CommandText = sql;
Recordset1_cmd.Prepared = true;
Recordset1_cmd.Parameters.Append(Recordset1_cmd.CreateParameter("param1",
200,
1, 255, Recordset1__MMColParam)); // adVarChar
var Recordset1 = Recordset1_cmd.Execute();
var Recordset1_numRows = 0;
%>
2. Paste that code immediately after the code block you
copied.
3. Delete the line with your sql variable.
4. Then comment out the code by adding /* at the beginning
and */ at the end. Like so:
<%
var Recordset1_cmd = Server.CreateObject ("ADODB.Command");
Recordset1_cmd.ActiveConnection = MM_stark_and_whyte_STRING;
Recordset1_cmd.CommandText = "SELECT * FROM Products;"
Recordset1_cmd.Prepared = true;
Recordset1_cmd.Parameters.Append(Recordset1_cmd.CreateParameter("param1",
200,
1, 255, Recordset1__MMColParam)); // adVarChar
var Recordset1 = Recordset1_cmd.Execute();
var Recordset1_numRows = 0;
%>
That should allow you to have DW recognize the recordset from
the commented out code block and not the one that you're generating
dynamically.
In a quick test locally, that seemed to work fine for ASP
JavaScript. For others listening in, ASP VBScript may not work out
so well as it doesn't allow for multi-line comments (that I'm aware
of), and you may run into issues with re-dimmed variables, so play
around with commenting out some lines and maybe you'll find a combo
that works.
Danilo Celic
|
http://blog.extensioneering.com/
| WebAssist Extensioneer
| Adobe Community Expert
Similar Messages
-
How to read a whole text file into a pl/sql variable?
Hi, I need to read an entire text file--which actually contains an email message extracted from a content management system-- into a variable in a pl/sql package, so I can insert some information from the database and then send the email. I want to read the whole text file in one shot, not just one line at a time. Shoud I use Utl_File.Get_Raw or is there another more appropriate way to do this?
how to read a whole text file into a pl/sql variable?
your_clob_variable := dbms_xslprocessor.read2clob('YOUR_DIRECTORY','YOUR_FILE');
.... -
Using sql:variable in an insert statement
I'm writing an insert statement for a table with an XML column. Most of the XML is static, but I need to replace the value of an element with the value of a T-SQL variable, as shown here:
CREATE TABLE [dbo].[OrderDetail](
[OrderID] [int] NULL,
[OrderDetail] [xml] NULL
GO
DECLARE @XMLData XML;
DECLARE @ItemID INT;
SET @ItemID = 1000;
SELECT @XMLData = N'
<OrderDetail xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
</OrderDetail>
SET @XMLData.modify('insert <ItemID>[sql:variable("@ItemID")]</ItemID> into (/OrderDetail)[1]')
INSERT INTO [dbo].[OrderDetail] ([OrderID], [OrderDetail])
VALUES (@ItemID, @XMLData);
When I run this, it inserts "[sql:variable("@ItemID")]" instead of the value of @ItemID. If someone could show me the proper syntax, I would really appreciate it. Thanks.Yes, that worked. Now I want to change it a little. I also have an attribute that I need to update with the value of a variable.
DECLARE @XMLData XML;
DECLARE @SetID INT;
DECLARE @SetIDStr VARCHAR(12);
DECLARE @SetIDXML XML;
SET @SetID = 9999;
SET @SetIDStr = CONVERT(VARCHAR(12), @SetID);
SET @SetIDXML = CONVERT(XML, @SetIDStr);
SELECT @XMLData = N'
<OrderDetail xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<ItemID>1000</ItemID>
<RightOperand ID="15524" Name="ItemName" Value="15524" />
</OrderDetail>
SET @XMLData.modify('replace value of (/OrderDetail/RightOperand/@ID)[1] with sql:variable("@SetIDXML")');
INSERT INTO [dbo].[OrderDetail] ([OrderID], [OrderDetail])
VALUES (@SetID, @XMLData);
SELECT * FROM [dbo].[OrderDetail];
I'm trying to replace "ID="15524"" with the value of @SetID. This code throws an exception:
Msg 9342, Level 16, State 1, Line 23
XQuery [modify()]: An XML instance is only supported as the direct source of an insert using sql:column/sql:variable.
Thanks again for your help. -
Populate the current os directory in a SQL variable
Hello, I need to populate a SQL variable in a script with the current OS directory I am working from. This is a windows environment and I am using oracle version 9.2.0.1. I know if you do SQL>$cd it will execute a cd like you are at the dos prompt. Is there a way to put this into a SQL variable? This is a SQL*Plus script.
Thank you.I have a tech support incident ongoing with ADC about this. People are away for the holidays, but so far I have been able to confirm that PackageMaker itself can't do this, as the name of the current user isn't available, nor do paths to the current Home directory work.
The only way is to have PackageMaker launch a preinstall shell or Applescript that does the "mv <item1> <item2>" or similar (the argument $1 that gets passed to these preinstall scripts IS the name of the user doing the install, so you can get the path to his home directory).
The problem THEN becomes, PackageMaker will not build a package that contains only scripts - it HAS to have some "payload" or you will get a build error. So the ultimate kludge would be to have it run the preinstall script, give it a bogus payload (empty file, etc) to install in e.g., /Library or /Applications, then have the postinstall script delete that bogus payload. I have not tried this so I do not know if it would work.
I am thinking now, with the extremely confusing and apparently contradictory rules that PackageMaker has, that the best way to install software is just to wrap a shell script in an Applescript Application Bundle wrapper (because you can't double-click a shell script without launching Terminal, so to have the user run a shell script you need to wrap it in Automator or AppleScript or a Cocoa app wrapper) and have the shell script do the copying of the files that you need. This still might result in the shell script trying to get some sort of permission (either sudo or that "Override user/group for xxx?" message).
I have read the rules on permissions for Packages about 1,017 times and they still make absolutely no sense to me, and I understand Unix permissions completely. All they would have to do is give some examples, but they don't. -
How to run recordset SQL query in FORM DATA event
How can I run recordset SQL query in FORM DATA event upon clicking on Add button in the document?
Hi Slamet,
When you receive a form data event you have a class containing inside it a ObjectKeys xml info regarding the object added/modified,...
With the objects keys you can then use the DI API method called GetByKeys to obtain the DI Object.
There is some information about it in the SDK Help file, mainly in the "FormDataEvent" class definition:
<i>The event provides the unique ID (BusinessObjectInfo.ObjectKey) of the modified business object. You can use the value of this property as an input parameter in the DI API DataBrowser.GetByKeys method to get a DI object.</i>
Pay attention you don't have this information in the Before=True event of the Add as it is not yet in the database.
Hope it helps
Trinidad. -
Sql:variable and XML query performance
Can someone help with sql:variable() in xml queries? It seems that when I attempt to reference variables with the sql:variable(...) function in an xpath function (exist or nodes) it comes up with a totally different query plan, possibly ignoring
my secondary indices like the ones for VALUE, PATH.
But if I replace sql:variable("@p_ObjectIdentifierForReference") with the literal (ie. "ord/p/ord0616.p") then it uses secondary indices more consistently.
Below you will see an unsuccessful attempt to get the query to "OPTIMIZE FOR" a specific literal value of @p_ObjectIdentifierForReference. But this doesn't give work. It doesn't give me a plan using the secondary index I expect.
Ideally there would be a way to get the sql:variable(...) function to give the same query plan as a literal. Not sure why that isn't the default behavior.
DECLARE
@p_ObjectIdentifierForReference
varchar(500);
SET
@p_ObjectIdentifierForReference
= 'ord/p/ord0616.p';
WITH
XMLNAMESPACES ('uri:schemas-progress-com:XREFD:0004'
as D)
SELECT
XREF_FileDataReference.XREF_FileData
AS XrefFileData,
InnerRowNode.value('/D:Reference[1]/D:File-num[1]',
'int')
AS FileNumber,
InnerRowNode.value('/D:Reference[1]/D:Line-num[1]',
'int')
AS LineNumber
FROM
(SELECT
XREF.XREF_FileData.XREF_FileData,
XREF.XREF_FileData.XREF_FileEntry,
InnerRow.query('.')
AS InnerRowNode
FROM
XREF.XREF_FileData
OUTER APPLY
DataXref.nodes('/D:Cross-reference/D:Source/D:Reference[@Object-identifier = sql:variable("@p_ObjectIdentifierForReference")
and @Reference-type = "RUN"]')
as T(InnerRow)
WHERE DataXref.exist('/D:Cross-reference/D:Source/D:Reference[@Object-identifier
= sql:variable("@p_ObjectIdentifierForReference") and @Reference-type = "RUN"]')
= 1)
AS XREF_FileDataReference
INNER
JOIN XREF.XREF_MemberBuilt
ON XREF_MemberBuilt.XREF_FileData
= XREF_FileDataReference.XREF_FileData
INNER
JOIN XREF.XREF_FileEntry
ON XREF_FileEntry.XREF_FileEntry
= XREF_FileDataReference.XREF_FileEntry
WHERE
XREF_MemberBuilt.XREF_ProjectBuilt
= 69
OPTION(RECOMPILE,
OPTIMIZE FOR (@p_ObjectIdentifierForReference
= 'ord/p/ord0616.p')I tried to create a "repro" of your query so we can work on it and try and improve it, but I got the best results by just adding text() and [1] to it, eg
SELECT
XREF_FileDataReference.XREF_FileData AS XrefFileData,
InnerRowNode.value('(/D:Reference/D:File-num/text())[1]', 'int') AS FileNumber,
InnerRowNode.value('(/D:Reference/D:Line-num/text())[1]', 'int') AS LineNumber
FROM (
In my main repro, even with a large piece of xml with 100,000 elements, there still wasn't much difference between the queries:
USE tempdb
GO
IF NOT EXISTS ( SELECT * FROM sys.schemas WHERE name = 'XREF' )
EXEC( 'CREATE SCHEMA XREF' )
GO
IF OBJECT_ID('XREF.XREF_FileData') IS NOT NULL DROP TABLE XREF.XREF_FileData
CREATE TABLE XREF.XREF_FileData
rowId INT IDENTITY,
DataXref XML,
XREF_FileData INT,
XREF_FileEntry INT,
CONSTRAINT PK_XREF_FileData PRIMARY KEY ( rowId )
GO
IF OBJECT_ID('XREF.XREF_MemberBuilt') IS NOT NULL DROP TABLE XREF.XREF_MemberBuilt
CREATE TABLE XREF.XREF_MemberBuilt
XREF_ProjectBuilt INT,
XREF_FileData INT
GO
IF OBJECT_ID('XREF.XREF_FileEntry') IS NOT NULL DROP TABLE XREF.XREF_FileEntry
CREATE TABLE XREF.XREF_FileEntry
XREF_FileEntry INT
GO
-- Create larger piece of xml for repro
;WITH XMLNAMESPACES ( DEFAULT 'uri:schemas-progress-com:XREFD:0004' ), cte AS (
SELECT TOP 100000 ROW_NUMBER() OVER ( ORDER BY ( SELECT 1 ) ) rn
FROM master.sys.columns c1
CROSS JOIN master.sys.columns c2
CROSS JOIN master.sys.columns c3
INSERT INTO XREF.XREF_FileData ( DataXref, XREF_FileData, XREF_FileEntry )
SELECT
SELECT
CASE rn WHEN 9999 THEN 'ord/p/ord0616.p' ELSE CAST( rn AS VARCHAR(20) ) END AS "@Object-identifier",
'RUN' AS "@Reference-type",
SELECT
rn AS "File-num",
rn * 10 AS "Line-num"
FOR XML PATH(''), TYPE
) AS "*"
FROM cte
FOR XML PATH('Reference'), ROOT('Source'), TYPE
).query('<Cross-reference xmlns="uri:schemas-progress-com:XREFD:0004">{.}</Cross-reference>'), 1, 100
INSERT INTO XREF.XREF_FileEntry ( XREF_FileEntry )
VALUES ( 100 )
INSERT INTO XREF.XREF_MemberBuilt ( XREF_ProjectBuilt, XREF_FileData )
VALUES ( 69, 1 )
GO
--SELECT * FROM XREF.XREF_FileData
--SELECT * FROM XREF.XREF_FileEntry
--SELECT * FROM XREF.XREF_MemberBuilt
--GO
-- Add primary XML index
CREATE PRIMARY XML INDEX xidx_XREF_FileData ON XREF.XREF_FileData (DataXref)
GO
-- Add value, property and path xml indexes
CREATE XML INDEX xvalidx_XREF_FileData ON XREF.XREF_FileData (DataXref)
USING XML INDEX xidx_XREF_FileData FOR VALUE
CREATE XML INDEX xpthidx_XREF_FileData ON XREF.XREF_FileData (DataXref)
USING XML INDEX xidx_XREF_FileData FOR PATH
CREATE XML INDEX xprpidx_XREF_FileData ON XREF.XREF_FileData (DataXref)
USING XML INDEX xidx_XREF_FileData FOR PROPERTY
GO
:exit
DBCC DROPCLEANBUFFERS
DBCC FREEPROCCACHE
GO
DECLARE @p_ObjectIdentifierForReference varchar(500);
SET @p_ObjectIdentifierForReference = 'ord/p/ord0616.p';
;WITH XMLNAMESPACES ('uri:schemas-progress-com:XREFD:0004' as D)
SELECT
XREF_FileDataReference.XREF_FileData AS XrefFileData,
InnerRowNode.value('/D:Reference[1]/D:File-num[1]', 'int') AS FileNumber,
InnerRowNode.value('/D:Reference[1]/D:Line-num[1]', 'int') AS LineNumber
FROM (
SELECT
XREF.XREF_FileData.XREF_FileData,
XREF.XREF_FileData.XREF_FileEntry,
InnerRow.query('.') AS InnerRowNode
FROM XREF.XREF_FileData
OUTER APPLY DataXref.nodes('/D:Cross-reference/D:Source/D:Reference[@Object-identifier = sql:variable("@p_ObjectIdentifierForReference") and @Reference-type = "RUN"]') as T(InnerRow)
WHERE DataXref.exist('/D:Cross-reference/D:Source/D:Reference[@Object-identifier = sql:variable("@p_ObjectIdentifierForReference") and @Reference-type = "RUN"]') = 1
) AS XREF_FileDataReference
INNER JOIN XREF.XREF_MemberBuilt ON XREF_MemberBuilt.XREF_FileData = XREF_FileDataReference.XREF_FileData
INNER JOIN XREF.XREF_FileEntry ON XREF_FileEntry.XREF_FileEntry = XREF_FileDataReference.XREF_FileEntry
WHERE XREF_MemberBuilt.XREF_ProjectBuilt = 69
OPTION( RECOMPILE, OPTIMIZE FOR (@p_ObjectIdentifierForReference = 'ord/p/ord0616.p') )
GO
DBCC DROPCLEANBUFFERS
DBCC FREEPROCCACHE
GO
DECLARE @p_ObjectIdentifierForReference varchar(500);
SET @p_ObjectIdentifierForReference = 'ord/p/ord0616.p';
;WITH XMLNAMESPACES ('uri:schemas-progress-com:XREFD:0004' as D)
SELECT
XREF_FileDataReference.XREF_FileData AS XrefFileData,
InnerRowNode.value('(/D:Reference/D:File-num/text())[1]', 'int') AS FileNumber,
InnerRowNode.value('(/D:Reference/D:Line-num/text())[1]', 'int') AS LineNumber
FROM (
SELECT
XREF.XREF_FileData.XREF_FileData,
XREF.XREF_FileData.XREF_FileEntry,
InnerRow.query('.') AS InnerRowNode
FROM XREF.XREF_FileData
OUTER APPLY DataXref.nodes('/D:Cross-reference/D:Source/D:Reference[@Object-identifier = sql:variable("@p_ObjectIdentifierForReference") and @Reference-type = "RUN"]') as T(InnerRow)
WHERE DataXref.exist('/D:Cross-reference/D:Source/D:Reference[@Object-identifier = sql:variable("@p_ObjectIdentifierForReference") and @Reference-type = "RUN"]') = 1
) AS XREF_FileDataReference
INNER JOIN XREF.XREF_MemberBuilt ON XREF_MemberBuilt.XREF_FileData = XREF_FileDataReference.XREF_FileData
INNER JOIN XREF.XREF_FileEntry ON XREF_FileEntry.XREF_FileEntry = XREF_FileDataReference.XREF_FileEntry
WHERE XREF_MemberBuilt.XREF_ProjectBuilt = 69
OPTION( RECOMPILE, OPTIMIZE FOR (@p_ObjectIdentifierForReference = 'ord/p/ord0616.p') )
GO
So I guess I'm saying I cannot reproduce your problem on SQL 2008 R2 or SQL 2012. Does anything about this repro stand out as different from your situation?
Looking at your query I would say you might consider the following:
are you really seeing big differences in query duration?
pretty much ignore estimated plan costs for xml queries
consider breaking it up; eg carve off the xml then do the joins? If poor cardinality estimation is part of the problem this might help
Understand what PATH, PROPERTY and VALUE are for, then only create the ones you need
do you really have the range of queries that requires all three?
this is still a great article on xml indexes:
http://technet.microsoft.com/en-us/library/ms191497.aspx
What's performance like with the primary xml index only?
If performance is that important, consider materialising the columns permanently
I think the buffer_descriptors stuff is a distraction - mostly your cache is warm right?
plan forcing could be a last resort
Selective XML indexes in SQL 2012 onwards are great : ) much less storage required for example but much more specific -
Generic reporting on SQL variables using sqlgls() /Pro*C
Generic reporting on host/SQL variables using sqlgls()
I use sqlgls() in Pro*C 8.1.7 to get the last SQL statement that was parsed.
It returns something like this.
"select distinct QTY ,CHAPTER into :b0:b1,:b2:b3 from PT ,PU ,UIN U ,EU where (PART=:b4 and PU.PART=:b5) ....."
I would like to see what the values are for each input variable e.g :b4 and :b5
Is there any generic way of reporting what these values are rather than explicity writing code for each individual SQL statement?
Is there a Pro*C method that gets the values of :b4 and :b5??
We are recording the last SQL statement to a text file but cannot see what the values are that caused the SQL query to fail.
Please contact me at [email protected]My answer is only for 1. problem (about ORA-01458)
I think that you use declaration for cursor C0 with a varchar
variable before you ininitialize length (member .len of varchar
structure) of this variable.
It's famous that many errors come from uninitialized varchar
variables in Pro*C. -
Load a table in a PL/SQL variable
Hi!
I'm using Oracle 8i and I'm interested in load a table from my database in a PL/SQL variable.In addition,I'm using Nested Table Type for loading a database table in a variable.When I load the table in the variable, I try doing a SQL query to the variable (is a nested table) but it doesn't work.There is some solution?
In the following lines there is an example about what I'm trying:
PACKAGE Types AS
TYPE cursor_type IS REF CURSOR;
END Types;
CREATE TABLE EXAMPLE(
ID NUMBER(4),
VAL Number(3)
CREATE or replace TYPE My_Row_Type AS OBJECT
ID NUMBER(4),
NStreet Number(3)
CREATE OR REPLACE PACKAGE PROVA AS
TYPE My_Tab_Type IS TABLE OF My_Row_Type;
PROCEDURE GetEXAMPLE (p_recordset OUT types.cursor_type);
END PROVA;
CREATE OR REPLACE PACKAGE BODY PROVA AS
PROCEDURE GetEXAMPLE (p_recordset OUT types.cursor_type) AS
v_tab My_Tab_Type := My_Tab_Type();
BEGIN
FOR cur_row IN (SELECT * FROM EXAMPLE) LOOP
v_tab.extend;
v_tab(v_tab.Last) := My_Row_Type(cur_row.ID, cur_row.NStreet);
END LOOP;
-- Open REF CURSOR for outout.
OPEN p_recordset FOR
SELECT *
FROM Table(Cast(v_tab As My_Tab_Type));
END GetEXAMPLE ;
END PROVA;
When I execute the procedure GetEXAMPLE, Oracle shows me the following error:
ERROR en línea 1:
ORA-00600: código de error interno, argumentos: [15419], [severe error during
PL/SQL execution], [], [], [], [], [], []
ORA-06544: PL/SQL: error interno, argumentos: [pfrrun.c:pfrbnd1()], [], [], [],
ORA-06553: PLS-801: error interno [0]Create your My_Tab_Type as a SQL Object Type, instead of a PL/SQL Table Type:
SQL> CREATE TABLE example
2 (id NUMBER (4),
3 nstreet NUMBER (3))
4 /
Table created.
SQL> INSERT INTO example VALUES (1234, 123)
2 /
1 row created.
SQL> INSERT INTO example VALUES (2345, 234)
2 /
1 row created.
SQL> COMMIT
2 /
Commit complete.
SQL> CREATE OR REPLACE TYPE My_Row_Type AS OBJECT
2 (id NUMBER (4),
3 nstreet NUMBER (3));
4 /
Type created.
SQL> CREATE OR REPLACE TYPE My_Tab_Type AS TABLE OF My_Row_Type;
2 /
Type created.
SQL> CREATE OR REPLACE PACKAGE types
2 AS
3 TYPE cursor_type IS REF CURSOR;
4 END types;
5 /
Package created.
SQL> CREATE OR REPLACE PACKAGE prova
2 AS
3 PROCEDURE GetExample
4 (p_recordset OUT types.cursor_type);
5 END prova;
6 /
Package created.
SQL> SHOW ERRORS
No errors.
SQL> CREATE OR REPLACE PACKAGE BODY prova
2 AS
3 PROCEDURE GetExample
4 (p_recordset OUT types.cursor_type)
5 AS
6 v_tab My_Tab_Type := My_Tab_Type();
7 BEGIN
8 FOR cur_row IN (SELECT * FROM example) LOOP
9 v_tab.EXTEND;
10 v_tab(v_tab.LAST) := My_Row_Type(cur_row.id, cur_row.nstreet);
11 END LOOP;
12 -- Open REF CURSOR for output.
13 OPEN p_recordset FOR
14 SELECT *
15 FROM TABLE(CAST(v_tab AS My_Tab_Type));
16 END GetExample;
17 END prova;
18 /
Package body created.
SQL> SHOW ERRORS
No errors.
SQL> VARIABLE g_ref REFCURSOR
SQL> EXEC prova.GetExample (:g_ref)
PL/SQL procedure successfully completed.
SQL> PRINT g_ref
ID NSTREET
1234 123
2345 234
2 rows selected. -
Passing Pl/Sql variables into shell variables.
I have written a file that ftp information from one pc to another in unix.
All you have to do is supply a user_name/password and machine name to which ftp program will connect to.
All connection information like user_id,password, machine name are stored in an oracle table FTP_TBL.
It has the following fields:
FTP_TBL
================
USER_ID NOT NULL VARCHAR2(100);
USR_PASSWD NOT NULL VARCHAR2(50);
TO_MACHINE NOT NULL VARCHAR2(50);
I have called a pl/sql script in unix shell.
This script selects all the connection information from FTP_TBL and populates the pl/sql variables with the
information.
Now i want the pl/sql variables like V_TO_MACHINE,V_USR_ID,V_USR_PASSWD to be passed on to unix variables
To_MACHINE, USR_ID AND USR_PASSWD.
How can i do this?
============================================================================================================
sqlplus -s <<+++ >> $LOG_FILE
$USER/$PASSWD
set serverout on SIZE 1000000
DECLARE
V_TO_MACHINE VARCHAR2(100);
V_USR_ID VARCHAR2(50);
V_USR_PASSWD VARCHAR2(50);
BEGIN
BEGIN
SELECT TO_MACHINE, USER_ID, USR_PASSWD
INTO V_TO_MACHINE,V_USR_ID,V_USR_PASSWD
FROM FTP_TBL;
EXCEPTION
when others then
dbms_output.put_line('ERROR|SQLPLUS|'||ERROR||'|'||sqlcode||'|Failed during selecting configuration information.'||sqlerrm );
END;
END;
+++
#======================== VARIABLES =====================
TO_MACHINE=$1
USR_ID=$2
USR_PASSWD=$3
#========================== MAIN ========================
ftp -vnd $TO_MACHINE << ++ 1>>$STA_LOG_FILE 2>&1
user $USR_ID $USR_PASSWD
prompt off
get $OR_DATA_DIR/ASC.STADATA $HOME_DIR/ASC.STADATA
bye
++
# testing the exit status of FTP
egrep "Transfer complete" $STA_LOG_FILE >/dev/null
if [ $? = 0 ]
then
echo >> $STA_LOG_FILE
echo "FTP Successfully Done" >> $STA_LOG_FILE
else
echo >> $STA_LOG_FILE
echo "FTP UnSuccessfull" >> $STA_LOG_FILE
exit 1
fiHere an example of how to pass variables to the shell script :
TEST@db102 SQL> select ename, job, dname from emp,dept
2 where empno = 7902
3 and emp.deptno = dept.deptno;
ENAME JOB DNAME
FORD ANALYST RESEARCH
TEST@db102 SQL> exit
Disconnected from Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options
[ora102 work db102]$ cat disp_var.sh
set `sqlplus -s test/test << EOF
set pages 0
select ename, job, dname from emp,dept
where empno = 7902
and emp.deptno = dept.deptno;
exit
EOF`
echo $1 $2 $3
[ora102 work db102]$ ./disp_var.sh
FORD ANALYST RESEARCH
[ora102 work db102]$ -
Passing pl/sql variable to Oarcle procedure to java program
Dear
Sir/madam
From java its easy to call procedure or function to get pl/sql variables like cursor type or varray type and cast back to that equi type thro' oracle extn package.Is there any way it could be done vice versa.Can i pass Oarcles Pl/SQL datatype like collection Of type Varray/Custom Object or Cursor,Array type to a procedure or function from java program.Is it possible to pass like that.If so could you kindly give a samll eaxample or URL where same type of example could be found
regards
kingshuDear
Sir/madam
From java its easy to call procedure or function to get pl/sql variables like cursor type or varray type and cast back to that equi type thro' oracle extn package.Is there any way it could be done vice versa.Can i pass Oarcles Pl/SQL datatype like collection Of type Varray/Custom Object or Cursor,Array type to a procedure or function from java program.Is it possible to pass like that.If so could you kindly give a samll eaxample or URL where same type of example could be found
regards
kingshu i suggest to read JPublisher doc - it help support or convert PL/SQL types in Java
http://otn.oracle.com/docs/products/oracle9i/doc_library/release2/java.920/a96658.pdf
Kuassi -
Passing pl/sql variable to oracle procedure from java
Dear
Sir/madam
From java its easy to call procedure or function to get pl/sql variables like cursor type or varray type and cast back to that equi type thro' oracle extn package.Is there any way it could be done vice versa.Can i pass Oarcles Pl/SQL datatype like collection Of type Varray/Custom Object or Cursor,Array type to a procedure or function from java program.Is it possible to pass like that.If so could you kindly give a samll eaxample or URL where same type of example could be found
regards
kingshukDear
Sir/madam
From java its easy to call procedure or function to get pl/sql variables like cursor type or varray type and cast back to that equi type thro' oracle extn package.Is there any way it could be done vice versa.Can i pass Oarcles Pl/SQL datatype like collection Of type Varray/Custom Object or Cursor,Array type to a procedure or function from java program.Is it possible to pass like that.If so could you kindly give a samll eaxample or URL where same type of example could be found
regards
kingshu i suggest to read JPublisher doc - it help support or convert PL/SQL types in Java
http://otn.oracle.com/docs/products/oracle9i/doc_library/release2/java.920/a96658.pdf
Kuassi -
Create a cursor from a PL/SQL variable or an external file
Dear friends,
is there a way for me to make Oracle Forms read a cursor from a PL/SQL variable, or an external file? Let's suppose we have the code below:
DECLARE
cursor c_values is select * from my_table;
r_values c_values%ROWTYPE;
BEGIN
for r_values in c_values loop
do_something;
end loop;
END;
In the situation described above, could I create "select * from my_table" from a PL/SQL variable (it could be something like p_cursor = 'select * from my_table'), or an external file - for example, make my form read the contents of c:\my_select.sql , where we see the "select * from my table" text?
My question comes because I need to export data from select instructions that were dinamically created inside the form - that is, via PL/SQL -, and I don't want to rewrite it, but I'll have to do it if I have no choice. Your help will be greatly appreciated.
Best regards,
Franklin
Edited by: franklinbrasil on 12/03/2009 11:33
Edited by: franklinbrasil on 12/03/2009 11:35Dear friends,
I am using DBMS_SQL package, which solved my problem. Please let me explain it better, if it's not clear.
I have some PL/SQL blocks inside my form, which creates SQL queries dinamically, and a dinamically created SQL is stored into a VARCHAR2 variable. These SQL queries are exported for use in Oracle Graphics, but since OG is not being developed by Oracle anymore then I am trying to find a substitute for it.
So I thought about creating an option for the final user: he/she can choose exporting data into Microsoft Excel, and user does what he/she wants, creating a customized graphic. Exporting into Excel works finely, with no problems at all - I could find a routine by searching on the web.
My goal was to use the same queries created above to export data dinamically to Microsoft Excel, and I absolutely don't want to rewrite all these dinamically created queries - one which works dinamically, other with no flexibility inside my form. Worse than it, I have many other dinamically created queries, and I obviously don't want to rewrite them all - any maintenance in this form would be terrible, with each SQL instruction written twice.
Since all dinamically created SQL instructions are stored inside a VARCHAR2 variable, I thought about reusing the same SQL, as explained above - and here we have your suggestions about using a ref cursor, execute immediate, and so on. And (answering Andreas) query structure is always based on the same table, but its structure changes a lot, depending on what the final user chooses in a drop-down list (it's a list of graphics options, where final user chooses one option, and form must mount SQL dinamically, based on user's choice).
By using your explanations, I could find DBMS_SQL solution here: http://download.oracle.com/docs/cd/B10501_01/appdev.920/a96590/adg09dyn.htm#26799
. Please notice that I had to change DBMS_SQL.native into 1 for it to work in my form. I'll mark all your answers as helpful because I can use them both for database and form purposes.
If my message was not clear enough, please tell me and I'll try to make it more clear.
Best regards,
Franklin -
Get Unix disk space available and assign it to a pl/sql variable
Hello,
From withint pl/sql, how do I get disk space(df -k) vailable from the os and assign that number to a pl/sql variable? I want to write a stored procedure that will look into how much space left on a os mount point. Thank you.You can check this thread
http://asktom.oracle.com/pls/ask/f?p=4950:8:13164696856450032216::NO::F4950_P8_DISPLAYID,F4950_P8_CRITERIA:952229840241 -
Final cut x 10.0.5 sqlite error too many sql variables
Hi,
We have a 463MB final cut project that can´t load.
If we see console out, it says:
Final Cut Pro CoreData: error: (1) I/O error for database at /Volumes/HD Pro RAID/Final Cut Projects/Teaser/CurrentVersion.fcpproject. SQLite error code:1, 'too many SQL variables'
Final Cut Pro Core Data: annotation: -executeRequest: encountered exception = I/O error for database at /Volumes/HD Pro RAID/Final Cut Projects/Teaser/CurrentVersion.fcpproject. SQLite error code:1, 'too many SQL variables' with userInfo = {
NSFilePath = "/Volumes/HD Pro RAID/Final Cut Projects/Teaser/Teaser con Burgos/CurrentVersion.fcpproject";
NSSQLiteErrorDomain = 1;
It seems that the project cames to big. I´m not the editor, so i can´t imagine how it could go that way and hao can we open it now.
Thanks.Hi Jon.
Thanks for your help. I´ve seen a post telling the same thing. I finally let Final cut pro X about 8 hours and it finally opened the project, but i couldn´t make anything with it. Tried to export xml and import it to another project without success. The problem persists. So i also tried to cut some parts from the project and is still the same. For each test we must wait 8 hours and it´s not reasonable time to test things. I just sent the project to apple engineers, so if is there any solution i will post in here.
Thanks. -
How to use sql variables in jdbc send adapter??
Hi,
i wanna use a variable in the sql statement in the jdbc send adapter.
i know i can key sql statement in the "Query SQL Statement" in the jdbc send adapter.but i dont know how to use variables in the sql statement.
i mean, for example, the sql statement is "SELECT * FROM t_student WHERE READFLAG = 0", but now i wanna instead of "0"(the value of the READFLAG) using a variable.
and if i can use a variable to replace the "0"(the value of the READFLAG above sql statement), then how can i send a value to the variable??
request help in the regard.
thx in advance.
BrianHi,
Use the place holders to pass the data at runtime. Check the below structure for more details.
Hope this helps.
Thanks and Regards,
Kalpesh
<root>
<stmt>
<Student action="SQL_QUERY">
<access> SELECT * FROM t_student WHERE READFLAG = '$FLAG$ </access>
<key>
<FLAG>0</FLAG>
</key>
</Student>
</stmt>
</root>
Maybe you are looking for
-
Backup MaxDB 7.6 mit HP Data Protector; Wrong file type
Hallo. Wir versuchen, eine MaxDB-Datenbank (Rel. 7.6) auf SUSE-LINUX unter Verwendung von HP Data Protector zu sichern. Der Versuch, das Backup durchzuführen, schlägt fehl, da auf dem MaxDB-Server anscheinend die Pipe nicht angelegt werden kann. Folg
-
Adobe Reader 11.0.03 not run files
On WIndows 7, I run Adobe Reader XI 11.0.03, and it won't open any files. I uninstalled and did fresh install but problem remains. I have had no previous problems and used the program since 2012.
-
[Solved][OpenGL]Vertex Buffer Objects - Crash on binding a buffer.
I am writing a little test application which is more or less just meant for learning and developing some of the underlying classes. I have recently decided to try replacing the immediate mode rendering with Vertex Buffer Objects. Since VBO's have bee
-
Dynamic vi not in memory in exe
Hello, I am using LV 2009 SP1. I am trying to build a "Main.vi" into an exe, in which this Main.vi needs to dynamically call two vi "A.vi" and "B.vi" using call by reference node. Therefore in the Build Specs/Source Files, I've put A.vi and B.vi into
-
Position of legend for curves.
HI, Please look at the picture below. I need to have curve legend similar to it. DIAdem provides Vertical,Horizontal and Automatic position. I am facing problem with position of channel names. How to do that.? I hope am clear about my requirement. Re