用DBI转发斜线问题(Forward Slash issue with DBI)
我不熟悉在perl脚本中使用DBI进行SQL查询。 我遇到的问题与具有正斜杠的字段中的数据有关。 我想为我的where子句使用变量作为输入,但它正在做DBI想要的一个正斜杠:停止查询。 我尝试了许多不同的工作,从绑定,报价等,但没有工作,这是甚至可能的? 这里的数据是一致的。 与我的$ sql变量行是麻烦的地方。
#!/usr/bin/perl # Modules use DBI; use DBD::Oracle; use strict; use warnings; # Connection Info $platform = "Oracle"; $database = "mydb"; $user = "user"; $pw = "pass"; # Data Source $ds = "dbi:Oracle:$database"; my $dbh = DBI->connect($ds, $user, $pw); # my $dbh = DBI->connect(); my $XCOD = $dbh->quote('cba'); my $a = $dbh->quote('abc'); my $b = $dbh->quote('123'); # tried this as well my $pid = $dbh->quote('$a/$b'); my $sql = "SELECT P_ID FROM MyTable WHERE P_ID=$a/$b AND XCOD=$XCOD"; my $sth = $dbh->prepare($sql); $sth->execute(); my $outfile = 'superunique.txt'; open OUTFILE, '>', $outfile or die "Unable to open $outfile: $!"; while(my @re = $sth->fetchrow_array) { print OUTFILE @re,"\n"; } close OUTFILE; $sth->finish(); $dbh->disconnect();
I'm new to using DBI for SQL queries in a perl script. The issue I'm having pertains to data in fields that have a forward slash. I'm wanting to use variables as input for my where clause, but it is doing what DBI intends a forward slash to do: stop the query. I tried numerous different work arounds from binds, quotes, etc. but none worked, is it even possible? Data in this is consistent. The line with the my $sql variable is where the trouble is.
#!/usr/bin/perl # Modules use DBI; use DBD::Oracle; use strict; use warnings; # Connection Info $platform = "Oracle"; $database = "mydb"; $user = "user"; $pw = "pass"; # Data Source $ds = "dbi:Oracle:$database"; my $dbh = DBI->connect($ds, $user, $pw); # my $dbh = DBI->connect(); my $XCOD = $dbh->quote('cba'); my $a = $dbh->quote('abc'); my $b = $dbh->quote('123'); # tried this as well my $pid = $dbh->quote('$a/$b'); my $sql = "SELECT P_ID FROM MyTable WHERE P_ID=$a/$b AND XCOD=$XCOD"; my $sth = $dbh->prepare($sql); $sth->execute(); my $outfile = 'superunique.txt'; open OUTFILE, '>', $outfile or die "Unable to open $outfile: $!"; while(my @re = $sth->fetchrow_array) { print OUTFILE @re,"\n"; } close OUTFILE; $sth->finish(); $dbh->disconnect();
原文:https://stackoverflow.com/questions/31465047
最满意答案
请参阅以下步骤:
- 添加PowerShell任务
脚本:
Install-PackageProvider -Name NuGet -Force -Scope CurrentUser Get-Module -ListAvailable| where {$_.Name -Like "*AzureRM*"} | Select Name, Version Install-Module -Name AzureRM -RequiredVersion 6.0.1 -Force -Scope CurrentUser -AllowClobber Import-Module AzureRM -Force -Verbose -Scope Local Get-Module -ListAvailable| where {$_.Name -Like "*AzureRM*"} | Select Name, Version
- 编辑Azure PowerShell任务(Azure PowerShell版本:
Specify other version
;首选Azure PowerShell版本:6.0.1
)相关主题: 升级托管2017代理上的AzureRM Powershell(VSTS - Visual Studio Team Services)
Refer to these steps:
- Add PowerShell task
Script:
Install-PackageProvider -Name NuGet -Force -Scope CurrentUser Get-Module -ListAvailable| where {$_.Name -Like "*AzureRM*"} | Select Name, Version Install-Module -Name AzureRM -RequiredVersion 6.0.1 -Force -Scope CurrentUser -AllowClobber Import-Module AzureRM -Force -Verbose -Scope Local Get-Module -ListAvailable| where {$_.Name -Like "*AzureRM*"} | Select Name, Version
- Edit your Azure PowerShell task (Azure PowerShell Version:
Specify other version
; Preferred Azure PowerShell Versioin:6.0.1
)Related thread: Upgrade AzureRM Powershell on Hosted 2017 Agent (VSTS - Visual Studio Team Services)
相关问答
更多-
下列中不属于面向对象的编程语言的是?[2022-05-30]
a -
ItemPropertyValue不会被识别为cmdlet的名称(ItemPropertyValue is not recognized as the name of a cmdlet)[2022-03-23]
找到V.4的解决方案 $j = $((Get-ItemProperty -Path "Registry::$_").Version) $k = $((Get-ItemProperty -Path "Registry::$_\Settings").Server) Found the solution for V.4 $j = $((Get-ItemProperty -Path "Registry::$_").Version) $k = $((Get-ItemProperty -Path "Registry: ... -
术语“Set-AzureRmVMPlan”未被识别为cmdlet的名称(The term 'Set-AzureRmVMPlan' is not recognized as the name of a cmdlet)[2023-10-07]
那么在这里发生的事情,Azure自动化使用旧版本的模块,您必须转到Azure自动化刀片>资产>模块>浏览库并重新导入AzureRM.Profile和AzureRM.Compute。 So what is happening here, Azure Automation uses the old version of the Module, you have to go to Azure Automation Blade > Assets > Modules > Browse Gallery and reim ... -
你试过这个命令: dotnet restore --infer-runtimes 有关更多信息,请访问: https : //github.com/aspnet/EntityFramework/issues/5549 ,它适用于某人。 Have you tried the command: dotnet restore --infer-runtimes For more information, you can visit: https://github.com/aspnet/EntityFramewo ...
-
再次遇到这个问题后,我们在这里找到了答案 。 打开“程序和功能”,选择“Microsoft Visual C ++ Redistributable(x86)”,单击“卸载”,然后选择“修复”。 修复后(如果有的话,还有x64版本),重新安装或修复.NET Core SDK 1.0.1的安装。 After again coming across this problem, we found the answer here. Open Programs and Features, choose Microsof ...
-
请参阅以下步骤: 添加PowerShell任务 脚本: Install-PackageProvider -Name NuGet -Force -Scope CurrentUser Get-Module -ListAvailable| where {$_.Name -Like "*AzureRM*"} | Select Name, Version Install-Module -Name AzureRM -RequiredVersion 6.0.1 -Force -Scope CurrentUser -Al ...
-
你可以尝试在PowerShell系统模块路径中安装OpenXmlPowerTools模块: C:\Windows\system32\WindowsPowerShell\v1.0\Modules Can you just try to install OpenXmlPowerTools module in the PowerShell System module path : C:\Windows\system32\WindowsPowerShell\v1.0\Modules
-
由于命令行参数通过“运行”标记的方式,您需要转义GigaBytes周围的双引号(使用\ escape字符)或用单引号替换它们。 这两个Select-Object命令中的任何一个都应该起作用: Select-Object Name, @{Name=\"GigaBytes\";Expression={$_.Length / 1GB}} 要么 Select-Object Name, @{Name='GigaBytes';Expression={$_.Length / 1GB}} 这是因为用双引号括起来的任何内 ...
-
您需要点源.ps1文件以获取导入会话的函数。 . C:\PowerShell\ConvertCSVtoExcel.ps1 You need to dot-source the .ps1 file to get the functions in it imported into your session. . C:\PowerShell\ConvertCSVtoExcel.ps1
-
术语“xWebsite”未被识别为cmdlet的名称(The term 'xWebsite' is not recognized as the name of a cmdlet)[2023-03-24]
屏幕截图显示了问题:未安装xWebsite资源。 仅安装了xwebApplication和xWebVirtualDirectory资源。 我刚从Technet下载了xWebAdministration 1.3.2.3 zip文件,看起来有人做了一个boo-boo - 它缺少xWebSite ! 问答部分充满了让人心烦的事情,所以你并不孤单。 :) 奇怪的是,据称包含所有模块的Wave 9资源包具有相同的问题! 最简单的方法是获取版本1.3.2 ,看起来它拥有一切。 The screenshot is sho ...