Accessing PL/SQL table in SQL query
Hello,
Is it possible to use plain SQL to query PL/SQL table? In my case this table is returned by UTL_HTTP.REQUEST_PIECES function, which is defined as:
create or replace package utl_http is
type html_pieces is table of varchar2(2000) index by binary_integer;
function request_pieces (url in varchar2,
max_pieces natural default 32767)
return html_pieces;
pragma restrict_references (request_pieces, wnds, rnds, wnps, rnps);
Generally, I want to access chunks of external data for comparison without using PL/SQL. Thanks ahead for ideas. Ideally, I need working example because my attempts to use TABLE & CAST failed.
I was going to suggest you could try and create your own wrapper around utl_http and use a database type, but then I remembered this excellent thread which covers it better than I ever could - Billy, hope you don't mind passing on your good work!
Re: Error using UTL_HTTP over HTTPS
Similar Messages
-
Get the Last Value of Status Field from SQL TABLE using SQL 2008
I have a table with Fields such as
UploadstartTime, UploadEndtime, STATUS From TBLA.
The STATUS Field, has values =7 and 11 are failed and 12 is SUCCESS. I cannot do a max, since it will always show 12, I need to get the MAX(UPLOADENDTIME, and get STATUS For that record. How can I do that using 1 SQL Query?
My current code is: The issue is
select
TBLNAME
MaxUploadstarttime
=
max(UploadStartTime),
MaxUploadEndtime
=
max(UpLoadEndTime),
Status=max(status)
from DB.DBO.LOGTABLE
p1Please post DDL, so that people do not have to guess what the keys, constraints, Declarative Referential Integrity, data types, etc. in your schema are. Learn how to follow ISO-11179 data element naming conventions and formatting rules. You failed! Temporal
data should use ISO-8601 formats. Code should be in Standard SQL as much as possible and not local dialect.
This is minimal polite behavior on SQL forums.
>> I have a table with Fields such as <<
Fields are not columns! There is no generic status in RDBMS. Putting “tbl-” in a table name is called tibbling and we make fun of people who do it (Google Phil Factor's humor columns. If you were polite is this what you wanted to post?
CREATE TABLE Something_Uploads
(upload_source_name CHAR(15) NOT NULL,
upload_start_timestamp DATETIME2(0) NOT NULL,
PRIMARY KEY (upload_source_name, upload_start_timestamp),
upload_end_timestamp DATETIME2(0),
CHECK(upload_start_timestamp < upload_end_timestamp),
upload_status INTEGER NOT NULL
CHECK (upload_status IN (7,11,12, ..))
>> I cannot do a max, since it will always show 12, I need to get the MAX(UPLOADENDTIME, and get upload_status For that record [sic]. How can I do that using 1 SQL Query? <<
Since you told us nothing and gave no sample data, want to correct this postign?
--CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
in Sets / Trees and Hierarchies in SQL -
SSRS/Powerview to compare SQL table and excel sheet
I have a SQL table and an excel sheet with some data...
I want to be able to compare the two and find out which Excel rows are missing in the SQL table...
Would it be easier to do this report in SSRS or would it be better to do it in Excel PowerView?
If so how do I go about it?
Thanks in advance for your help...
Dhananjay ReleHi Dhananjay,
According to your description, you want to compare the data of a SQL table and an excel sheet. To achieve this goal, we can create two tables in Reporting Services report, one for SQL table with SQL Server connection type, another for excel sheet with ODBC
connection type.
For more details about how to create the report, please see the following steps:
Create a report server project with SQL Server Data Tools (SSDT) Business Intelligence Templates list.
Create a new report definition file in Solution Explorer.
Create a Data Source named DataSource1 with Microsoft SQL Server Type, then select the SQL table database from the corresponding server.
Create a Data Source named DataSource2 with ODBC Type, then select the excel file.
Create two datasets which returns the SQL data and Excel sheet data based on the two data source, one for DataSource1, another for DataSource2.
Create two table next to each other based on the datasets on the design surface.
References:
Create a Basic Table Report (SSRS Tutorial)
Create SSRS report using Excel Data Source Step by Step
If there are any other questions, please feel free to ask.
Regards,
Katherine Xiong
Katherine Xiong
TechNet Community Support -
How to find out which Tables have been accessed without looking at the SQL query ?
Hi,
I would like to know is there a way to find out what queries have been executed and on which tables without looking at the SQL query.
I have an old C++ code which calls some library functions to access the Oracle database. The source code for the library is not available to me yet. The functions selects/updates/deletes and inserts based on some input parameters I give. I do not know which tables it affects. How do I find out the actual SQL query and/or the tables it accesses ? I was told about V$SQL table that
has the most recently executed queries, but
I did'nt see any queries connected to my process.
Could anybody help me on this ?
Thanks
Jagdeep
[email protected]
nullPRECISE/SQL can help you if you have access to it
2nd option can be that turn on SQL_TRACE
Run executable of ur c++ program
it will create a trace file in user_dump_dest
and then using TKPROF u can see all quesries and their plan also.
HTH
Gagan Deep Singh
<BLOCKQUOTE><font size="1" face="Verdana, Arial, Helvetica">quote:</font><HR>Originally posted by (jagdeeps):
Hi,
I would like to know is there a way to find out what queries have been executed and on which tables without looking at the SQL query.
I have an old C++ code which calls some library functions to access the Oracle database. The source code for the library is not available to me yet. The functions selects/updates/deletes and inserts based on some input parameters I give. I do not know which tables it affects. How do I find out the actual SQL query and/or the tables it accesses ? I was told about V$SQL table that
has the most recently executed queries, but
I did'nt see any queries connected to my process.
Could anybody help me on this ?
Thanks
Jagdeep
[email protected]<HR></BLOCKQUOTE>
null -
I was told that SAP on SQL Server maintains a very unique security where someone can not just directly access tables in SQL Server. I was told you need the SAP client in order to access the data stored within the DB. With other systems, normally users such as a DBA or privileged users would be able to directly log into the database and possibly alter data, whereas this is not the case for SAP on SQL. Can someone help confirm if this is true or not and explain to me how this works.
Hi Julia:
You can access data stored in SQL tables using Enterprise Manager or SQL Query Analyzer and you can do in every other database system such as DB2, Informix or Oracle; there are some well-known Cluster tables that information can only be read from inside SAP.
Regards,
Federico -
Accessing MySQL InnoDB tables via JDBC using Oracle SQL Developer
I had posted a problem in the Oracle SQL Developer forum with how that application (v1.1) accesses MySQL InnoDB tables and someone replied that the "[data migration] team created the integration with MySQL", so I am posting here in hopes of learning more about the problem.
Here's a summary:
When I use Oracle SQL Developer to query MySQL InnoDB tables, I need to issue a "commit" before I do each query to ensure that I am getting current results. Otherwise, it appears to be using a snapshot as-of the last commit. Is this a problem with SQL Developer, or a JDBC configuration, or MySQL problem even?
The full details are here:
Re: MySQL InnoDB tablesHi,
I've posted a response to your original thread.
Regards,
Dermot. -
PL/SQL Table use in report region query
Hello,
I have a package function which return pl/sql table. I want to create a report region based on this pl/sql table. Is it possible to do this kind of report in HTMLDB?
Please guide me in this area.
Thanks
HAThe htmldb_collections API (apec_collections in 2.2) is a very useful method for rendering reports and one I have used extensivly in the past.
Once created and populated you can reference your collection as if it were a SQL table i.e.
Select c001, c002, c003
from htmldb_collections
where collection_name = 'MY_COLLECTION';
You can absolutly base an Apex Report region on collections. Just treat them as another table that you can select from, join to others etc.
In order to utilise this you must do the following:
1) Create your collection:
note that collections only persist for the duration of your session and you can only see the data you inserted into the collection. Also I would create this collection as the Database user who owns the Apex Workspace
htmldb_collection.create_or_truncate_collection ('MY_COLLECTION');
2) Populate your collection:
In your case I would set a loop construct that parses through your pl/sql table and assign all values as described below. I assumed that my_plsql_tab has 3 columns called Val1, Val2, Val3
FOR x IN 1..my_plsql_tab.count
LOOP
htmldb_collection.add_member (p_collection_name => 'MY_COLLECTION',
p_c001 => my_plsql_tab(x).val1,
p_c002 => my_plsql_tab(x).val2,
p_c003 => my_plsql_tab(x).val3
END LOOP;
Note that you can have upto 60 elements in your collection.
3) Access your collection:
Select c001, c002, c003
from htmldb_collections
where collection_name = 'MY_COLLECTION';
This quesry can then form the source of your sql report region.
Hope all that helps
Duncan -
Table does not exist (servlet accessing the postgres sql table)
Hello every body,
I am running servlet to access the postgres sql table. But there exist error.
ERROR: relation "employee" does not exist
I have checked the table name in database and table name into the servlet. Both are same. Please give me suggestion to solve this error.
Thankscan you connect to the database without the servlet?
put your stuff into this and try it. If it works, add something to check the table names. - %
package test;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
* Connect to a database using JDBC
public class ConnectionTest
private static final String DEFAULT_DRIVER = "your driver here";
private static final String DEFAULT_URL = "your url here";
private static final String DEFAULT_USERNAME = "your username here";
private static final String DEFAULT_PASSWORD = "your password here";
public static void main(String[] args)
Connection connection = null;
ResultSet rs = null;
try
String driver = ((args.length > 0) ? args[0] : DEFAULT_DRIVER);
Class.forName(driver);
String url = ((args.length > 1) ? args[1] : DEFAULT_URL);
String username = ((args.length > 2) ? args[2] : DEFAULT_USERNAME);
String password = ((args.length > 3) ? args[3] : DEFAULT_PASSWORD);
connection = DriverManager.getConnection(url, username, password);
DatabaseMetaData databaseMetaData = connection.getMetaData();
System.out.println("product: " + databaseMetaData.getDatabaseProductName());
System.out.println("major : " + databaseMetaData.getDatabaseMajorVersion());
System.out.println("minor : " + databaseMetaData.getDatabaseMinorVersion());
System.out.println("schemas");
rs = databaseMetaData.getSchemas();
while (rs.next())
System.out.println(rs.getString(1));
catch (Exception e)
e.printStackTrace();
finally
close(rs);
close(connection);
public static void close(ResultSet resultSet)
try
if (resultSet != null)
resultSet.close();
catch (Exception e)
e.printStackTrace();
public static void close(Statement statement)
try
if (statement != null)
statement.close();
catch (Exception e)
e.printStackTrace();
public static void close(Connection connection)
try
if (connection != null)
connection.close();
catch (Exception e)
e.printStackTrace();
} -
Access APEX_APPLICATION.G_F01 in an SQL query for a report
APEX 4.0.2.00.07
I've got a standard report with checkboxes. The SQL is along the lines of:
SELECT APEX_ITEM.CHECKBOX(1,empno,'CHECKED') " ",
ename,
job
FROM empThen I have another report below this, which I want to drive based on the items checked in the first report. I know that the checkbox values will go into the APEX_APPLICATION.G_F01 collection. Normally these are accessed using pl/sql such as:
FOR I in 1..APEX_APPLICATION.G_F01.COUNT LOOP
DELETE FROM emp WHERE empno = to_number(APEX_APPLICATION.G_F01(i));
END LOOP;But is there any way I can access the collection from the sql for my second report.
i.e. I want my sql to be something like:
SELECT empno, day_of_service
FROM emp_timesheet
WHERE emp_no in <get access to the collection here>I was hoping that the check box collection would be available from the APEX_COLLECTIONS view, but it doesn't seem to be there.
Thanks,
JohnJohn,
If the goal is to hold onto the checked values for some other processing then you could add them to a collection yourself.
create a process on your page which looks something like this:
This will create your collection if it does not exist or delete everything currently in it if it does exist and then insert your new selections.
DECLARE
l_col_name varchar2(30) := 'EMP_SELECTED';
BEGIN
apex_collection.create_or_truncate_collection(l_col_name);
FOR I in 1..APEX_APPLICATION.G_F01.COUNT LOOP
apex_collection.add_member(
l_col_name,
to_number(APEX_APPLICATION.G_F01(i))
END LOOP;
END;your second query could look something like this:
SELECT empno, day_of_service
FROM emp_timesheet
WHERE empno in (select C001 empno
from apex_collections ac
where ac.collection_name = 'EMP_SELECTED')
Edit
some people choose to create a view ontop of certain collection queries which will be reapeated throughout the application so you could also just
create view selected_emps as
select C001 empno
from apex_collections ac
where ac.collection_name = 'EMP_SELECTED' and your new query would look like:
SELECT empno, day_of_service
FROM emp_timesheet
WHERE empno in (select empno
from selected_emps)Cheers,
Tyson Jouglet
Edited by: Tyson Jouglet on Apr 6, 2011 10:37 AM -
Import MS Access 2013 tables into SQL Server 2012
Hi there,
Is there a step by step example somewhere showing how to import an MS Access 2013 table into SQL Server 2012?
I have read the existing posts and don't see a definitive answer.
I have installed MS Access 2010 engine, first 32 bit then 64 bit.
I have installed the MS Access 2013 runtime on my server.
I use the Office 2015 Access Database Engine OLE DB Provider.
I get the error:
Error 0xc0202009: Source - APEntries [1]: SSIS Error Code DTS_E_OLEDBERROR. An OLE DB error has occurred. Error code: 0x80040E37.
Error 0xc02020e8: Source - APEntries [1]: Opening a rowset for "`TableName`" failed. Check that the object exists in the database.
The post regarding the above errors doesn't resolve the issue.
I have full administrative permissions on the server.
What is the trick to making this work?
Thanks,
Ric
Ric MillerHi there,
I tried the exact same operation on a third machine.
This machine has Windows 8.1 64 bit, SQL Server 2012 64 bit, MS Office 2013 Plus 32 bit.
I am the administrator on this machine.
I installed this:
Microsoft Access Database Engine 2010 Redistributable 32 bit (because I have MS Office 2013 plus 32 bit installed.)
From here:
http://www.microsoft.com/en-us/download/details.aspx?id=13255
It won't let me install the 64 bit version without uninstalling MS Office 32 bit.
I created an MS Access database on this machine using MS Access 2013 and created a table with 3 records.
I used the "Import and Export Data (32 bit)" from the start menu.
After I installed the "Database Engine 2010 32 bit" driver above, I now have the option of "Office 2015 Access Database Engine OLE DB Provider" as Data Source which I did not have prior to doing this installation.
I selected the driver and added the Properties of the Data Source Name file location of the MS Access file. I am using a blank password.
I go thru the same sequence of selecting a table to import and after running the result is the same:
Error 0xc0202009: Source - APEntries [1]: SSIS Error Code DTS_E_OLEDBERROR. An OLE DB error has occurred. Error code: 0x80040E37.
"Error 0xc02020e8: Source - APEntries [1]: Opening a rowset for "`TableName`" failed. Check that the object exists in the database."
This seems to be consistent across three machines with three operating systems with the same files and the same result.
I understand that some people have gotten this to work.
I would appreciate it if anyone can report an error in the above procedure to me.
Thanks,
Ric
Ric Miller -
Report cannot access pl/sql table variable defined in Package Spec.
Hi,
I've created a package spec called pkg_report with a PL/SQL table variable defined called body_text_table. When I tried to compile the following code under the Before Report trigger:
:desc := pkg_report.body_text_table(1);
Oracle gave me the following error:
Implementation Restriction: 'PKG_REPORT.BODY_TEXT_TABLE': Cannot directly access remote package variable or cursor.
Does anyone have any idea about this error? Thank you for your time at looking at it.
Regards,
JohnYou cannot directly access the package variable in a database package. The work around is to create a set_variable and get_variable wrapper function in the package body. See Metalink note 105838.1 for more info.
A simple example:
create or replace package my_package as
my_var number;
function get_variable return number ;
procedure set_variable (p_value in number) ;
end ;
create or replace package body my_package as
function get_variable return number is
begin
return my_var;
end ;
procedure set_variable(p_value in number) is
begin
my_var := p_value ;
end ;
end; -
SQL Developer fails to query table
I am trying to use SQL Developer (v3.2.20.09) to query a particular table in an Oracle 10G database using a simple "select * from table" query. When I run the query SQL Developer sits there forever waiting for results but nothing is every returned.
The table is relatively small, just a few thousand rows and just half a dozen columns (mixture of numbers, short text strings and datetimes). I can run other queries on the table in question so I know I have privileges, it's just when run a simple query to return all columns and all rows it fails. I even tried to an export of the table using Tools->Database Export but that too just sat there forever failing to complete.
Any ideas? It seems that there is just something in the table that SQL Developer doesn't like.I've never used sqlplus before but I just tried it and it runs the same query (select * from [table] where rownum <= 40) without any problems. The strange thing is that once I could see which row was row 40 in sqlplus I queried just that one row in SQL Developer (using the primary key column) and it worked fine.
I did a bit more experimenting and it doesn't look like a problem with that row in particular just with displaying more than a certain number of rows. The first column on the table is called OBJ_ID and is a unique integer which forms the primary key. Row 40 has OBJ_ID = 53. I tried running:
select * from [table] where obj_id between 40 and 53 - no problems
select * from [table] where obj_id between 30 and 53 - no problems
select * from [table] where obj_id between 20 and 53 - no problems
select * from [table] where obj_id between 10 and 53 - failure as above (no errors but SQL Developer never displays the results) -
Import Access Table into SQL Server 2005
I am using BIDS and have created a OLEDB connection to my mdb file, and a DataFlowTask for the Control Flow, but lost on what to set-up on the Data Flow tab. What do I do to set-up the data flow to import the mdb table to sql server?
Why Execute SQL Task is needed?
Typically the SQL is embedded into the OLEDB Source.
I guess when you were working on the destination you chose to create the table. Then you mapped to it. Why you cannot find it in
options I am not sure. Can you post a picture? The table would be now in the drop down list of tables available, but you supposed not to repeat this step.
Arthur My Blog
Maybe I am just not fully understanding the link posted - but am trying. Attached are my screenshots 1 of Control Flow Tab and 2 of Data Flow Tab. My process is to take an access table and link it into SQL Server -
How to invoke PL/SQL Table parameter in the query string?
Hello,
I've met a problem invoking PL/SQL Table parameter in the query string, in OWS 3.0.
What I'm going to do is, to invoke a stored procedure to generate a web page using PL/SQL Web Toolkit 2.0, like: "http://.../owa/test_proc".
But there is a IN parameter for this procedure, and it's a PL/SQL Table variable. So I can't invoke the procedure sucessfully just using "http://.../owa/test_proc?v_plsql=i_plsql".
Did someone have met this kind of problem or have the answer to it? Thanks so much for your help.When using procedures with pl/sql-tables as parameter they should be overloaded, e.g.:
procedure my_procedure (my_var in varchar2)...
and
procedure my_procedure (my_var in owa_util.ident_arr)
the procedure then can be called with:
http://..../my_procedure?my_var=Scott, which invokes the version with the varchar2 parameter, or
http://..../my_procedure?my_var=Scott&my_var=Miller......
which invokes the version with the pl/sql-Table
Another solution might be the use of flexible parameters, passing pairs of parameter_name, parameter_value to your procedure. Your procedure looks like:
procedure my_procedure (name_array IN owa.vc_arr, value_array IN owa.vc_arr)..
and is invoked (note the ! )
http://..../!my_procedure?ename=Scott&sal=200&job=clerk.....
looping through the pl/sql tables will retrieve values of ename, sal and job for name_array and Scott, 200 and clerk for value_array
Hth
null -
Can we query a stored procedure results as an SQL Table ?
Hi,
Can we query a results from the results of a stored procedure returning a result set either as cursors or as PL/SQL Table like what we do like this
select * from <tablename>
select * from (select * from tablename) alias. instead of this, can we do like this
select * from (results of stored procedure) alias.
Please Provide any Help.I agree. Pipelined Table Functions are the way to go.
Docs at http://tahiti.oracle.com
Working demos in Morgan's Library at www.psoug.org under Pipelined Table Functions.
Maybe you are looking for
-
How to connect my perfectly-working 20-year-old Apple Personal Laserwriter 320 to my iMac running Mountain Lion? Thank you, Morty S.
-
What's the difference between "Full Name" and "Account Name"
Just re-install a new OS X Lion. On the "Create Your Computer Account" screen, what's the difference between "Full Name" and "Account Name"?
-
Adding field in Invoice Details
Hi Experts, The user has asked to add contact person name in invoice details through query manager. It could be possible to do.
-
Bulk Export Package Spec and Body as single file
Is there a way to bulk export the package spec and body into a single file, you can export spec and body if you choose each individual proc/package but if you just choose the spec/body individually from the connection - > packages list it only export
-
I tried to follow the directions for moving files from one hard disk to another, but itunes cannot find them. It recognizes them if I manually give it the location, but I have a gazillion songs and it would take me weeks... Is there a way to force it