I have a package, which is already created in DB.
How to wrap the package by inputting the object name without inputting the total script?
You can use DBMS_DDL.Wrap to wrap packages that are n the database, but it requires that you read their definition (using DBMS_Metadata for example) to pass it to the procedure, then take the wrapped output and execute the wrapped create package code (using EXECUTE IMMEDIATE for example).
http://docs.oracle.com/cd/E11882_01/appdev.112/e25519/wrap.htm#BEHGEBGI
Related
I am using R to create a function that allows me to load specific Rdata.
So I have several different files, each containing a specific Rdata set. For instance, if I want to load the information about the northern line, I would write
load(“TfL/Line/northern/Arrivals.Rdata")
And if I want circle line, I would write
load(“TfL/Line/circle/Arrivals.Rdata")
The question is, can I write a function that takes the name of the tube line, say LineName,as an input, using the load function? I tried
Get_information<- function(LineName==NULL){
load(“TfL/Line/LineName/Arrivals.Rdata")}
This doesn’t work. Could someone help me deal with this? Thanks!
You need to pass 'LineName' as a variable. Currently you're just writing "LineName" as a string-literal.
There are a few functions which can do this:
Paste0
Paste0 combines character vectors (literals or objects) into a single string:
load(paste0(“TfL/Line/", LineName, "/Arrivals.Rdata"))
Glue
Glue is a CRAN package which functions in a similar way to paste0, but can be easier to write and read:
#install.packages("glue") #<- run if you don't have glue installed
require("glue") # attach the package so that we can use 'glue'
load(glue("TfL/Line/{LineName}/Arrivals.Rdata"))
If run either of those inside your function, it will work as intended.
In my work I develop R packages that export R data objects (.RData). The name of these .RData files is always the same (e.g. files.RData). These packages also define and export a function that uploads the data to my database, say upload_data(). Inside upload_data() I first load the data using data(files, package = "PACKAGE NAME") and then push it into my database.
Let's say I have two packages, package1 and package2, which live on my file system. Given a vector of the package names (c("package1", "package2")), how would I go about to call 'upload_data()' programatically? Specifically, inside a script, how would I construct a call using "::" notation that constructs and evaluates a call like this: package1::upload_data()). I tried 'call' but couldn't get it right.
You could go the route of constructing the call using :: notation and evaluating that - but it's probably just easier to directly use get and specify the package you want to grab from.
get("upload_data", envir = asNamespace("package1"))
will return the function the same as using package1::upload_data would but is much easier to deal with programatically.
I'm building a package that contains a number of look up tables, hidden from the user by storing them in R/sysdata.rda. This works fine and I am able to reference them from internal package functions directly or via get.
Is there a way to get a vector of object names contained in sysdata.rda from within a function inside the package? What about as a user?
The behavior I am looking for would be similar to how ls lists the objects in an environment.
The way I use is to have an internal function to generate the sysdata.R It can then also generate the vector of names within the limited scope of the function. You can then add the list of names to sysdata.R itself.
Or, if it is more complicated, have the function save the tables in a new environment: you can then ls the new environment for the list, and save the contents into sysdata.R.
I was wondering if it is possible to define an R package within another R package and achieving functionality of only being able to access the inner R package through the outer? Say that I am building an R package that corresponds to a db layer, and that within the db layer I have a lot of sql statements, is it possible to define a package db where functions would be accessed through, db::db1::function1() where db1 is the package that is defined within db, or would the approach be to use environments to bind together the functionality as I would want to have some logical coherence between the two? So that rather I would have db::db1$ function where the db1 is an environment defined in db.
Edited example:
main folder use case:
./folder1
./folder1a
./folder1b
./folder1c
...
./folder2
./folder3
...
The way I envisioned was that if each folder in the hierarchy that in turns contains dussins of scripts would be a package. How would I do the mapping to packages? What would be the alternative, that each folder1 folder2 etc are the packages and the functionality in folder1a folder1b etc would be tied to an environment that lives inside the package that would correspond to folder1. Which would allow accessing some function defined in a file inside folder1a say through folder1::folder1a::function_defined_in_script_in_1a.
I am new to PL/SQL so just trying to figure out the general flow of creating a package
CREATE OR REPLACE PACKAGE P1 AS
PROCEDURE PROC1
(
);
END P1;
CREATE OR REPLACE PACKAGE BODY P1 AS
//package definition
END P1;
Is this the correct way to define the package?
Basically, I am trying to find out whether I can declare the package and define the package body in the same file or would i need to create 2 separate files?
When I try to execute it, I get the error Encountered the word 'PROCEDURE' when expecting one of the following
Generally, you have the specification of the package in a file, and the body in another. Why are you trying to put them in the same file?
It doesn't matter for an individual package, but you must declare the specification before the body.
Where you are creating multiple packages it is best to create all of the specifications first because the bodies can then compile even if they reference a different package for which the body has not yet been created.